mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[FIX] contract: Modification mail + Auto-create follower in contract creation related to partner_id
Co-Authored-By: Pedro M. Baeza <pedro.baeza@tecnativa.com>
This commit is contained in:
committed by
Francisco Ivan Anton Prieto
parent
4614944dff
commit
01a142e6d3
@@ -5,13 +5,13 @@
|
|||||||
# Copyright 2017 Tecnativa - Vicent Cubells
|
# Copyright 2017 Tecnativa - Vicent Cubells
|
||||||
# Copyright 2016-2017 LasLabs Inc.
|
# Copyright 2016-2017 LasLabs Inc.
|
||||||
# Copyright 2018-2019 ACSONE SA/NV
|
# Copyright 2018-2019 ACSONE SA/NV
|
||||||
# Copyright 2020 Tecnativa - Pedro M. Baeza
|
# Copyright 2020-2021 Tecnativa - Pedro M. Baeza
|
||||||
# Copyright 2020 Tecnativa - Víctor Martínez
|
# Copyright 2020 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).
|
||||||
|
|
||||||
{
|
{
|
||||||
"name": "Recurring - Contracts Management",
|
"name": "Recurring - Contracts Management",
|
||||||
"version": "13.0.2.2.1",
|
"version": "13.0.2.2.2",
|
||||||
"category": "Contract Management",
|
"category": "Contract Management",
|
||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
"author": "Tecnativa, ACSONE SA/NV, Odoo Community Association (OCA)",
|
"author": "Tecnativa, ACSONE SA/NV, Odoo Community Association (OCA)",
|
||||||
|
|||||||
@@ -131,11 +131,15 @@ 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": [
|
||||||
@@ -151,18 +155,13 @@ 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,
|
||||||
|
subtype_id=self.env.ref(
|
||||||
|
"contract.mail_message_subtype_contract_modification"
|
||||||
|
).id,
|
||||||
|
email_layout_xmlid="contract.template_contract_modification",
|
||||||
)
|
)
|
||||||
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],
|
|
||||||
email_layout_xmlid="contract.template_contract_modification",
|
|
||||||
)
|
|
||||||
modification_ids_not_sent.write({"sent": True})
|
modification_ids_not_sent.write({"sent": True})
|
||||||
|
|
||||||
def _compute_access_url(self):
|
def _compute_access_url(self):
|
||||||
@@ -541,7 +540,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
|
||||||
|
)
|
||||||
|
|
||||||
def _recurring_create_invoice(self, date_ref=False):
|
def _recurring_create_invoice(self, date_ref=False):
|
||||||
invoices_values = self._prepare_recurring_invoices_values(date_ref)
|
invoices_values = self._prepare_recurring_invoices_values(date_ref)
|
||||||
|
|||||||
@@ -172,11 +172,10 @@ 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=subtype.ids,
|
||||||
subtype_ids=self.env.ref(
|
|
||||||
"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)
|
||||||
@@ -188,11 +187,18 @@ class TestContract(TestContractBase):
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
self.assertGreaterEqual(len(self.contract.message_partner_ids), 1)
|
partner_ids = self.contract.message_follower_ids.filtered(
|
||||||
mail_messages = self.env["mail.message"].search(
|
lambda x: subtype in x.subtype_ids
|
||||||
[("model", "=", "contract.contract"), ("res_id", "=", self.contract.id)]
|
).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),
|
||||||
|
]
|
||||||
)
|
)
|
||||||
self.assertGreaterEqual(len(mail_messages), 2)
|
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):
|
||||||
@@ -257,7 +263,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), 1)
|
self.assertGreaterEqual(len(invoice_daily.message_follower_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