Skip to content

Commit

Permalink
[FIX][12.0] add ability to set discount percent or amount on decimal …
Browse files Browse the repository at this point in the history
…number
  • Loading branch information
sergiocorato committed Oct 28, 2024
1 parent 2afd44b commit 9342e90
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions l10n_it_fatturapa_out/wizard/wizard_export_fatturapa.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -706,9 +706,12 @@ def setDettaglioLinea(
NumeroLinea=str(line_no),
Descrizione=encode_for_export(line.name, 1000),
PrezzoUnitario='{prezzo:.{precision}f}'.format(
prezzo=prezzo_unitario, precision=price_precision),
prezzo=prezzo_unitario,
precision=price_precision
if prezzo_unitario and price_precision < 8 else 2),
Quantita='{qta:.{precision}f}'.format(
qta=quantity, precision=uom_precision),
qta=quantity, precision=uom_precision
if quantity and uom_precision < 8 else 3),
UnitaMisura=line.uom_id and (
unidecode(line.uom_id.name)) or None,
PrezzoTotale='%.2f' % float_round(
Expand Down Expand Up @@ -769,10 +772,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):
Expand Down

0 comments on commit 9342e90

Please sign in to comment.