Skip to content

Commit

Permalink
[14.0][MIG] l10n_it_fatturapa_in - fixes - da fare lo squash col prec…
Browse files Browse the repository at this point in the history
…edente

Commit separato solo per agevolare il merge da parte di chi fa il
tracking del branch durante lo sviluppo.
  • Loading branch information
TheMule71 committed Dec 18, 2020
1 parent 6c3cedc commit 101e5f3
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 24 deletions.
7 changes: 5 additions & 2 deletions l10n_it_fatturapa_in/models/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ def e_inv_dati_ritenuta(self):
)
def _compute_e_invoice_validation_error(self):
self.ensure_one()
self.e_invoice_validation_error = False
self.e_invoice_validation_message = False

bills_to_check = self.filtered(
lambda inv: inv.move_type in ["in_invoice", "in_refund"]
and inv.state in ["draft", "open", "paid"]
Expand Down Expand Up @@ -246,8 +249,8 @@ def name_get(self):
invoice.amount_total_signed,
invoice.currency_id.symbol,
)
if invoice.origin:
name += ", %s" % invoice.origin
if invoice.invoice_origin:
name += ", %s" % invoice.invoice_origin
res.append((invoice.id, name))
else:
res.append(tup)
Expand Down
39 changes: 22 additions & 17 deletions l10n_it_fatturapa_in/models/attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,26 +86,31 @@ def get_xml_string(self):
@api.depends("ir_attachment_id.datas")
def _compute_xml_data(self):
for att in self:
att.xml_supplier_id = False
att.invoices_number = False
att.invoices_total = False
att.invoices_date = False
wiz_obj = self.env["wizard.import.fatturapa"].with_context(
from_attachment=att
)
fatt = wiz_obj.get_invoice_obj(att)
cedentePrestatore = fatt.FatturaElettronicaHeader.CedentePrestatore
partner_id = wiz_obj.getCedPrest(cedentePrestatore)
att.xml_supplier_id = partner_id
att.invoices_number = len(fatt.FatturaElettronicaBody)
att.invoices_total = 0
invoices_date = []
for invoice_body in fatt.FatturaElettronicaBody:
dgd = invoice_body.DatiGenerali.DatiGeneraliDocumento
att.invoices_total += float(dgd.ImportoTotaleDocumento or 0)
invoice_date = format_date(
att.with_context(lang=att.env.user.lang).env,
fields.Date.from_string(dgd.Data),
)
if invoice_date not in invoices_date:
invoices_date.append(invoice_date)
att.invoices_date = " ".join(invoices_date)
if wiz_obj:
fatt = wiz_obj.get_invoice_obj(att)
cedentePrestatore = fatt.FatturaElettronicaHeader.CedentePrestatore
partner_id = wiz_obj.getCedPrest(cedentePrestatore)
att.xml_supplier_id = partner_id
att.invoices_number = len(fatt.FatturaElettronicaBody)
att.invoices_total = 0
invoices_date = []
for invoice_body in fatt.FatturaElettronicaBody:
dgd = invoice_body.DatiGenerali.DatiGeneraliDocumento
att.invoices_total += float(dgd.ImportoTotaleDocumento or 0)
invoice_date = format_date(
att.with_context(lang=att.env.user.lang).env,
fields.Date.from_string(dgd.Data),
)
if invoice_date not in invoices_date:
invoices_date.append(invoice_date)
att.invoices_date = " ".join(invoices_date)

@api.depends("in_invoice_ids")
def _compute_registered(self):
Expand Down
2 changes: 1 addition & 1 deletion l10n_it_fatturapa_in/security/rules.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<field eval="True" name="global" />
<field
name="domain_force"
>['|',('company_id','=',False),('company_id','child_of',[company.id])]</field>
>['|',('company_id','=',False),('company_id','in',company_ids)]</field>
</record>

</odoo>
60 changes: 56 additions & 4 deletions l10n_it_fatturapa_in/wizard/efattura.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,58 @@
_logger = logging.getLogger(__name__)
_logger.setLevel(logging.DEBUG)

XSD_SCHEMA = "Schema_del_file_xml_FatturaPA_versione_1.2.1.xsd"
# XMLSchema del SdI
# Contiene un riferimento ad un'antica spec di xmldsig-core-schema.xsd, non presente
# nei vari XML Catalog recenti, es. sulla mia Fedora 33
# $ fgrep xmldsig-core-schema.xsd /etc/xml/catalog
# <system systemId="http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd" uri="file:///usr/share/xml/xmldsig-core-schema.xsd"/> # noqa: B950
# <uri name="http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd" uri="file:///usr/share/xml/xmldsig-core-schema.xsd"/> # noqa: B950
# L'assenza dell'entry nel Catalog fa sì che il documento venga scaricato
# ogni volta, e - a giudicare dalla lentezza nella risposta - qualcuno
# al w3.org ha notato la cosa (la lentezza è relativa a quel solo URL).
#
# Noi interpretiamo lo Schema due volte, per lxml, per le correzioni
# pre-verifica, e successivamente per xmlschema. Entrambe le librerie hanno
# modalità di modificare il comportamento di download delle import esterne.
# Il file xmldsig-core-schema.xsd locale è ottenuto dall'URL indicato dal SdI.
# Per lxml.etree, va creata al classe Resover. Per xmlschema, si indicano
# le locations aggiuntive.

_XSD_SCHEMA = "Schema_del_file_xml_FatturaPA_versione_1.2.1.xsd"
_xml_schema_1_2_1 = get_module_resource(
"l10n_it_fatturapa", "bindings", "xsd", _XSD_SCHEMA
)
_old_xsd_specs = get_module_resource(
"l10n_it_fatturapa", "bindings", "xsd", "xmldsig-core-schema.xsd"
)

_xsd_schema = get_module_resource("l10n_it_fatturapa", "bindings", "xsd", XSD_SCHEMA)
_root = etree.parse(_xsd_schema)
_logger = logging.getLogger(__name__)


def _schema_parse():
# fix <xs:import namespace="http://www.w3.org/2000/09/xmldsig#"
# schemaLocation="http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd" /> # noqa: B950
class VeryOldXSDSpecResolverTYVMSdI(etree.Resolver):
def resolve(self, system_url, public_id, context):
if (
system_url
== "http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd" # noqa: B950
):
_logger.info(
"mapping URL for %r to local file %r",
system_url,
_old_xsd_specs,
)
return self.resolve_filename(self._old_xsd_specs, context)
else:
return super().resolve(system_url, public_id, context)

parser = etree.XMLParser()
parser.resolvers.add(VeryOldXSDSpecResolverTYVMSdI())
return etree.parse(_xml_schema_1_2_1, parser)


_root = _schema_parse()

date_types = {}
datetime_types = {}
Expand Down Expand Up @@ -111,6 +159,7 @@ def _fix_xmlstring(xml_string):
xml_string,
)
# HACK#2 - in attesa di fix su xmlschema
# https://github.com/sissaschool/xmlschema/issues/213
xml_string = re.sub(r">\s*0.0000000+\s*<", ">0.00<", xml_string)
return xml_string.encode()

Expand All @@ -131,7 +180,10 @@ def __setitem__(self, *attr, **kwattr):
return self.__dict__.__setitem__(*attr, **kwattr)

# TODO: crearlo una tantum?
validator = xmlschema.XMLSchema(_xsd_schema)
validator = xmlschema.XMLSchema(
_xml_schema_1_2_1,
locations={"http://www.w3.org/2000/09/xmldsig#": _old_xsd_specs},
)

xml_string = _fix_xmlstring(xml_string)
root = etree.fromstring(xml_string)
Expand Down

0 comments on commit 101e5f3

Please sign in to comment.