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

[10.0] pyxb 1.2.6 #998

Merged
merged 1 commit into from
Apr 8, 2019
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ install:
- pip install unicodecsv
- pip install codicefiscale
- pip install unidecode==0.04.17
- pip install PyXB==1.2.5
- pip install PyXB==1.2.6

script:
- travis_run_tests
Expand Down
4 changes: 2 additions & 2 deletions l10n_it_fatturapa/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ Installation

**Italiano**

Questo modulo richiede PyXB 1.2.5
Questo modulo richiede PyXB 1.2.6

http://pyxb.sourceforge.net/

**English**

This module requires PyXB 1.2.5
This module requires PyXB 1.2.6

http://pyxb.sourceforge.net/

Expand Down
4 changes: 2 additions & 2 deletions l10n_it_fatturapa/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

{
'name': 'Italian Localization - Fattura elettronica - Base',
'version': '10.0.2.4.1',
'version': '10.0.2.5.0',
'category': 'Localization/Italy',
'summary': 'Fatture elettroniche',
'author': 'Davide Corio, Agile Business Group, Innoviu, '
Expand Down Expand Up @@ -40,7 +40,7 @@
'installable': True,
'external_dependencies': {
'python': [
'pyxb', # pyxb 1.2.5
'pyxb', # pyxb 1.2.6
'asn1crypto'
],
}
Expand Down
129 changes: 129 additions & 0 deletions l10n_it_fatturapa/bindings/FatturaPA_versione_1.2.1.xsd.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
--- Schema_del_file_xml_FatturaPA_versione_1.2.1.xsd.orig 2019-02-12 12:10:42.024629978 +0100
+++ Schema_del_file_xml_FatturaPA_versione_1.2.1.xsd 2019-02-13 18:16:23.629695305 +0100
@@ -4,7 +4,7 @@
xmlns="http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2"
targetNamespace="http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2"
version="1.2">
- <xsd:import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd"/>
+ <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"/>

<xs:element name="FatturaElettronica" type="FatturaElettronicaType">
<xs:annotation>
@@ -413,6 +413,11 @@
<xs:documentation>Parcella</xs:documentation>
</xs:annotation>
</xs:enumeration>
+ <xs:enumeration value="TD20">
+ <xs:annotation>
+ <xs:documentation>Autofattura</xs:documentation>
+ </xs:annotation>
+ </xs:enumeration>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="TipoRitenutaType">
@@ -1158,62 +1163,62 @@
</xs:simpleType>
<xs:simpleType name="String10Type">
<xs:restriction base="xs:normalizedString">
- <xs:pattern value="(\p{IsBasicLatin}{1,10})" />
+ <xs:pattern value="(\p{IsBasicLatin}{0,10})" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="String15Type">
<xs:restriction base="xs:normalizedString">
- <xs:pattern value="(\p{IsBasicLatin}{1,15})" />
+ <xs:pattern value="(\p{IsBasicLatin}{0,15})" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="String20Type">
<xs:restriction base="xs:normalizedString">
- <xs:pattern value="(\p{IsBasicLatin}{1,20})" />
+ <xs:pattern value="(\p{IsBasicLatin}{0,20})" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="String35Type">
<xs:restriction base="xs:normalizedString">
- <xs:pattern value="(\p{IsBasicLatin}{1,35})" />
+ <xs:pattern value="(\p{IsBasicLatin}{0,35})" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="String60Type">
<xs:restriction base="xs:normalizedString">
- <xs:pattern value="(\p{IsBasicLatin}{1,60})" />
+ <xs:pattern value="(\p{IsBasicLatin}{0,60})" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="String80Type">
<xs:restriction base="xs:normalizedString">
- <xs:pattern value="(\p{IsBasicLatin}{1,80})" />
+ <xs:pattern value="(\p{IsBasicLatin}{0,80})" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="String100Type">
<xs:restriction base="xs:normalizedString">
- <xs:pattern value="(\p{IsBasicLatin}{1,100})" />
+ <xs:pattern value="(\p{IsBasicLatin}{0,100})" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="String60LatinType">
<xs:restriction base="xs:normalizedString">
- <xs:pattern value="[\p{IsBasicLatin}\p{IsLatin-1Supplement}]{1,60}" />
+ <xs:pattern value="[\p{IsBasicLatin}\p{IsLatin-1Supplement}]{0,60}" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="String80LatinType">
<xs:restriction base="xs:normalizedString">
- <xs:pattern value="[\p{IsBasicLatin}\p{IsLatin-1Supplement}]{1,80}" />
+ <xs:pattern value="[\p{IsBasicLatin}\p{IsLatin-1Supplement}]{0,80}" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="String100LatinType">
<xs:restriction base="xs:normalizedString">
- <xs:pattern value="[\p{IsBasicLatin}\p{IsLatin-1Supplement}]{1,100}" />
+ <xs:pattern value="[\p{IsBasicLatin}\p{IsLatin-1Supplement}]{0,100}" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="String200LatinType">
<xs:restriction base="xs:normalizedString">
- <xs:pattern value="[\p{IsBasicLatin}\p{IsLatin-1Supplement}]{1,200}" />
+ <xs:pattern value="[\p{IsBasicLatin}\p{IsLatin-1Supplement}]{0,200}" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="String1000LatinType">
<xs:restriction base="xs:normalizedString">
- <xs:pattern value="[\p{IsBasicLatin}\p{IsLatin-1Supplement}]{1,1000}" />
+ <xs:pattern value="[\p{IsBasicLatin}\p{IsLatin-1Supplement}]{0,1000}" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="ProvinciaType">
@@ -1265,18 +1270,17 @@
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="Amount8DecimalType">
- <xs:restriction base="xs:decimal">
+ <xs:restriction base="xs:string">
<xs:pattern value="[\-]?[0-9]{1,11}\.[0-9]{2,8}" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="Amount2DecimalType">
- <xs:restriction base="xs:decimal">
+ <xs:restriction base="xs:string">
<xs:pattern value="[\-]?[0-9]{1,11}\.[0-9]{2}" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="RateType">
- <xs:restriction base="xs:decimal">
- <xs:maxInclusive value="100.00" />
+ <xs:restriction base="xs:string">
<xs:pattern value="[0-9]{1,3}\.[0-9]{2}" />
</xs:restriction>
</xs:simpleType>
@@ -1320,7 +1324,7 @@
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="QuantitaType">
- <xs:restriction base="xs:decimal">
+ <xs:restriction base="xs:string">
<xs:pattern value="[0-9]{1,12}\.[0-9]{2,8}" />
</xs:restriction>
</xs:simpleType>
35 changes: 35 additions & 0 deletions l10n_it_fatturapa/bindings/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Informazioni riguardanti la fatturazione elettronica

## Incongruenze rispetto alle specifiche del file xsd

* StringNNType: nelle specifiche da 1 a NN, lo SDI accetta da 0 a N
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok il file da cui parti è https://www.fatturapa.gov.it/export/fatturazione/sdi/fatturapa/v1.2.1/Schema_del_file_xml_FatturaPA_versione_1.2.1.xsd, ma dove hai trovato quello che SDI accetta o meno? (Posto che non dovrebbero essercene accidenti a loro)

Copy link
Member Author

@sherpya sherpya Mar 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non l'ho trovato io, è già nel codice corrente ma fatto direttamente nel codice python generato (vedi cb063e9#diff-f548cc151f6b5372dd653cb1c1378ba0)

Li ho riportati nell'xsd per minimizzare le modifiche al file generato

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concordo che è la soluzione più pulita, ma mi chiedevo il motivo di questi aggiustamenti, forse @eLBati lo sai?
Se avessimo un xsd di cosa accetta SDI sarebbe perfetto, ma forse esiste e solo io non lo trovo.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non c'è, ho visto su un pdf una fantomatica 1.3 ma non trovo l'xsd, io credo abbiano fatto la specifica ma poi nella pratica accettano anche stringa vuota

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SimoRubi ti chiedi da quale XSD sia stato generato l'attuale fatturapa_v_1_2.py? Penso da versioni precedenti dell'XSD pubblicato su https://www.fatturapa.gov.it/export/fatturazione/it/normativa/f-2.htm

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non esattamente @eLBati, mi (e ti) chiedo il motivo delle modifiche al file cb063e9#diff-f548cc151f6b5372dd653cb1c1378ba0, in particolare come mai le stringhe sono passate da {1, x} a {0, x}?
E' stato per a una nuova versione del XSD o altro?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SimoRubi il motivo è nel commento:

strings of blank spaces are allowed by SDI.
{1,60} would produce
SimpleFacetValueError: Type
{http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2}
String1000LatinType pattern constraint violated by value

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quindi sono modifiche fatte su base empirica? Cioè gli XML inviati a SDI fallivano quindi hai cambiato il codice? Speravo fossero dedotti da una qualche specifica su cosa accetta SDI

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ciò che accetta SDI è qui https://www.fatturapa.gov.it/export/fatturazione/sdi/fatturapa/v1.2.1/Schema_del_file_xml_FatturaPA_versione_1.2.1.xsd
Quindi nello specifico [\p{IsBasicLatin}\p{IsLatin-1Supplement}]{1,60}.
Il problema è che per pyXB (o meglio per python) la stringa " " non passa tale espressione, mentre per SDI sì

* Amount8DecimalType, Amount2DecimalType, RateType, QuantitaType sono xs:decimal
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modificare da decimal a string non mi pare proprio il massimo, quando rispondi alla mia domanda qui sopra vedo se ci possono essere altre soluzioni

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stessa cosa di su (la modifica c'era già), il problema è che xs:decimal non permette trailing zeros quindi 5.00 lo rappresenta come 5.0 quando crea una fattura
per esempio:
RateType ha un pattern [0-9]{1,3}\.[0-9]{2} che non è fattibile con un xs:decimal

forse si può aggiungere fractionMinDigits ma non so se pyxb lo considera, posso provare

ma la specifica vieta gli zeri finali, quindi li modifichiamo in xs:string

## Istruzioni per generazione nuovi bindings

* Scaricare il relativo xsd in locale
* Applicare la patch allegata, adattarla se necessario
* Generare i bindings utilizzando: `pyxbgen schema.xsd`
* Rimuovere i riferimenti locali dai file py con il comando (adattando l'url se differente):

`sed -i -e "s,$(pwd),https://www\.fatturapa\.gov\.it/export/fatturazione/sdi/fatturapa/v1\.2\.1,g" *.py`

* rinominare `binding.py` in `fatturapa_v_1_2.py`
* in cima ai files generati sostiture il commento con il nome del file con la seguente riga:
`# flake8: noqa`
* nel file `fatturapa_v_1_2` individuare la classe `DataFatturaType` ed aggiungere il seguente metodo:
* sostituire i files precedenti

```python
# remove tzinfo from parsed dates or pyxb will fail the comparison
def __new__(cls, *args, **kwargs):
result = super(DataFatturaType, cls).__new__(cls, *args, **kwargs)
return result.replace(tzinfo=None)
```

La patch dell'xsd modifica il range di caratteri delle stringhe portandolo da 1-N a 0-N,
trasforma in stringhe i decimali che hanno bisogno di zeri finali,
inoltre aggiungere il tipo documento TD20 (Autofattura).

Per la 1.2.1 inoltre corregge un errore di namespace.
12 changes: 3 additions & 9 deletions l10n_it_fatturapa/bindings/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
# -*- coding: utf-8 -*-
# Copyright 2015-2016 Lorenzo Battistini - Agile Business Group
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

import logging

_logger = logging.getLogger(__name__)

# pyxb is referenced in several in top-level statements in
# fatturapa_v_1_1, so we guard the import of the entire file
try:
from . import fatturapa_v_1_1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sherpya intendi qui? il try c'era mica già? temo comunque che il controllo fatto da Travis richieda il try dovunque ci siano import

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quello è un refuso nel codice corrente, nella mia pr ora è così:

import logging
  
_logger = logging.getLogger(__name__)

try:
    from . import fatturapa_v_1_2
except Exception as e:  # ImportError or pyxb.PyXBVersionError
    _logger.warning('%s: %s' % (e.__class__.__name__, e))

e se non hai pyxb 1.2.6:

     from odoo.addons.l10n_it_fatturapa.bindings import fatturapa_v_1_2
  File "/home/sherpya/workspace/odoo/odoo/addons10/l10n_it_fatturapa/bindings/fatturapa_v_1_2.py", line 23, in <module>
    raise pyxb.PyXBVersionError(_PyXBVersion)
PyXBVersionError: 1.2.6

except ImportError:
_logger.debug('Cannot `import pyxb`.') # Avoid init error if not installed
from . import fatturapa_v_1_2
except Exception as e: # ImportError or pyxb.PyXBVersionError
_logger.warning('%s: %s' % (e.__class__.__name__, e))
Loading