From cc37ca4b2e5c9662eeeb7d25bd60d13166a88721 Mon Sep 17 00:00:00 2001 From: Daniel Reis Date: Wed, 29 Jun 2016 13:10:08 +0100 Subject: [PATCH] Improvements on the implementation --- .../models/account_analytic_analysis.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) 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 eb366831..8d300c5b 100644 --- a/contract_invoice_merge_by_partner/models/account_analytic_analysis.py +++ b/contract_invoice_merge_by_partner/models/account_analytic_analysis.py @@ -12,19 +12,19 @@ class PurchaseOrderLine(models.Model): def _recurring_create_invoice(self, automatic=False): invoice_obj = self.env['account.invoice'] invoices = invoice_obj.browse( - super(PurchaseOrderLine, self)._recurring_create_invoice(automatic) - ) + super(PurchaseOrderLine, self)._recurring_create_invoice( + automatic)) res = [] unlink_list = [] for partner in invoices.mapped('partner_id'): - inv_to_merge = invoices.filtered(lambda x: x.partner_id == partner) - if partner.contract_invoice_merge and (len(inv_to_merge) > 1): - invoices_info = inv_to_merge.do_merge() - res.extend(invoices_info.keys()) - for inv_ids_list in invoices_info.values(): - unlink_list.extend(inv_ids_list) + inv_to_merge = invoices.filtered( + lambda x: x.partner_id.id == partner) + if partner.contract_invoice_merge and len(inv_to_merge) > 1: + invoices_merged = inv_to_merge.do_merge() + res.extend(invoices_merged) + unlink_list.extend(inv_to_merge) else: - res.extend(inv_to_merge.ids) + res.extend(inv_to_merge) if unlink_list: invoice_obj.browse(unlink_list).unlink() return res