From 397ec536f1cbeba646b131fa89cfabf09a1aa4b4 Mon Sep 17 00:00:00 2001 From: sergiocorato Date: Tue, 3 Sep 2024 10:17:20 +0200 Subject: [PATCH] [FIX][12.0] add ability to set discount percent or amount on decimal number --- .../wizard/wizard_export_fatturapa.py | 35 ++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/l10n_it_fatturapa_out/wizard/wizard_export_fatturapa.py b/l10n_it_fatturapa_out/wizard/wizard_export_fatturapa.py index 6fb19f1472c8..4f63287c468d 100644 --- a/l10n_it_fatturapa_out/wizard/wizard_export_fatturapa.py +++ b/l10n_it_fatturapa_out/wizard/wizard_export_fatturapa.py @@ -16,7 +16,7 @@ from odoo.tools.translate import _ from odoo.exceptions import UserError from odoo.addons.l10n_it_account.tools.account_tools import encode_for_export -from odoo.tools.float_utils import float_round +from odoo.tools.float_utils import float_round, float_repr from odoo.addons.l10n_it_fatturapa.bindings.fatturapa import ( FatturaElettronica, @@ -769,10 +769,35 @@ def setDettaglioLinea( def setScontoMaggiorazione(self, line): res = [] if line.discount: - res.append(ScontoMaggiorazioneType( - Tipo='SC', - Percentuale='%.2f' % float_round(line.discount, 8) - )) + str_number = str(line.discount) + number = str_number[::-1].find(".") + if number <= 2: + net_discount = False + else: + net_discount = line.price_unit * line.discount / 100 + if net_discount: + price_precision = self.env['decimal.precision'].precision_get( + 'Product Price for XML e-invoices') + if net_discount >= 0: + tipo = 'SC' + else: + tipo = 'MG' + res.append(ScontoMaggiorazioneType( + Tipo=tipo, + Importo=float_repr( + float_round(net_discount, price_precision), + price_precision, + ) + )) + else: + if line.discount >= 0: + tipo = 'SC' + else: + tipo = 'MG' + res.append(ScontoMaggiorazioneType( + Tipo=tipo, + Percentuale='%.2f' % float_round(line.discount, 8) + )) return res def setDatiRiepilogo(self, invoice, body):