From c3bdff329bf4d1281c4eda4a198d83d685ff1f5e Mon Sep 17 00:00:00 2001 From: Daniel Reis Date: Wed, 29 Jun 2016 13:10:08 +0100 Subject: [PATCH 1/3] Improvements on the implementation --- .../models/account_analytic_analysis.py | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 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..1fe7e1be 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,17 @@ 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'): + for partner in set(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) + if partner.contract_invoice_merge: + invoices_merged = inv_to_merge.do_merge() + res.extend(invoices_merged) + unlink_list.extend(inv_to_merge) else: - res.extend(inv_to_merge.ids) - if unlink_list: - invoice_obj.browse(unlink_list).unlink() + res.extend(inv_to_merge) + for inv in unlink_list: + inv.unlink() return res From 85942a1addaa5265305acb5149159d1b3878e5b2 Mon Sep 17 00:00:00 2001 From: Daniel Reis Date: Thu, 30 Jun 2016 16:28:28 +0100 Subject: [PATCH 2/3] Fixed for loop and mass unlink --- .../models/account_analytic_analysis.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 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 1fe7e1be..9ca946ea 100644 --- a/contract_invoice_merge_by_partner/models/account_analytic_analysis.py +++ b/contract_invoice_merge_by_partner/models/account_analytic_analysis.py @@ -15,14 +15,15 @@ class PurchaseOrderLine(models.Model): super(PurchaseOrderLine, self)._recurring_create_invoice(automatic)) res = [] unlink_list = [] - for partner in set(invoices.mapped('partner_id')): - inv_to_merge = invoices.filtered(lambda x: x.partner_id == partner) + for partner in invoices.mapped('partner_id'): + inv_to_merge = invoices.filtered( + lambda x: x.partner_id.id == partner) if partner.contract_invoice_merge: invoices_merged = inv_to_merge.do_merge() res.extend(invoices_merged) unlink_list.extend(inv_to_merge) else: res.extend(inv_to_merge) - for inv in unlink_list: - inv.unlink() + if unlink_list: + invoice_obj.unlink([x.id for x in unlink_list]) return res From 26f984a7732491e87e4eb756caf0056a7ac71484 Mon Sep 17 00:00:00 2001 From: Daniel Reis Date: Mon, 4 Jul 2016 11:53:11 +0100 Subject: [PATCH 3/3] Fix unlink, >1 filter and lines too long --- .../models/account_analytic_analysis.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 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 9ca946ea..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,18 +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.id == partner) - if partner.contract_invoice_merge: + 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) if unlink_list: - invoice_obj.unlink([x.id for x in unlink_list]) + invoice_obj.browse(unlink_list).unlink() return res