[FIX+IMP] contract: Fix tests + Batch modifications

This commit is contained in:
Víctor Martínez
2020-12-24 10:36:50 +01:00
committed by Pedro M. Baeza
parent c09c93cda6
commit 6daf88a437
3 changed files with 16 additions and 6 deletions

View File

@@ -135,6 +135,16 @@ class ContractContract(models.Model):
records._set_start_contract_modification()
return records
def write(self, vals):
if 'modification_ids' in vals:
res = super(ContractContract, self.with_context(
bypass_modification_send=True
)).write(vals)
self._modification_mail_send()
else:
res = super(ContractContract, self).write(vals)
return res
@api.model
def _set_start_contract_modification(self):
for record in self:

View File

@@ -33,15 +33,15 @@ class ContractModification(models.Model):
@api.model_create_multi
def create(self, vals_list):
records = super().create(vals_list)
records.check_modification_ids_need_sent()
if not self.env.context.get('bypass_modification_send'):
records.check_modification_ids_need_sent()
return records
def write(self, vals):
res = super().write(vals)
self.check_modification_ids_need_sent()
if not self.env.context.get('bypass_modification_send'):
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()
self.mapped('contract_id')._modification_mail_send()

View File

@@ -168,7 +168,7 @@ class TestContract(TestContractBase):
("model", "=", "contract.contract"),
("res_id", "=", self.contract.id),
])
self.assertGreaterEqual(len(mail_messages), 3)
self.assertGreaterEqual(len(mail_messages), 2)
def test_check_discount(self):
with self.assertRaises(ValidationError):