From 5f9a6aae682de546d23fe11fc3bb5792e5187f0b Mon Sep 17 00:00:00 2001 From: Carlos Fonseca Date: Wed, 18 Oct 2023 22:27:35 +0100 Subject: [PATCH] [FIX] convert unit price in invoice lines to company currency. --- .../models/account_move.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/l10n_pt_account_invoicexpress/models/account_move.py b/l10n_pt_account_invoicexpress/models/account_move.py index 3924cee5..31a361bf 100644 --- a/l10n_pt_account_invoicexpress/models/account_move.py +++ b/l10n_pt_account_invoicexpress/models/account_move.py @@ -108,6 +108,7 @@ def _get_invoicexpress_prefix(self, doctype): }.get(doctype) def _prepare_invoicexpress_lines(self): + date_today = fields.Date.today() # FIXME: set user lang, based on country? lines = self.invoice_line_ids.filtered( lambda l: l.display_type not in ("line_section", "line_note") @@ -119,12 +120,23 @@ def _prepare_invoicexpress_lines(self): tax = line.tax_ids[:1] # If not tax set, force zero VAT tax_detail = {"name": tax.name or "IVA0", "value": tax.amount or 0.0} + # Because InvoiceXpress expects unit_price in EUR, check if we need to convert + # line currency to company currency (company should use EUR as default currency) + if line.currency_id.id == line.company_id.currency_id.id: + price_unit = line.price_unit + else: + price_unit = line.currency_id._convert( + line.price_unit, + line.company_id.currency_id, + line.company_id, + date_today + ) items.append( { "name": line.product_id.default_code or line.product_id.display_name, "description": line._get_invoicexpress_descr(), - "unit_price": abs(line.balance), + "unit_price": price_unit, "quantity": line.quantity, "discount": line.discount, "tax": tax_detail,