mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[FIX] contract: Changed modification_mail auto to appear like email and not internal comment
This commit is contained in:
@@ -177,14 +177,15 @@ class ContractContract(models.Model):
|
|||||||
)
|
)
|
||||||
if modification_ids_not_sent:
|
if modification_ids_not_sent:
|
||||||
if not self.env.context.get('skip_modification_mail'):
|
if not self.env.context.get('skip_modification_mail'):
|
||||||
record.message_post_with_template(
|
record.with_context(
|
||||||
|
default_subtype_id=self.env.ref(
|
||||||
|
'contract.mail_message_subtype_contract_modification'
|
||||||
|
).id,
|
||||||
|
).message_post_with_template(
|
||||||
self.env.ref(
|
self.env.ref(
|
||||||
"contract.mail_template_contract_modification"
|
"contract.mail_template_contract_modification"
|
||||||
).id,
|
).id,
|
||||||
notif_layout="contract.template_contract_modification",
|
notif_layout="contract.template_contract_modification",
|
||||||
subtype_id=self.env.ref(
|
|
||||||
'contract.mail_message_subtype_contract_modification'
|
|
||||||
).id
|
|
||||||
)
|
)
|
||||||
modification_ids_not_sent.write({'sent': True})
|
modification_ids_not_sent.write({'sent': True})
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
# Copyright 2018 Tecnativa - Carlos Dauden
|
# Copyright 2018 Tecnativa - Carlos Dauden
|
||||||
# Copyright 2018 Tecnativa - Pedro M. Baeza
|
# Copyright 2018 Tecnativa - Pedro M. Baeza
|
||||||
|
# Copyright 2021 Tecnativa - Víctor Martínez
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
@@ -134,15 +135,35 @@ class TestContract(TestContractBase):
|
|||||||
vals.update(overrides)
|
vals.update(overrides)
|
||||||
return self.env['contract.template.line'].create(vals)
|
return self.env['contract.template.line'].create(vals)
|
||||||
|
|
||||||
|
def _get_mail_messages_prev(self, contract, subtype):
|
||||||
|
return self.env["mail.message"].search([
|
||||||
|
("model", "=", "contract.contract"),
|
||||||
|
("res_id", "=", contract.id),
|
||||||
|
("subtype_id", "=", subtype.id),
|
||||||
|
]).ids
|
||||||
|
|
||||||
|
def _get_mail_messages(self, exclude_ids, contract, subtype):
|
||||||
|
return self.env["mail.message"].search([
|
||||||
|
("model", "=", "contract.contract"),
|
||||||
|
("res_id", "=", contract.id),
|
||||||
|
("subtype_id", "=", subtype.id),
|
||||||
|
('id', 'not in', exclude_ids)
|
||||||
|
])
|
||||||
|
|
||||||
def test_add_modifications(self):
|
def test_add_modifications(self):
|
||||||
partner2 = self.partner.copy()
|
partner2 = self.partner.copy()
|
||||||
subtype = self.env.ref('contract.mail_message_subtype_contract_modification')
|
|
||||||
self.contract.message_subscribe(
|
self.contract.message_subscribe(
|
||||||
partner_ids=partner2.ids,
|
partner_ids=partner2.ids,
|
||||||
subtype_ids=subtype.ids
|
subtype_ids=self.env.ref('mail.mt_comment').ids
|
||||||
)
|
)
|
||||||
|
subtype = self.env.ref('contract.mail_message_subtype_contract_modification')
|
||||||
|
partner_ids = self.contract.message_follower_ids.filtered(
|
||||||
|
lambda x: subtype in x.subtype_ids
|
||||||
|
).mapped('partner_id')
|
||||||
|
self.assertGreaterEqual(len(partner_ids), 1)
|
||||||
# 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)
|
||||||
|
exclude_ids = self._get_mail_messages_prev(self.contract, subtype)
|
||||||
self.contract.write({
|
self.contract.write({
|
||||||
'modification_ids': [
|
'modification_ids': [
|
||||||
(
|
(
|
||||||
@@ -163,16 +184,12 @@ class TestContract(TestContractBase):
|
|||||||
)
|
)
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
partner_ids = self.contract.message_follower_ids.filtered(
|
mail_messages = self._get_mail_messages(exclude_ids, self.contract, subtype)
|
||||||
lambda x: subtype in x.subtype_ids
|
self.assertGreaterEqual(len(mail_messages), 1)
|
||||||
).mapped('partner_id')
|
self.assertEqual(
|
||||||
self.assertGreaterEqual(len(partner_ids), 2)
|
mail_messages[0].notification_ids.mapped('res_partner_id').ids,
|
||||||
total_mail_messages = self.env["mail.message"].search_count([
|
self.contract.partner_id.ids
|
||||||
("model", "=", "contract.contract"),
|
)
|
||||||
("res_id", "=", self.contract.id),
|
|
||||||
("subtype_id", "=", subtype.id)
|
|
||||||
])
|
|
||||||
self.assertGreaterEqual(total_mail_messages, 1)
|
|
||||||
|
|
||||||
def test_check_discount(self):
|
def test_check_discount(self):
|
||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
@@ -260,7 +277,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.assertTrue(self.contract.partner_id in invoice_daily.message_partner_ids)
|
||||||
|
|
||||||
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