From 53eba74a77499fcf200532522644156f3ca03176 Mon Sep 17 00:00:00 2001 From: Nikul Chaudhary Date: Tue, 17 Dec 2019 18:13:23 +0530 Subject: [PATCH] [FIX] Fixed Issue #440 (when calling Scheduled Actions) --- contract_sale_invoicing/models/contract.py | 28 ++++++++++--------- .../tests/test_contract_sale_invoicing.py | 7 +++++ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/contract_sale_invoicing/models/contract.py b/contract_sale_invoicing/models/contract.py index ca5094e7..d2b79465 100644 --- a/contract_sale_invoicing/models/contract.py +++ b/contract_sale_invoicing/models/contract.py @@ -16,16 +16,18 @@ class ContractContract(models.Model): @api.multi def _recurring_create_invoice(self, date_ref=False): invoices = super()._recurring_create_invoice(date_ref) - if not self.invoicing_sales: - return invoices - sales = self.env['sale.order'].search([ - ('analytic_account_id', '=', self.group_id.id), - ('partner_invoice_id', 'child_of', - self.partner_id.commercial_partner_id.ids), - ('invoice_status', '=', 'to invoice'), - ('date_order', '<=', - '{} 23:59:59'.format(self.recurring_next_date)), - ]) - if sales: - invoice_ids = sales.action_invoice_create() - invoices |= self.env['account.invoice'].browse(invoice_ids)[:1] + for rec in self: + if not rec.invoicing_sales: + return invoices + sales = self.env['sale.order'].search([ + ('analytic_account_id', '=', rec.group_id.id), + ('partner_invoice_id', 'child_of', + rec.partner_id.commercial_partner_id.ids), + ('invoice_status', '=', 'to invoice'), + ('date_order', '<=', + '{} 23:59:59'.format(rec.recurring_next_date)), + ]) + if sales: + invoice_ids = sales.action_invoice_create() + invoices |= self.env['account.invoice'].browse(invoice_ids)[:1] + return invoices diff --git a/contract_sale_invoicing/tests/test_contract_sale_invoicing.py b/contract_sale_invoicing/tests/test_contract_sale_invoicing.py index 0e0d5134..9b41193a 100644 --- a/contract_sale_invoicing/tests/test_contract_sale_invoicing.py +++ b/contract_sale_invoicing/tests/test_contract_sale_invoicing.py @@ -45,3 +45,10 @@ class TestContractSaleInvoicing(TestContractBase): self.sale_order.action_confirm() self.contract.recurring_create_invoice() self.assertEqual(self.sale_order.invoice_status, 'to invoice') + + def test_multi_contract_recurring_create_invoice(self): + self.contract.copy() + self.contract.copy() + self.contract.copy() + self.contract.copy() + self.env['contract.contract'].cron_recurring_create_invoice()