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:
committed by
Francisco Ivan Anton Prieto
parent
b0e137dd71
commit
a6bafcd4d3
@@ -1,9 +1,10 @@
|
||||
# Copyright 2004-2010 OpenERP SA
|
||||
# Copyright 2014 Angel Moya <angel.moya@domatix.com>
|
||||
# Copyright 2015-2020 Tecnativa - Pedro M. Baeza
|
||||
# Copyright 2016-2018 Carlos Dauden <carlos.dauden@tecnativa.com>
|
||||
# Copyright 2016-2018 Tecnativa - Carlos Dauden
|
||||
# Copyright 2016-2017 LasLabs Inc.
|
||||
# Copyright 2018 ACSONE SA/NV
|
||||
# Copyright 2021 Tecnativa - Víctor Martínez
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, fields, models
|
||||
@@ -162,11 +163,12 @@ class ContractContract(models.Model):
|
||||
)
|
||||
if modification_ids_not_sent:
|
||||
if not self.env.context.get("skip_modification_mail"):
|
||||
record.message_post_with_template(
|
||||
self.env.ref("contract.mail_template_contract_modification").id,
|
||||
subtype_id=self.env.ref(
|
||||
record.with_context(
|
||||
default_subtype_id=self.env.ref(
|
||||
"contract.mail_message_subtype_contract_modification"
|
||||
).id,
|
||||
).message_post_with_template(
|
||||
self.env.ref("contract.mail_template_contract_modification").id,
|
||||
email_layout_xmlid="contract.template_contract_modification",
|
||||
)
|
||||
modification_ids_not_sent.write({"sent": True})
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# Copyright 2018 Tecnativa - Carlos Dauden
|
||||
# Copyright 2018-2020 Tecnativa - Pedro M. Baeza
|
||||
# Copyright 2021 Tecnativa - Víctor Martínez
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from collections import namedtuple
|
||||
@@ -180,14 +181,42 @@ class TestContract(TestContractBase):
|
||||
vals.update(overrides)
|
||||
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):
|
||||
partner2 = self.partner.copy()
|
||||
subtype = self.env.ref("contract.mail_message_subtype_contract_modification")
|
||||
self.contract.message_subscribe(
|
||||
partner_ids=partner2.ids, subtype_ids=subtype.ids,
|
||||
partner_ids=partner2.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
|
||||
self.assertEqual(len(self.contract.modification_ids), 1)
|
||||
exclude_ids = self._get_mail_messages_prev(self.contract, subtype)
|
||||
self.contract.write(
|
||||
{
|
||||
"modification_ids": [
|
||||
@@ -196,18 +225,12 @@ class TestContract(TestContractBase):
|
||||
]
|
||||
}
|
||||
)
|
||||
partner_ids = self.contract.message_follower_ids.filtered(
|
||||
lambda x: subtype in x.subtype_ids
|
||||
).mapped("partner_id")
|
||||
self.assertGreaterEqual(len(partner_ids), 2)
|
||||
total_mail_messages = self.env["mail.message"].search(
|
||||
[
|
||||
("model", "=", "contract.contract"),
|
||||
("res_id", "=", self.contract.id),
|
||||
("subtype_id", "=", subtype.id),
|
||||
]
|
||||
mail_messages = self._get_mail_messages(exclude_ids, self.contract, subtype)
|
||||
self.assertGreaterEqual(len(mail_messages), 1)
|
||||
self.assertEqual(
|
||||
mail_messages[0].notification_ids.mapped("res_partner_id").ids,
|
||||
self.contract.partner_id.ids,
|
||||
)
|
||||
self.assertGreaterEqual(len(total_mail_messages), 1)
|
||||
|
||||
def test_check_discount(self):
|
||||
with self.assertRaises(ValidationError):
|
||||
|
||||
Reference in New Issue
Block a user