mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[IMP] - contract termination
This commit is contained in:
@@ -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,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user