From c273694bbd125f040a73219f2eea623a0954876c Mon Sep 17 00:00:00 2001 From: Carlos Incaser Date: Tue, 14 Jun 2016 11:47:46 +0200 Subject: [PATCH] [IMP] contract_invoice_merge_by_partner: Tests and improvements. --- contract_invoice_merge_by_partner/README.rst | 6 +++- .../models/account_analytic_analysis.py | 7 ++-- .../test_contract_invoice_merge_by_partner.py | 33 +++++++++++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/contract_invoice_merge_by_partner/README.rst b/contract_invoice_merge_by_partner/README.rst index 2371ab5d..4dba40bc 100644 --- a/contract_invoice_merge_by_partner/README.rst +++ b/contract_invoice_merge_by_partner/README.rst @@ -18,7 +18,11 @@ To install this module you need *account_invoice_merge*, available in: Usage ===== -#. Go to ... +#. Go to *Sales > Contracts* and create some contrats with same partner +#. Go to *Settings > Automation > Scheduled Actions* +#. Select *Generate Recurring Invoices from Contracts* +#. Set previous time that now in *Next Execution Date* +#. Go to *Invoicing > Customer Invoices* and show merged invoice .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot diff --git a/contract_invoice_merge_by_partner/models/account_analytic_analysis.py b/contract_invoice_merge_by_partner/models/account_analytic_analysis.py index 23c46dcf..5d31287c 100644 --- a/contract_invoice_merge_by_partner/models/account_analytic_analysis.py +++ b/contract_invoice_merge_by_partner/models/account_analytic_analysis.py @@ -10,7 +10,8 @@ class PurchaseOrderLine(models.Model): @api.multi def _recurring_create_invoice(self, automatic=False): - invoices = self.env['account.invoice'].browse( + invoice_obj = self.env['account.invoice'] + invoices = invoice_obj.browse( super(PurchaseOrderLine, self)._recurring_create_invoice(automatic) ) res = [] @@ -22,7 +23,9 @@ class PurchaseOrderLine(models.Model): keep_references=True, date_invoice=False) res.extend(invoices_info.keys()) for inv_ids_list in invoices_info.values(): - unlink_list.append(inv_ids_list) + unlink_list.extend(inv_ids_list) else: res.append(inv_to_merge.id) + if unlink_list: + invoice_obj.browse(unlink_list).unlink() return res diff --git a/contract_invoice_merge_by_partner/tests/test_contract_invoice_merge_by_partner.py b/contract_invoice_merge_by_partner/tests/test_contract_invoice_merge_by_partner.py index 147689c9..e7defcd6 100644 --- a/contract_invoice_merge_by_partner/tests/test_contract_invoice_merge_by_partner.py +++ b/contract_invoice_merge_by_partner/tests/test_contract_invoice_merge_by_partner.py @@ -9,3 +9,36 @@ class TestContractInvoiceMergeByPartner(TransactionCase): """ Use case : Prepare some data for current test case """ def setUp(self): super(TestContractInvoiceMergeByPartner, self).setUp() + #self.partner = self.env.ref('base.res_partner_2') + self.partner = self.env['res.partner'].create( + {'customer': True, + 'name': "Test Customer" + }) + self.product = self.env.ref('product.product_product_consultant') + self.uom = self.env.ref('product.product_uom_hour') + self.contract1 = self.env['account.analytic.account'].create({ + 'name': 'Test contract', + 'partner_id': self.partner.id, + 'type': 'contract', + 'recurring_invoices': True, + 'recurring_rule_type': 'monthly', + 'recurring_interval': 1, + 'recurring_invoice_line_ids': [ + (0, 0, {'quantity': 2.0, + 'price_unit': 100.0, + 'name': self.product.name, + 'product_id': self.product.id, + 'uom_id': self.uom.id})], + }) + self.contract2 = self.contract1.copy() + self.contract3 = self.contract1.copy() + self.contract4 = self.contract1.copy() + + def test_invoices_merged(self): + self.env['account.analytic.account']._cron_recurring_create_invoice() + invoices = self.env['account.invoice'].search( + [('partner_id', '=', self.partner.id)]) + inv_draft = invoices.filtered(lambda x: x.state == 'draft') + self.assertEqual(len(inv_draft), 1) + inv_cancel = invoices.filtered(lambda x: x.state == 'cancel') + self.assertFalse(inv_cancel)