From c05abb2db837138ef784034aa8bab2fe2e014206 Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Wed, 28 Nov 2018 10:19:15 +0000 Subject: [PATCH] [FIX] sale: Wrong amount amount invoiced in sale.report Steps to reproduce the bug: Let's consider a product P with a unit price = 10 - Create a SO for two lines of the same product P - Validate the SO and create the invoice - Refund the invoice and validate it - Go to Reporting > Sale report and select "Invoiced amount" as measures Bug= -20 was displayed for the invoiced amount. Technically, the two refund invoice lines of P were used two times in function _compute_invoice_amount because for each SO line we catched all the refund lines of the same product. opw:1906445 closes odoo/odoo#29095 --- addons/sale/models/sale.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py index 53614f0e78e..0f3848ec69e 100644 --- a/addons/sale/models/sale.py +++ b/addons/sale/models/sale.py @@ -746,12 +746,15 @@ class SaleOrderLine(models.Model): 'invoice_lines.invoice_id.refund_invoice_ids.state', 'invoice_lines.invoice_id.refund_invoice_ids.amount_total') def _compute_invoice_amount(self): + refund_lines_product = self.env['account.invoice.line'] for line in self: # Invoice lines referenced by this line invoice_lines = line.invoice_lines.filtered(lambda l: l.invoice_id.state in ('open', 'paid')) # Refund invoices linked to invoice_lines refund_invoices = invoice_lines.mapped('invoice_id.refund_invoice_ids').filtered(lambda inv: inv.state in ('open', 'paid')) - refund_invoice_lines = refund_invoices.mapped('invoice_line_ids').filtered(lambda l: l.product_id == line.product_id) + refund_invoice_lines = (refund_invoices.mapped('invoice_line_ids') - refund_lines_product).filtered(lambda l: l.product_id == line.product_id) + if refund_invoice_lines: + refund_lines_product |= refund_invoice_lines # If the currency of the invoice differs from the sale order, we need to convert the values if line.invoice_lines and line.invoice_lines[0].currency_id \ and line.invoice_lines[0].currency_id != line.currency_id: