[FIX] contract: Modification mail + Auto-create follower in contract creation related to partner_id + Set groups in back_in_edit_mode link to show only correct users + Prevent first contract modification mail to partner

Co-Authored-By: Pedro M. Baeza <pedro.baeza@tecnativa.com>
This commit is contained in:
Víctor Martínez
2021-01-04 16:47:48 +01:00
committed by Christopher Rogos
parent c0aa7936c1
commit 67d5c43618
4 changed files with 36 additions and 22 deletions

View File

@@ -5,13 +5,13 @@
# Copyright 2017 Tecnativa - Vicent Cubells
# Copyright 2016-2017 LasLabs Inc.
# 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
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Recurring - Contracts Management",
"version": "13.0.2.2.1",
"version": "13.0.2.3.1",
"category": "Contract Management",
"license": "AGPL-3",
"author": "Tecnativa, ACSONE SA/NV, Odoo Community Association (OCA)",

View File

@@ -113,6 +113,12 @@ class ContractContract(models.Model):
string="Modifications",
)
def get_formview_id(self, access_uid=None):
if self.contract_type == "sale":
return self.env.ref("contract.contract_contract_customer_form_view").id
else:
return self.env.ref("contract.contract_contract_supplier_form_view").id
@api.model_create_multi
def create(self, vals_list):
records = super().create(vals_list)
@@ -131,12 +137,16 @@ class ContractContract(models.Model):
@api.model
def _set_start_contract_modification(self):
subtype_id = self.env.ref("contract.mail_message_subtype_contract_modification")
for record in self:
if record.contract_line_ids:
date_start = min(record.contract_line_ids.mapped("date_start"))
else:
date_start = record.create_date
record.write(
record.message_subscribe(
partner_ids=[record.partner_id.id], subtype_ids=[subtype_id.id]
)
record.with_context(skip_modification_mail=True).write(
{
"modification_ids": [
(0, 0, {"date": date_start, "description": _("Contract start")})
@@ -151,16 +161,12 @@ class ContractContract(models.Model):
lambda x: not x.sent
)
if modification_ids_not_sent:
contract_modification_subtype = self.env.ref(
"contract.mail_message_subtype_contract_modification"
)
notified_partners = record.message_follower_ids.filtered(
lambda x: contract_modification_subtype in x.subtype_ids
).mapped("partner_id")
if notified_partners:
if not self.env.context.get("skip_modification_mail"):
record.message_post_with_template(
self.env.ref("contract.mail_template_contract_modification").id,
partner_ids=[(4, x.id) for x in notified_partners],
subtype_id=self.env.ref(
"contract.mail_message_subtype_contract_modification"
).id,
email_layout_xmlid="contract.template_contract_modification",
)
modification_ids_not_sent.write({"sent": True})
@@ -541,7 +547,9 @@ class ContractContract(models.Model):
lambda x: invoice_create_subtype in x.subtype_ids
).mapped("partner_id")
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):
invoices_values = self._prepare_recurring_invoices_values(date_ref)

View File

@@ -172,11 +172,10 @@ class TestContract(TestContractBase):
return self.env["contract.template.line"].create(vals)
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=self.contract.partner_id.ids,
subtype_ids=self.env.ref(
"contract.mail_message_subtype_contract_modification"
).ids,
partner_ids=partner2.ids, subtype_ids=subtype.ids,
)
# Check initial modification auto-creation
self.assertEqual(len(self.contract.modification_ids), 1)
@@ -188,11 +187,18 @@ class TestContract(TestContractBase):
]
}
)
self.assertGreaterEqual(len(self.contract.message_partner_ids), 1)
mail_messages = self.env["mail.message"].search(
[("model", "=", "contract.contract"), ("res_id", "=", self.contract.id)]
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),
]
)
self.assertGreaterEqual(len(mail_messages), 2)
self.assertGreaterEqual(len(total_mail_messages), 1)
def test_check_discount(self):
with self.assertRaises(ValidationError):
@@ -257,7 +263,7 @@ class TestContract(TestContractBase):
self.contract._recurring_create_invoice()
invoice_daily = self.contract._get_related_invoices()
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):
recurring_next_date = to_date("2018-03-01")

View File

@@ -82,7 +82,7 @@
</template>
<template id="portal_contract_page" name="My Contract">
<t t-call="portal.portal_layout">
<t t-set="o_portal_fullwidth_alert">
<t t-set="o_portal_fullwidth_alert" groups="account.group_account_invoice">
<t t-call="portal.portal_back_in_edit_mode">
<t
t-set="backend_url"