From 72cb16865c294efb56f4c0caa757c4120720b169 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Tue, 14 Aug 2018 16:19:20 +0200 Subject: [PATCH] [FIX] purchase: avoid non-sense domain on invoice's purchase order PO that can be linked to an invoice are filtered via a domain restricting the partner. However when no partner is selected yet, the domain was `('partner_id', 'child_of', False)` which, beside being horribly slow, was also useless as it returns ALL partners. Only generate a meaningfull domain. --- addons/purchase/invoice.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/addons/purchase/invoice.py b/addons/purchase/invoice.py index ad3b1e0cec7..52beb5433ad 100644 --- a/addons/purchase/invoice.py +++ b/addons/purchase/invoice.py @@ -23,11 +23,12 @@ class AccountInvoice(models.Model): purchase_line_ids = self.invoice_line_ids.mapped('purchase_line_id') purchase_ids = self.invoice_line_ids.mapped('purchase_id').filtered(lambda r: r.order_line <= purchase_line_ids) - result['domain'] = {'purchase_id': [ - ('invoice_status', '=', 'to invoice'), - ('partner_id', 'child_of', self.partner_id.id), - ('id', 'not in', purchase_ids.ids), - ]} + domain = [('invoice_status', '=', 'to invoice')] + if self.partner_id: + domain += [('partner_id', 'child_of', self.partner_id.id)] + if purchase_ids: + domain += [('id', 'not in', purchase_ids.ids)] + result['domain'] = {'purchase_id': domain} return result def _prepare_invoice_line_from_po_line(self, line):