diff --git a/contract/__manifest__.py b/contract/__manifest__.py
index 1dc3f76c8..3c18be147 100644
--- a/contract/__manifest__.py
+++ b/contract/__manifest__.py
@@ -28,6 +28,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 65beb2ac1..b338bc5f8 100644
--- a/contract/models/contract.py
+++ b/contract/models/contract.py
@@ -466,9 +466,22 @@ class ContractContract(models.Model):
)
return invoice
+ @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)
+
def _recurring_create_invoice(self, date_ref=False):
invoices_values = self._prepare_recurring_invoices_values(date_ref)
moves = self.env["account.move"].create(invoices_values)
+ self._invoice_followers(moves)
self._compute_recurring_next_date()
return moves
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 0bb2952a6..8069965ae 100644
--- a/contract/tests/test_contract.py
+++ b/contract/tests/test_contract.py
@@ -220,6 +220,21 @@ class TestContract(TestContractBase):
self.assertEqual(self.acct_line.recurring_next_date, recurring_next_date)
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), 1)
+
def test_contract_weekly_post_paid(self):
recurring_next_date = to_date("2018-03-01")
last_date_invoiced = to_date("2018-02-21")