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.