From e648f5fbe48d8728b7ffb93c8736cf13e1585d88 Mon Sep 17 00:00:00 2001 From: len-odoo Date: Mon, 15 Oct 2018 13:11:16 +0000 Subject: [PATCH] [FIX] sale: convert invoice values to the sale order currency If the invoice is not in the same currency as the sale order, then there was an inconsistency in the sales report, as it was considered to be the unit currency. We keep the initial computation in case where the invoice currency is the same. opw 1890381 closes odoo/odoo#27797 --- addons/sale/models/sale.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py index b70657578f5..a2148cc9985 100644 --- a/addons/sale/models/sale.py +++ b/addons/sale/models/sale.py @@ -750,11 +750,17 @@ class SaleOrderLine(models.Model): 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')) - # Total invoiced amount - invoiced_amount_total = sum(invoice_lines.mapped('price_total')) - # Total refunded amount refund_invoice_lines = refund_invoices.mapped('invoice_line_ids').filtered(lambda l: l.product_id == line.product_id) - refund_amount_total = sum(refund_invoice_lines.mapped('price_total')) + # 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: + invoiced_amount_total = sum([inv_line.currency_id.with_context({'date': inv_line.invoice_id.date}).compute(inv_line.price_total, line.currency_id) + for inv_line in invoice_lines]) + refund_amount_total = sum([inv_line.currency_id.with_context({'date': inv_line.invoice_id.date}).compute(inv_line.price_total, line.currency_id) + for inv_line in refund_invoice_lines]) + else: + invoiced_amount_total = sum(invoice_lines.mapped('price_total')) + refund_amount_total = sum(refund_invoice_lines.mapped('price_total')) # Total of remaining amount to invoice on the sale ordered (and draft invoice included) to support upsell (when # delivered quantity is higher than ordered one). Draft invoice are ignored on purpose, the 'to invoice' should # come only from the SO lines.