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 2004-2010 OpenERP SA
|
||||||
# Copyright 2014 Angel Moya <angel.moya@domatix.com>
|
# Copyright 2014 Angel Moya <angel.moya@domatix.com>
|
||||||
# Copyright 2015-2020 Tecnativa - Pedro M. Baeza
|
# 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 2016-2017 LasLabs Inc.
|
||||||
# Copyright 2018 ACSONE SA/NV
|
# Copyright 2018 ACSONE SA/NV
|
||||||
|
# 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 odoo import api, fields, models
|
from odoo import api, fields, models
|
||||||
@@ -162,11 +163,12 @@ 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(
|
||||||
self.env.ref("contract.mail_template_contract_modification").id,
|
default_subtype_id=self.env.ref(
|
||||||
subtype_id=self.env.ref(
|
|
||||||
"contract.mail_message_subtype_contract_modification"
|
"contract.mail_message_subtype_contract_modification"
|
||||||
).id,
|
).id,
|
||||||
|
).message_post_with_template(
|
||||||
|
self.env.ref("contract.mail_template_contract_modification").id,
|
||||||
email_layout_xmlid="contract.template_contract_modification",
|
email_layout_xmlid="contract.template_contract_modification",
|
||||||
)
|
)
|
||||||
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-2020 Tecnativa - Pedro M. Baeza
|
# 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).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
@@ -180,14 +181,42 @@ 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, 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
|
# 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": [
|
||||||
@@ -196,18 +225,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(
|
self.contract.partner_id.ids,
|
||||||
[
|
|
||||||
("model", "=", "contract.contract"),
|
|
||||||
("res_id", "=", self.contract.id),
|
|
||||||
("subtype_id", "=", subtype.id),
|
|
||||||
]
|
|
||||||
)
|
)
|
||||||
self.assertGreaterEqual(len(total_mail_messages), 1)
|
|
||||||
|
|
||||||
def test_check_discount(self):
|
def test_check_discount(self):
|
||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
|
|||||||
Reference in New Issue
Block a user