mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
@@ -147,11 +147,16 @@ class ContractContract(models.Model):
|
|||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _set_start_contract_modification(self):
|
def _set_start_contract_modification(self):
|
||||||
|
subtype_id = self.env.ref('contract.mail_message_subtype_contract_modification')
|
||||||
for record in self:
|
for record in self:
|
||||||
if record.contract_line_ids:
|
if record.contract_line_ids:
|
||||||
date_start = min(record.contract_line_ids.mapped('date_start'))
|
date_start = min(record.contract_line_ids.mapped('date_start'))
|
||||||
else:
|
else:
|
||||||
date_start = record.create_date
|
date_start = record.create_date
|
||||||
|
record.message_subscribe(
|
||||||
|
partner_ids=[record.partner_id.id],
|
||||||
|
subtype_ids=[subtype_id.id]
|
||||||
|
)
|
||||||
record.write({
|
record.write({
|
||||||
'modification_ids': [
|
'modification_ids': [
|
||||||
(0, 0, {'date': date_start, 'description': _('Contract start')})
|
(0, 0, {'date': date_start, 'description': _('Contract start')})
|
||||||
@@ -165,20 +170,15 @@ class ContractContract(models.Model):
|
|||||||
lambda x: not x.sent
|
lambda x: not x.sent
|
||||||
)
|
)
|
||||||
if modification_ids_not_sent:
|
if modification_ids_not_sent:
|
||||||
contract_modification_subtype = self.env.ref(
|
record.message_post_with_template(
|
||||||
'contract.mail_message_subtype_contract_modification'
|
self.env.ref(
|
||||||
|
"contract.mail_template_contract_modification"
|
||||||
|
).id,
|
||||||
|
notif_layout="contract.template_contract_modification",
|
||||||
|
subtype_id=self.env.ref(
|
||||||
|
'contract.mail_message_subtype_contract_modification'
|
||||||
|
).id
|
||||||
)
|
)
|
||||||
notified_partners = record.message_follower_ids.filtered(
|
|
||||||
lambda x: contract_modification_subtype in x.subtype_ids
|
|
||||||
).mapped('partner_id')
|
|
||||||
if notified_partners:
|
|
||||||
record.message_post_with_template(
|
|
||||||
self.env.ref(
|
|
||||||
"contract.mail_template_contract_modification"
|
|
||||||
).id,
|
|
||||||
partner_ids=[(4, x.id) for x in notified_partners],
|
|
||||||
notif_layout="contract.template_contract_modification",
|
|
||||||
)
|
|
||||||
modification_ids_not_sent.write({'sent': True})
|
modification_ids_not_sent.write({'sent': True})
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
@@ -485,7 +485,9 @@ class ContractContract(models.Model):
|
|||||||
lambda x: invoice_create_subtype in x.subtype_ids
|
lambda x: invoice_create_subtype in x.subtype_ids
|
||||||
).mapped('partner_id')
|
).mapped('partner_id')
|
||||||
if partner_ids:
|
if partner_ids:
|
||||||
invoices.message_subscribe(partner_ids=partner_ids.ids)
|
(
|
||||||
|
invoices & item._get_related_invoices()
|
||||||
|
).message_subscribe(partner_ids=partner_ids.ids)
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _finalize_and_create_invoices(self, invoices_values):
|
def _finalize_and_create_invoices(self, invoices_values):
|
||||||
|
|||||||
@@ -135,11 +135,11 @@ class TestContract(TestContractBase):
|
|||||||
return self.env['contract.template.line'].create(vals)
|
return self.env['contract.template.line'].create(vals)
|
||||||
|
|
||||||
def test_add_modifications(self):
|
def test_add_modifications(self):
|
||||||
|
partner2 = self.partner.copy()
|
||||||
|
subtype = self.env.ref('contract.mail_message_subtype_contract_modification')
|
||||||
self.contract.message_subscribe(
|
self.contract.message_subscribe(
|
||||||
partner_ids=self.contract.partner_id.ids,
|
partner_ids=partner2.ids,
|
||||||
subtype_ids=self.env.ref(
|
subtype_ids=subtype.ids
|
||||||
'contract.mail_message_subtype_contract_modification'
|
|
||||||
).ids
|
|
||||||
)
|
)
|
||||||
# Check initial modification auto-creation
|
# Check initial modification auto-creation
|
||||||
self.assertEqual(len(self.contract.modification_ids), 1)
|
self.assertEqual(len(self.contract.modification_ids), 1)
|
||||||
@@ -163,12 +163,16 @@ class TestContract(TestContractBase):
|
|||||||
)
|
)
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
self.assertGreaterEqual(len(self.contract.message_partner_ids), 2)
|
partner_ids = self.contract.message_follower_ids.filtered(
|
||||||
mail_messages = self.env["mail.message"].search([
|
lambda x: subtype in x.subtype_ids
|
||||||
|
).mapped('partner_id')
|
||||||
|
self.assertGreaterEqual(len(partner_ids), 2)
|
||||||
|
total_mail_messages = self.env["mail.message"].search_count([
|
||||||
("model", "=", "contract.contract"),
|
("model", "=", "contract.contract"),
|
||||||
("res_id", "=", self.contract.id),
|
("res_id", "=", self.contract.id),
|
||||||
|
("subtype_id", "=", subtype.id)
|
||||||
])
|
])
|
||||||
self.assertGreaterEqual(len(mail_messages), 2)
|
self.assertGreaterEqual(total_mail_messages, 1)
|
||||||
|
|
||||||
def test_check_discount(self):
|
def test_check_discount(self):
|
||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
@@ -256,7 +260,7 @@ class TestContract(TestContractBase):
|
|||||||
self.contract.recurring_create_invoice()
|
self.contract.recurring_create_invoice()
|
||||||
invoice_daily = self.contract._get_related_invoices()
|
invoice_daily = self.contract._get_related_invoices()
|
||||||
self.assertTrue(invoice_daily)
|
self.assertTrue(invoice_daily)
|
||||||
self.assertEqual(len(invoice_daily.message_partner_ids.ids), 2)
|
self.assertEqual(len(invoice_daily.message_partner_ids.ids), 1)
|
||||||
|
|
||||||
def test_contract_weekly_post_paid(self):
|
def test_contract_weekly_post_paid(self):
|
||||||
recurring_next_date = to_date('2018-03-01')
|
recurring_next_date = to_date('2018-03-01')
|
||||||
|
|||||||
Reference in New Issue
Block a user