mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[IMP] contract: Add contract modification
This commit is contained in:
committed by
Pedro M. Baeza
parent
7f8c59fb2a
commit
a9f65b439a
@@ -6,6 +6,7 @@ from . import contract_template
|
||||
from . import contract
|
||||
from . import contract_template_line
|
||||
from . import contract_line
|
||||
from . import contract_modification
|
||||
from . import account_invoice
|
||||
from . import account_invoice_line
|
||||
from . import res_partner
|
||||
|
||||
@@ -123,6 +123,49 @@ class ContractContract(models.Model):
|
||||
copy=False,
|
||||
track_visibility="onchange",
|
||||
)
|
||||
modification_ids = fields.One2many(
|
||||
comodel_name='contract.modification',
|
||||
inverse_name='contract_id',
|
||||
string='Modifications',
|
||||
)
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
records = super().create(vals_list)
|
||||
records._set_start_contract_modification()
|
||||
return records
|
||||
|
||||
@api.model
|
||||
def _set_start_contract_modification(self):
|
||||
for record in self:
|
||||
if record.contract_line_ids:
|
||||
date_start = min(record.contract_line_ids.mapped('date_start'))
|
||||
else:
|
||||
date_start = record.create_date
|
||||
record.write({
|
||||
'modification_ids': [
|
||||
(0, 0, {'date': date_start, 'description': _('Contract start')})
|
||||
]
|
||||
})
|
||||
|
||||
@api.model
|
||||
def _modification_mail_send(self):
|
||||
modification_ids_not_sent = self.modification_ids.filtered(
|
||||
lambda x: not x.sent
|
||||
)
|
||||
if modification_ids_not_sent:
|
||||
contract_modification_subtype = self.sudo().env.ref(
|
||||
'contract.mail_message_subtype_contract_modification'
|
||||
)
|
||||
notified_partners = self.message_follower_ids.filtered(
|
||||
lambda x: contract_modification_subtype in x.subtype_ids
|
||||
).mapped('partner_id')
|
||||
if notified_partners:
|
||||
self.message_post_with_view(
|
||||
'mail.email_contract_modification_template',
|
||||
partner_ids=notified_partners.ids,
|
||||
)
|
||||
modification_ids_not_sent.write({'sent': True})
|
||||
|
||||
@api.multi
|
||||
def _inverse_partner_id(self):
|
||||
|
||||
48
contract/models/contract_modification.py
Normal file
48
contract/models/contract_modification.py
Normal file
@@ -0,0 +1,48 @@
|
||||
# Copyright 2020 Tecnativa - Víctor Martínez
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class ContractModification(models.Model):
|
||||
|
||||
_name = 'contract.modification'
|
||||
_description = 'Contract Modification'
|
||||
_order = 'date desc'
|
||||
|
||||
date = fields.Date(
|
||||
required=True,
|
||||
string='Date'
|
||||
)
|
||||
description = fields.Text(
|
||||
required=True,
|
||||
string='Description'
|
||||
)
|
||||
contract_id = fields.Many2one(
|
||||
string='Contract',
|
||||
comodel_name='contract.contract',
|
||||
required=True,
|
||||
ondelete='cascade',
|
||||
index=True
|
||||
)
|
||||
sent = fields.Boolean(
|
||||
string='Sent',
|
||||
default=False,
|
||||
readonly=True,
|
||||
)
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
records = super().create(vals_list)
|
||||
records.check_modification_ids_need_sent()
|
||||
return records
|
||||
|
||||
def write(self, vals):
|
||||
res = super().write(vals)
|
||||
self.check_modification_ids_need_sent()
|
||||
return res
|
||||
|
||||
def check_modification_ids_need_sent(self):
|
||||
records_not_sent = self.filtered(lambda x: not x.sent)
|
||||
if records_not_sent:
|
||||
records_not_sent.mapped('contract_id')._modification_mail_send()
|
||||
Reference in New Issue
Block a user