From fcacbcb2cd20bfdcdb4b40417533ddd2049b8005 Mon Sep 17 00:00:00 2001 From: Francisco Martins Date: Fri, 13 Oct 2023 17:24:28 +0100 Subject: [PATCH 1/5] [FIX] send total amount as euro in invoice --- l10n_pt_account_invoicexpress/models/account_move.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/l10n_pt_account_invoicexpress/models/account_move.py b/l10n_pt_account_invoicexpress/models/account_move.py index 6c14dc09..3924cee5 100644 --- a/l10n_pt_account_invoicexpress/models/account_move.py +++ b/l10n_pt_account_invoicexpress/models/account_move.py @@ -124,7 +124,7 @@ def _prepare_invoicexpress_lines(self): "name": line.product_id.default_code or line.product_id.display_name, "description": line._get_invoicexpress_descr(), - "unit_price": line.price_unit, + "unit_price": abs(line.balance), "quantity": line.quantity, "discount": line.discount, "tax": tax_detail, From 5f9a6aae682de546d23fe11fc3bb5792e5187f0b Mon Sep 17 00:00:00 2001 From: Carlos Fonseca Date: Wed, 18 Oct 2023 22:27:35 +0100 Subject: [PATCH 2/5] [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, From c6ae71471703e2fb613c063f00a84d8a73eb6449 Mon Sep 17 00:00:00 2001 From: Carlos Fonseca Date: Wed, 18 Oct 2023 22:37:10 +0100 Subject: [PATCH 3/5] [REF] convert currency to follow PEP8 guidelines when using multiple lines --- l10n_pt_account_invoicexpress/models/account_move.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/l10n_pt_account_invoicexpress/models/account_move.py b/l10n_pt_account_invoicexpress/models/account_move.py index 31a361bf..977f20be 100644 --- a/l10n_pt_account_invoicexpress/models/account_move.py +++ b/l10n_pt_account_invoicexpress/models/account_move.py @@ -129,7 +129,7 @@ def _prepare_invoicexpress_lines(self): line.price_unit, line.company_id.currency_id, line.company_id, - date_today + date_today, ) items.append( { From fae36d583a8181addf45808c89c212dae3ab1285 Mon Sep 17 00:00:00 2001 From: Carlos Fonseca Date: Thu, 19 Oct 2023 11:23:26 +0100 Subject: [PATCH 4/5] Update l10n_pt_account_invoicexpress/models/account_move.py Co-authored-by: Daniel Reis --- l10n_pt_account_invoicexpress/models/account_move.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/l10n_pt_account_invoicexpress/models/account_move.py b/l10n_pt_account_invoicexpress/models/account_move.py index 977f20be..61305e65 100644 --- a/l10n_pt_account_invoicexpress/models/account_move.py +++ b/l10n_pt_account_invoicexpress/models/account_move.py @@ -122,7 +122,7 @@ def _prepare_invoicexpress_lines(self): 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: + if line.currency_id == line.company_id.currency_id: price_unit = line.price_unit else: price_unit = line.currency_id._convert( From ebf4a37cea2d2bc54403f40ef8e4278b4c829550 Mon Sep 17 00:00:00 2001 From: Carlos Fonseca Date: Fri, 29 Dec 2023 11:41:25 +0000 Subject: [PATCH 5/5] [IMP] currency conversion date when converting other currencies to company currency --- l10n_pt_account_invoicexpress/models/account_move.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/l10n_pt_account_invoicexpress/models/account_move.py b/l10n_pt_account_invoicexpress/models/account_move.py index 61305e65..48d483df 100644 --- a/l10n_pt_account_invoicexpress/models/account_move.py +++ b/l10n_pt_account_invoicexpress/models/account_move.py @@ -108,7 +108,6 @@ 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") @@ -129,7 +128,7 @@ def _prepare_invoicexpress_lines(self): line.price_unit, line.company_id.currency_id, line.company_id, - date_today, + line.move_id.invoice_date or line.move_id.date or fields.Date.context_today(line), ) items.append( {