mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[IMP] contract: Improve partner With running contracts search view filter + contract termination
This commit is contained in:
@@ -12,3 +12,4 @@ from . import res_partner
|
||||
from . import contract_tag
|
||||
from . import res_company
|
||||
from . import res_config_settings
|
||||
from . import contract_terminate_reason
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.exceptions import ValidationError, UserError
|
||||
from odoo.tools.translate import _
|
||||
|
||||
|
||||
@@ -93,6 +93,29 @@ class ContractContract(models.Model):
|
||||
)
|
||||
tag_ids = fields.Many2many(comodel_name="contract.tag", string="Tags")
|
||||
note = fields.Text(string="Notes")
|
||||
is_terminated = fields.Boolean(
|
||||
string="Terminated", readonly=True, copy=False
|
||||
)
|
||||
terminate_reason_id = fields.Many2one(
|
||||
comodel_name="contract.terminate.reason",
|
||||
string="Termination Reason",
|
||||
ondelete="restrict",
|
||||
readonly=True,
|
||||
copy=False,
|
||||
track_visibility="onchange",
|
||||
)
|
||||
terminate_comment = fields.Text(
|
||||
string="Termination Comment",
|
||||
readonly=True,
|
||||
copy=False,
|
||||
track_visibility="onchange",
|
||||
)
|
||||
terminate_date = fields.Date(
|
||||
string="Termination Date",
|
||||
readonly=True,
|
||||
copy=False,
|
||||
track_visibility="onchange",
|
||||
)
|
||||
|
||||
@api.multi
|
||||
def _inverse_partner_id(self):
|
||||
@@ -458,3 +481,43 @@ class ContractContract(models.Model):
|
||||
domain = self._get_contracts_to_invoice_domain(date_ref)
|
||||
contracts_to_invoice = self.search(domain)
|
||||
return contracts_to_invoice._recurring_create_invoice(date_ref)
|
||||
|
||||
@api.multi
|
||||
def action_terminate_contract(self):
|
||||
self.ensure_one()
|
||||
context = {"default_contract_id": self.id}
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'name': _('Terminate Contract'),
|
||||
'res_model': 'contract.contract.terminate',
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'target': 'new',
|
||||
'context': context,
|
||||
}
|
||||
|
||||
@api.multi
|
||||
def _terminate_contract(
|
||||
self, terminate_reason_id, terminate_comment, terminate_date
|
||||
):
|
||||
self.ensure_one()
|
||||
if not self.env.user.has_group("contract.can_terminate_contract"):
|
||||
raise UserError(_('You are not allowed to terminate contracts.'))
|
||||
self.contract_line_ids.filtered('is_stop_allowed').stop(terminate_date)
|
||||
self.write({
|
||||
'is_terminated': True,
|
||||
'terminate_reason_id': terminate_reason_id.id,
|
||||
'terminate_comment': terminate_comment,
|
||||
'terminate_date': terminate_date,
|
||||
})
|
||||
return True
|
||||
|
||||
@api.multi
|
||||
def action_cancel_contract_termination(self):
|
||||
self.ensure_one()
|
||||
self.write({
|
||||
'is_terminated': False,
|
||||
'terminate_reason_id': False,
|
||||
'terminate_comment': False,
|
||||
'terminate_date': False,
|
||||
})
|
||||
|
||||
@@ -296,9 +296,19 @@ class ContractLine(models.Model):
|
||||
'successor_contract_line_id',
|
||||
'predecessor_contract_line_id',
|
||||
'is_canceled',
|
||||
'contract_id.is_terminated',
|
||||
)
|
||||
def _compute_allowed(self):
|
||||
for rec in self:
|
||||
if rec.contract_id.is_terminated:
|
||||
rec.update({
|
||||
'is_plan_successor_allowed': False,
|
||||
'is_stop_plan_successor_allowed': False,
|
||||
'is_stop_allowed': False,
|
||||
'is_cancel_allowed': False,
|
||||
'is_un_cancel_allowed': False,
|
||||
})
|
||||
continue
|
||||
if rec.date_start:
|
||||
allowed = get_allowed(
|
||||
rec.date_start,
|
||||
@@ -310,13 +320,14 @@ class ContractLine(models.Model):
|
||||
rec.is_canceled,
|
||||
)
|
||||
if allowed:
|
||||
rec.is_plan_successor_allowed = allowed.plan_successor
|
||||
rec.is_stop_plan_successor_allowed = (
|
||||
allowed.stop_plan_successor
|
||||
)
|
||||
rec.is_stop_allowed = allowed.stop
|
||||
rec.is_cancel_allowed = allowed.cancel
|
||||
rec.is_un_cancel_allowed = allowed.uncancel
|
||||
rec.update({
|
||||
'is_plan_successor_allowed': allowed.plan_successor,
|
||||
'is_stop_plan_successor_allowed':
|
||||
allowed.stop_plan_successor,
|
||||
'is_stop_allowed': allowed.stop,
|
||||
'is_cancel_allowed': allowed.cancel,
|
||||
'is_un_cancel_allowed': allowed.uncancel,
|
||||
})
|
||||
|
||||
@api.constrains('is_auto_renew', 'successor_contract_line_id', 'date_end')
|
||||
def _check_allowed(self):
|
||||
@@ -1163,7 +1174,7 @@ class ContractLine(models.Model):
|
||||
).id
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'name': 'Resiliate contract line',
|
||||
'name': 'Terminate contract line',
|
||||
'res_model': 'contract.line.wizard',
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
@@ -1251,6 +1262,7 @@ class ContractLine(models.Model):
|
||||
@api.model
|
||||
def _contract_line_to_renew_domain(self):
|
||||
return [
|
||||
('contract_id.is_terminated', '=', False),
|
||||
('is_auto_renew', '=', True),
|
||||
('is_canceled', '=', False),
|
||||
('termination_notice_date', '<=', fields.Date.context_today(self)),
|
||||
|
||||
15
contract/models/contract_terminate_reason.py
Normal file
15
contract/models/contract_terminate_reason.py
Normal file
@@ -0,0 +1,15 @@
|
||||
# Copyright 2020 ACSONE SA/NV
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ContractTerminateReason(models.Model):
|
||||
|
||||
_name = 'contract.terminate.reason'
|
||||
_description = 'Contract Termination Reason'
|
||||
|
||||
name = fields.Char(required=True)
|
||||
terminate_comment_required = fields.Boolean(
|
||||
string="Require a termination comment", default=True
|
||||
)
|
||||
Reference in New Issue
Block a user