[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
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user