Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX][12.0] add ability to set discount percent or amount on decimal number #4350

Open
wants to merge 1 commit into
base: 12.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading