Skip to content

Commit

Permalink
[14.0][IMP] make template data overridable
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMule71 committed Jun 29, 2022
1 parent d71d34c commit a74346a
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 62 deletions.
68 changes: 6 additions & 62 deletions l10n_it_fatturapa_out/wizard/efattura.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,67 +195,9 @@ def in_eu(partner):
return False

def get_all_taxes(record):
"""Generate summary data for taxes.
Odoo does that for us, but only for nonzero taxes.
SdI expects a summary for every tax mentioned in the invoice,
even those with price_total == 0.
"""

def _key(tax_id):
return tax_id.id

out_computed = {}
# existing tax lines
tax_ids = record.line_ids.filtered(lambda line: line.tax_line_id)
for tax_id in tax_ids:
tax_line_id = tax_id.tax_line_id
aliquota = format_numbers(tax_line_id.amount)
key = _key(tax_line_id)
out_computed[key] = {
"AliquotaIVA": aliquota,
"Natura": tax_line_id.kind_id.code,
# 'Arrotondamento':'',
"ImponibileImporto": tax_id.tax_base_amount,
"Imposta": tax_id.price_total,
"EsigibilitaIVA": tax_line_id.payability,
}
if tax_line_id.law_reference:
out_computed[key]["RiferimentoNormativo"] = encode_for_export(
tax_line_id.law_reference, 100
)

out = {}
# check for missing tax lines
for line in record.invoice_line_ids:
if line.display_type in ("line_section", "line_note"):
# notes and sections
# we ignore line.tax_ids altogether,
# (it is popolated with a default tax usually)
# and use another tax in the template
continue
for tax_id in line.tax_ids:
aliquota = format_numbers(tax_id.amount)
key = _key(tax_id)
if key in out_computed:
continue
if key not in out:
out[key] = {
"AliquotaIVA": aliquota,
"Natura": tax_id.kind_id.code,
# 'Arrotondamento':'',
"ImponibileImporto": line.price_subtotal,
"Imposta": 0.0,
"EsigibilitaIVA": tax_id.payability,
}
if tax_id.law_reference:
out[key]["RiferimentoNormativo"] = encode_for_export(
tax_id.law_reference, 100
)
else:
out[key]["ImponibileImporto"] += line.price_subtotal
out[key]["Imposta"] += 0.0
out.update(out_computed)
return out
# wrapper to a method in wizard (for better overriding)
wiz = self.env["wizard.export.fatturapa"]
return wiz.getAllTaxes(record)

def get_importo(line):
str_number = str(line.discount)
Expand Down Expand Up @@ -315,7 +257,9 @@ def fpa_to_eur(amount, invoice):
},
"fpa_to_eur": fpa_to_eur,
}
return template_values

wiz = self.env["wizard.export.fatturapa"]
return wiz.getTemplateValues(template_values)

def to_xml(self, env):
"""Create the xml file content.
Expand Down
87 changes: 87 additions & 0 deletions l10n_it_fatturapa_out/wizard/wizard_export_fatturapa.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@

from odoo import api, fields, models
from odoo.exceptions import UserError
from odoo.tools import float_repr
from odoo.tools.translate import _

from odoo.addons.l10n_it_account.tools.account_tools import encode_for_export

from .efattura import EFatturaOut

_logger = logging.getLogger(__name__)
Expand All @@ -26,6 +29,18 @@ def id_generator(
return "".join(random.choice(chars) for dummy in range(size))


def format_numbers(number):
# format number to str with between 2 and 8 decimals (event if it's .00)
number_splited = str(number).split(".")
if len(number_splited) == 1:
return "%.02f" % number

cents = number_splited[1]
if len(cents) > 8:
return "%.08f" % number
return float_repr(number, max(2, len(cents)))


class WizardExportFatturapa(models.TransientModel):
_name = "wizard.export.fatturapa"
_description = "Export E-invoice"
Expand Down Expand Up @@ -87,6 +102,78 @@ def getImportoTotale(self, invoice):
# in the total amount of the invoice)
return invoice.amount_total

@api.model
def getAllTaxes(self, invoice):
"""Generate summary data for taxes.
Odoo does that for us, but only for nonzero taxes.
SdI expects a summary for every tax mentioned in the invoice,
even those with price_total == 0.
"""

def _key(tax_id):
return tax_id.id

out_computed = {}
# existing tax lines
tax_ids = invoice.line_ids.filtered(lambda line: line.tax_line_id)
for tax_id in tax_ids:
tax_line_id = tax_id.tax_line_id
aliquota = format_numbers(tax_line_id.amount)
key = _key(tax_line_id)
out_computed[key] = {
"AliquotaIVA": aliquota,
"Natura": tax_line_id.kind_id.code,
# 'Arrotondamento':'',
"ImponibileImporto": tax_id.tax_base_amount,
"Imposta": tax_id.price_total,
"EsigibilitaIVA": tax_line_id.payability,
}
if tax_line_id.law_reference:
out_computed[key]["RiferimentoNormativo"] = encode_for_export(
tax_line_id.law_reference, 100
)

out = {}
# check for missing tax lines
for line in invoice.invoice_line_ids:
if line.display_type in ("line_section", "line_note"):
# notes and sections
# we ignore line.tax_ids altogether,
# (it is popolated with a default tax usually)
# and use another tax in the template
continue
for tax_id in line.tax_ids:
aliquota = format_numbers(tax_id.amount)
key = _key(tax_id)
if key in out_computed:
continue
if key not in out:
out[key] = {
"AliquotaIVA": aliquota,
"Natura": tax_id.kind_id.code,
# 'Arrotondamento':'',
"ImponibileImporto": line.price_subtotal,
"Imposta": 0.0,
"EsigibilitaIVA": tax_id.payability,
}
if tax_id.law_reference:
out[key]["RiferimentoNormativo"] = encode_for_export(
tax_id.law_reference, 100
)
else:
out[key]["ImponibileImporto"] += line.price_subtotal
out[key]["Imposta"] += 0.0
out.update(out_computed)
return out

@api.model
def getTemplateValues(self, template_values):
"""
Entry point for other modules to override values
(and helper functions) passed to template
"""
return template_values

def group_invoices_by_partner(self):
def split_list(my_list, size):
it = iter(my_list)
Expand Down

0 comments on commit a74346a

Please sign in to comment.