From b2299fb4ff3ddcd1700535e009429394e2123cf3 Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Wed, 28 Mar 2018 17:22:38 +0200 Subject: [PATCH] [FIX] sale: invoice count on SO: only take inv on same company Before this commit, the smart button on the SO was computed with only the SO's name field In a multicompany setting, it could give up invoices from other companies After this commit, only the invoices of the same company as the order are accounted for OPW 1831551 closes #23925 --- addons/sale/models/sale.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py index 5d0dd9d83cd..6115911b718 100644 --- a/addons/sale/models/sale.py +++ b/addons/sale/models/sale.py @@ -59,7 +59,7 @@ class SaleOrder(models.Model): # Search for invoices which have been 'cancelled' (filter_refund = 'modify' in # 'account.invoice.refund') # use like as origin may contains multiple references (e.g. 'SO01, SO02') - refunds = invoice_ids.search([('origin', 'like', order.name)]).filtered(lambda r: r.type in ['out_invoice', 'out_refund']) + refunds = invoice_ids.search([('origin', 'like', order.name), ('company_id', '=', order.company_id.id)]).filtered(lambda r: r.type in ['out_invoice', 'out_refund']) invoice_ids |= refunds.filtered(lambda r: order.name in [origin.strip() for origin in r.origin.split(',')]) # Search for refunds as well refund_ids = self.env['account.invoice'].browse()