[IMP] contract: Add followers to invoices created

This commit is contained in:
Víctor Martínez
2020-11-30 10:23:08 +01:00
parent 95fe13df70
commit 912d7385a9
5 changed files with 44 additions and 4 deletions

View File

@@ -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",

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" ?>
<odoo noupdate="1">
<record id="mail_message_subtype_invoice_created" model="mail.message.subtype">
<field name="name">Invoice created</field>
<field name="res_model">contract.contract</field>
</record>
</odoo>

View File

@@ -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

View File

@@ -1,11 +1,15 @@
* Pedro M. Baeza <pedro.baeza@tecnativa.com>
* Carlos Dauden <carlos.dauden@tecnativa.com>
* Angel Moya <angel.moya@domatix.com>
* Dave Lasley <dave@laslabs.com>
* Vicent Cubells <vicent.cubells@tecnativa.com>
* Miquel Raïch <miquel.raich@eficent.com>
* Souheil Bejaoui <souheil.bejaoui@acsone.eu>
* Thomas Binsfeld <thomas.binsfeld@acsone.eu>
* Rafael Blasco <rafael.blasco@tecnativa.com>
* Guillaume Vandamme <guillaume.vandamme@acsone.eu>
* Raphaël Reverdy <raphael.reverdy@akretion.com>
* `Tecnativa <https://www.tecnativa.com>`_:
* Pedro M. Baeza
* Carlos Dauden
* Vicent Cubells
* Rafael Blasco
* Víctor Martínez

View File

@@ -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")