From 145692af31d42e5aca743d166f875d98e5630381 Mon Sep 17 00:00:00 2001 From: Harshad Date: Tue, 4 Aug 2020 17:08:18 +0530 Subject: [PATCH 1/2] [FIX] looping contract in recurring_create_invoice to support multi recordset --- contract_sale_invoicing/models/contract.py | 29 ++++++++++++---------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/contract_sale_invoicing/models/contract.py b/contract_sale_invoicing/models/contract.py index ca5094e77..8562eb797 100644 --- a/contract_sale_invoicing/models/contract.py +++ b/contract_sale_invoicing/models/contract.py @@ -16,16 +16,19 @@ 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 contract in self: + if not contract.invoicing_sales or not contract.recurring_next_date: + continue + sales = self.env['sale.order'].search([ + ('analytic_account_id', '=', contract.group_id.id), + ('partner_invoice_id', 'child_of', + contract.partner_id.commercial_partner_id.ids), + ('invoice_status', '=', 'to invoice'), + ('date_order', '<=', + '{} 23:59:59'.format(contract.recurring_next_date)), + ]) + if sales: + invoice_ids = sales.action_invoice_create() + invoices |= self.env['account.invoice'].browse(invoice_ids)[:1] + + return invoices From dcc55ee073dda2f82efe7d856e732de58e976464 Mon Sep 17 00:00:00 2001 From: Harshad Date: Thu, 6 Aug 2020 21:50:25 +0530 Subject: [PATCH 2/2] [FIX] looping over invoices to write a message from reccuring invoice create --- contract/models/contract.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/contract/models/contract.py b/contract/models/contract.py index 1445f2f73..ca15ec89b 100644 --- a/contract/models/contract.py +++ b/contract/models/contract.py @@ -524,17 +524,18 @@ class ContractContract(models.Model): This method triggers the creation of the next invoices of the contracts even if their next invoicing date is in the future. """ - invoice = self._recurring_create_invoice() - if invoice: - self.message_post( - body=_( - 'Contract manually invoiced: ' - 'Invoice' - '' + invoices = self._recurring_create_invoice() + if invoices: + for invoice in invoices: + self.message_post( + body=_( + 'Contract manually invoiced: ' + 'Invoice' + '' + ) + % (invoice._name, invoice.id) ) - % (invoice._name, invoice.id) - ) - return invoice + return invoices @api.multi def _recurring_create_invoice(self, date_ref=False):