From e093a51bbc5c3987561a0dea471416c29e708424 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mart=C3=ADnez?= Date: Mon, 30 Nov 2020 10:23:08 +0100 Subject: [PATCH] [IMP] contract: Add followers to invoices created --- contract/__manifest__.py | 1 + contract/data/mail_message_subtype.xml | 7 +++++++ contract/models/contract.py | 13 +++++++++++++ contract/readme/CONTRIBUTORS.rst | 12 ++++++++---- contract/tests/test_contract.py | 15 +++++++++++++++ 5 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 contract/data/mail_message_subtype.xml diff --git a/contract/__manifest__.py b/contract/__manifest__.py index b7248ea89..042930aa7 100644 --- a/contract/__manifest__.py +++ b/contract/__manifest__.py @@ -30,6 +30,7 @@ 'data/contract_cron.xml', 'data/contract_renew_cron.xml', 'data/mail_template.xml', + 'data/mail_message_subtype.xml', 'data/ir_ui_menu.xml', 'wizards/contract_line_wizard.xml', 'wizards/contract_manually_create_invoice.xml', diff --git a/contract/data/mail_message_subtype.xml b/contract/data/mail_message_subtype.xml new file mode 100644 index 000000000..f9fcbfc9a --- /dev/null +++ b/contract/data/mail_message_subtype.xml @@ -0,0 +1,7 @@ + + + + Invoice created + contract.contract + + diff --git a/contract/models/contract.py b/contract/models/contract.py index b7c0f50b3..02957b08e 100644 --- a/contract/models/contract.py +++ b/contract/models/contract.py @@ -417,6 +417,18 @@ class ContractContract(models.Model): """ invoices.compute_taxes() + @api.model + def _invoice_followers(self, invoices): + invoice_create_subtype = self.sudo().env.ref( + 'contract.mail_message_subtype_invoice_created' + ) + for item in self: + partner_ids = item.message_follower_ids.filtered( + lambda x: invoice_create_subtype in x.subtype_ids + ).mapped('partner_id') + if partner_ids: + invoices.message_subscribe(partner_ids=partner_ids.ids) + @api.model def _finalize_and_create_invoices(self, invoices_values): """This method: @@ -435,6 +447,7 @@ class ContractContract(models.Model): ) invoices = self.env['account.invoice'].create(final_invoices_values) self._finalize_invoice_creation(invoices) + self._invoice_followers(invoices) return invoices @api.model diff --git a/contract/readme/CONTRIBUTORS.rst b/contract/readme/CONTRIBUTORS.rst index ef3f91ff9..6fd5286a2 100644 --- a/contract/readme/CONTRIBUTORS.rst +++ b/contract/readme/CONTRIBUTORS.rst @@ -1,11 +1,15 @@ -* Pedro M. Baeza -* Carlos Dauden * Angel Moya * Dave Lasley -* Vicent Cubells * Miquel Raïch * Souheil Bejaoui * Thomas Binsfeld -* Rafael Blasco * Guillaume Vandamme * Raphaël Reverdy + +* `Tecnativa `_: + + * Pedro M. Baeza + * Carlos Dauden + * Vicent Cubells + * Rafael Blasco + * Víctor Martínez diff --git a/contract/tests/test_contract.py b/contract/tests/test_contract.py index d44dc7102..ec2ba0c66 100644 --- a/contract/tests/test_contract.py +++ b/contract/tests/test_contract.py @@ -201,6 +201,21 @@ class TestContract(TestContractBase): ) self.assertEqual(self.acct_line.last_date_invoiced, last_date_invoiced) + def test_contract_invoice_followers(self): + self.acct_line.recurring_next_date = '2018-02-23' + self.acct_line.recurring_rule_type = 'daily' + self.contract.pricelist_id = False + self.contract.message_subscribe( + partner_ids=self.contract.partner_id.ids, + subtype_ids=self.env.ref( + 'contract.mail_message_subtype_invoice_created' + ).ids + ) + 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), 2) + def test_contract_weekly_post_paid(self): recurring_next_date = to_date('2018-03-01') last_date_invoiced = to_date('2018-02-21')