From bf9e47e47967eeea2e2b7629d28aa1528fc5ec19 Mon Sep 17 00:00:00 2001 From: Sven Fuehr Date: Thu, 23 Nov 2023 09:51:40 +0100 Subject: [PATCH] [FIX] l10n_es_edi_tbai: fix discount computation traceback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently there is a traceback in case of a 100% discount on an invoice line. This commit fixes the issue by computing the discount differently. Previously it was tried to calculate the discount amount from the discounted value and the discount factor. This is (mathematically) not possible if the discounted value is 0. After this commit we compute and use the undiscounted value in case the discount is 100% to compute the discount amount. The computation was adapted from '_prepare_edi_vals_to_export' from account.move.line Reproduce 1. Install l10n_es_edi_tbai 2. Select the Spanish company 3. Settings > Accounting: Ensure "Test Mode" is set in Spain Localization section 4. Create a new invoice with Spanish customer 5. Add a line with a 100% discount 6. Confirm the invoice 7. Process the invocie with TicketBAI 8. Error / Traceback opw-3572426 closes odoo/odoo#144571 X-original-commit: 74aa7136fea8bd0f962c577fba89bbd4f7618742 Signed-off-by: Cedric Snauwaert Signed-off-by: Sven Führ (svfu) --- addons/l10n_es_edi_tbai/models/account_edi_format.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/addons/l10n_es_edi_tbai/models/account_edi_format.py b/addons/l10n_es_edi_tbai/models/account_edi_format.py index 949abaea35c..87983fc37fa 100644 --- a/addons/l10n_es_edi_tbai/models/account_edi_format.py +++ b/addons/l10n_es_edi_tbai/models/account_edi_format.py @@ -320,7 +320,12 @@ class AccountEdiFormat(models.Model): refund_sign = (1 if values['is_refund'] else -1) invoice_lines = [] for line in invoice.invoice_line_ids.filtered(lambda line: line.display_type not in ('line_section', 'line_note')): - discount = line.balance / (1 - line.discount / 100) * line.discount / 100 + if line.discount == 100.0: + gross_price_subtotal = line.price_unit * line.quantity + else: + gross_price_subtotal = line.price_subtotal / (1 - line.discount / 100.0) + discount = (gross_price_subtotal - line.price_subtotal) * refund_sign + if not any([t.l10n_es_type == 'sujeto_isp' for t in line.tax_ids]): total = line.price_total * abs(line.balance / line.amount_currency if line.amount_currency != 0 else 1) * -refund_sign else: