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

[10.0] pyxb 1.2.6 #998

merged 1 commit into from
Apr 8, 2019

Conversation

sherpya
Copy link
Member

@sherpya sherpya commented Feb 12, 2019

Ho fatto il porting a 1.2.6 + la fix del mindate

approccio un po' diverso, ho fatto meno modifiche possibili al file generato

  • la parte iniziale per gli import
  • il fix del mindate

il resto è stato fatto sull'xsd, ed ho aggiunto il diff

potete controllare se le cose cambiate siano quelle del diff e basta?

  • stringhe da 0 a n invece che da 1 a n
  • aggiunta TD20 - Autofattura (da v1.3)

il file con le diff è l10n-italy/l10n_it_fatturapa/bindings/FatturaPA_versione_1.2.xsd.diff

bindings generati con pyxbgen da file locale patchato, poi ho fatto questo per rimuovere i riferimenti al file locale:

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

@@ -0,0 +1,89 @@
--- Schema_del_file_xml_FatturaPA_versione_1.2.xsd.orig 2019-02-12 02:28:11.342236082 +0100
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

in realtà con la 1.2 ma si aggiorna agevole

Copy link
Member Author

Choose a reason for hiding this comment

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

ma è sbagliato l'xsd! c'è <xsd:import invece di <xs:import

Copy link
Member

Choose a reason for hiding this comment

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

Perchè xsd:import sarebbe sbagliato?

Copy link
Member Author

@sherpya sherpya Feb 12, 2019

Choose a reason for hiding this comment

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

non c'è nessuna definizione di namespace xsd sopra (e pyxbgen mi rimbalza)

@sherpya
Copy link
Member Author

sherpya commented Feb 12, 2019

ma nell'__init__.py che fa questa roba?

# 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
except ImportError:
    _logger.debug('Cannot `import pyxb`.')  # Avoid init error if not installed

v_1_1?

@sherpya
Copy link
Member Author

sherpya commented Feb 13, 2019

aggiunto un README.md con la procedura per l'aggiornamento dei bindings

@sherpya
Copy link
Member Author

sherpya commented Feb 13, 2019

faillisce il doppio zero :( devo trovare un modo per farlo andare senza mettere le mani dentro i .py

@sherpya
Copy link
Member Author

sherpya commented Feb 13, 2019

per specifica i decimal non possono avere trailing zero:
https://www.w3.org/TR/xmlschema-2/#decimal

quindi tocca considerarle stringhe

@eLBati
Copy link
Member

eLBati commented Feb 13, 2019

v_1_1?

Probabilmente roba vecchia

@sherpya
Copy link
Member Author

sherpya commented Feb 13, 2019

patchato l'xsd anche per i decimal

@eLBati
Copy link
Member

eLBati commented Feb 14, 2019

@sherpya cosa succede alle installazioni dove c'è pyxb 1.2.5, nel momento in cui aggiornano questo modulo?

@eLBati
Copy link
Member

eLBati commented Feb 14, 2019

Direi di prenderci un pochino di tempo per valutare il da farsi con pyxb, considerato questo #879 (comment)

@sherpya
Copy link
Member Author

sherpya commented Feb 14, 2019

2019-02-14 11:21:17,592 18709 CRITICAL test10 odoo.service.server: Failed to initialize database `test10`.
Traceback (most recent call last):
  File "/home/sherpya/workspace/odoo/odoo/odoo/odoo/service/server.py", line 911, in preload_registries
    registry = Registry.new(dbname, update_module=update_module)
  File "/home/sherpya/workspace/odoo/odoo/odoo/odoo/modules/registry.py", line 83, in new
    odoo.modules.load_modules(registry._db, force_demo, status, update_module)
  File "/home/sherpya/workspace/odoo/odoo/odoo/odoo/modules/loading.py", line 373, in load_modules
    force, status, report, loaded_modules, update_module, models_to_check)
  File "/home/sherpya/workspace/odoo/odoo/odoo/odoo/modules/loading.py", line 270, in load_marked_modules
    perform_checks=perform_checks, models_to_check=models_to_check
  File "/home/sherpya/workspace/odoo/odoo/odoo/odoo/modules/loading.py", line 138, in load_module_graph
    load_openerp_module(package.name)
  File "/home/sherpya/workspace/odoo/odoo/odoo/odoo/modules/module.py", line 367, in load_openerp_module
    __import__('odoo.addons.' + module_name)
  File "/home/sherpya/workspace/odoo/odoo/odoo/odoo/modules/module.py", line 81, in load_module
    execfile(modfile, new_mod.__dict__)
  File "/home/sherpya/workspace/odoo/odoo/l10n-italy/l10n_it_fatturapa_in/__init__.py", line 5, in <module>
    from . import wizard
  File "/home/sherpya/workspace/odoo/odoo/l10n-italy/l10n_it_fatturapa_in/wizard/__init__.py", line 3, in <module>
    from . import wizard_import_fatturapa
  File "/home/sherpya/workspace/odoo/odoo/l10n-italy/l10n_it_fatturapa_in/wizard/wizard_import_fatturapa.py", line 9, in <module>
    from odoo.addons.l10n_it_fatturapa.bindings import fatturapa_v_1_2
  File "/home/sherpya/workspace/odoo/odoo/l10n-italy/l10n_it_fatturapa/bindings/fatturapa_v_1_2.py", line 10, in <module>
    from . import _ds as _ImportedBinding__ds
  File "/home/sherpya/workspace/odoo/odoo/l10n-italy/l10n_it_fatturapa/bindings/_ds.py", line 32, in <module>
    raise pyxb.PyXBVersionError(_PyXBVersion)
PyXBVersionError: 1.2.6

sembra ok, cmq prima di mergiare vorrei fare ed avere qualche feedback "su strada"

@sherpya
Copy link
Member Author

sherpya commented Feb 14, 2019

o forse deve dare solo il warn e non morire? cmq si può sistemare

@eLBati
Copy link
Member

eLBati commented Feb 19, 2019

o forse deve dare solo il warn e non morire?

Penso che così vada bene: così eventualmente all'avvio del server ci si accorge della mancanza

@eLBati
Copy link
Member

eLBati commented Feb 19, 2019

@sherpya questa è WIP nel senso che intendi lavorarci ancora?

@sherpya
Copy link
Member Author

sherpya commented Feb 19, 2019

@sherpya questa è WIP nel senso che intendi lavorarci ancora?

in realtà wip si può levare ma volevo provarla su dati reali prima di mergiarla

@eLBati eLBati changed the title [10.0] [WIP] pyxb 1.2.6 [10.0] pyxb 1.2.6 Feb 19, 2019
@@ -6,7 +6,7 @@

{
'name': 'Italian Localization - Fattura elettronica - Base',
'version': '10.0.2.3.6',
'version': '10.0.2.3.7',
Copy link
Member

Choose a reason for hiding this comment

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

Data l'entità della modifica, farei almeno 2.4.0

Copy link
Member

Choose a reason for hiding this comment

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

@sherpya c'è anche da risolvere i conflitti con un rebase

Copy link
Member Author

@sherpya sherpya Feb 22, 2019

Choose a reason for hiding this comment

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

fatturapa_v_1_1

l'ho potato questo e messo un __init__.py vuoto

Copy link
Member Author

Choose a reason for hiding this comment

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

che poi in effetti se si mette lì il check forse si può evitare nel due autogenerati

@eLBati
Copy link
Member

eLBati commented Feb 19, 2019

La testo su un cliente

@eLBati
Copy link
Member

eLBati commented Feb 27, 2019

Per ora nessun problema rilevato

@eLBati
Copy link
Member

eLBati commented Mar 4, 2019

@sherpya dovresti fare rebase per risolvere i conflitti. Grazie

@eLBati
Copy link
Member

eLBati commented Mar 6, 2019

Per me si può procedere.

@OCA/local-italy-developers ?

Copy link
Member

@SimoRubi SimoRubi left a comment

Choose a reason for hiding this comment

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

Grazie mille @sherpya!
Solo qualche commento, approfondirò review quando troverò il xsd di cosa accetta/non accetta SDI


## 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ì

## Incongruenze rispetto alle specifiche del file xsd

* StringNNType: nelle specifiche da 1 a NN, lo SDI accetta da 0 a N
* 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


* rinominare `binding.py` in `fatturapa_v_1_2.py`
* riportare il prologo dai file `fatturapa_v_1_2.py` e `_ds.py` precedenti,
in particolare da `# flake8: noqa` a fine import, software come `meld` o similari
Copy link
Member

Choose a reason for hiding this comment

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

Il mio prologo di _ds.py è

# ./_ds.py
# -*- coding: utf-8 -*-
# PyXB bindings for NM:f1c343a882e7a65fb879f4ee813309f8231f28c8
# Generated 2019-03-13 11:37:03.086990 by PyXB version 1.2.6 using Python 2.7.15.candidate.1
# Namespace http://www.w3.org/2000/09/xmldsig# [xmlns:ds]

from __future__ import unicode_literals
import pyxb
import pyxb.binding
import pyxb.binding.saxer
import io
import pyxb.utils.utility
import pyxb.utils.domutils
import sys
import pyxb.utils.six as _six
# Unique identifier for bindings created at the same time
_GenerationUID = pyxb.utils.utility.UniqueIdentifier('urn:uuid:e74caf7a-457b-11e9-82e4-144f8a914443')

# Version of PyXB used to generate the bindings
_PyXBVersion = '1.2.6'
# Generated bindings are not compatible across PyXB versions
if pyxb.__version__ != _PyXBVersion:
    raise pyxb.PyXBVersionError(_PyXBVersion)

# A holder for module-level binding classes so we can access them from
# inside class definitions where property names may conflict.
_module_typeBindings = pyxb.utils.utility.Object()

# Import bindings for namespaces imported into schema
import pyxb.binding.datatypes

# NOTE: All namespace declarations are reserved within the binding
Namespace = pyxb.namespace.NamespaceForURI('http://www.w3.org/2000/09/xmldsig#', create_if_missing=True)
Namespace.configureCategories(['typeBinding', 'elementBinding'])

e non ho riferimenti a flake8

Copy link
Member Author

Choose a reason for hiding this comment

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

nell'altro file (fatturapa_v_1_2.py ) c'è in ogni caso per farlo passare a flake8 erano state fatte delle modifiche alla formattazione,
dubito che possa esserci utile stare dietro alla formattazione di un file generato

Copy link
Member Author

Choose a reason for hiding this comment

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

probabilmente si potrebbero anche fare meno modifiche ai file generati e fare un import in __init__.py come già c'era (ma scassato)

Copy link
Member

Choose a reason for hiding this comment

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

@SimoRubi #998 (comment) non capisco a cosa ti stai riferendo

Copy link
Member

Choose a reason for hiding this comment

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

Avevo letto male, pensavo che nei file generati ci dovesse essere un # flake8 invece è nei file precedenti

Copy link
Member

Choose a reason for hiding this comment

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

Anche in quelli nuovi:

E concordo su

dubito che possa esserci utile stare dietro alla formattazione di un file generato

return result.replace(tzinfo=None)
```

La patch dell'xsd modifica il range di caratteri delle stringhe portandolo da 1-N a 0-N, inoltre aggiungere il tipo documento TD20 (Autofattura).
Copy link
Member

Choose a reason for hiding this comment

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

Fa anche il cambio di alcuni campi da decimal a string

Copy link
Member Author

Choose a reason for hiding this comment

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

verifico se fractionMinDigits ci piace altrimenti lo aggiungo

Copy link
Contributor

@robyf70 robyf70 Mar 14, 2019

Choose a reason for hiding this comment

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

Ho notato che nel caso in cui si spediscano fatture con destinatario estero, spesso capita di avere caratteri non Latin1 o con accenti nei nomi delle città, vie etc etc. Inoltre ci sono casi come città L'Aquila non viene accettata, ma se la cambio in L' Aquila allora passa la validazione.

Copy link
Member Author

Choose a reason for hiding this comment

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

@robyf70 non è che l'apostrofo originale è questo carattere qui? https://www.fileformat.info/info/unicode/char/2019/index.htm non è latin1 o extended latin1

se il nome del destinatario contiene un carattere non latin1 o extended latin1 ti attacchi, ringrazia chi ha fatto la specifica 😃

Copy link
Member Author

Choose a reason for hiding this comment

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

@SimoRubi purtroppo nulla, pyxb non supporta fractionMinDigits quindi ci tocca usare stringa, ho aggiornato il readme e minimizzato le modifiche ai file generati mettendo il controllo in __init__

@eLBati
Copy link
Member

eLBati commented Mar 18, 2019

@sherpya sai come mai lint è diventato rosso? (mi pare fosse verde qualche giorno fa)

Copy link
Member

@SimoRubi SimoRubi left a comment

Choose a reason for hiding this comment

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

Per me ok quando travis e runbot saranno ✔️

@sherpya
Copy link
Member Author

sherpya commented Mar 18, 2019

@sherpya sai come mai lint è diventato rosso? (mi pare fosse verde qualche giorno fa)

Non è roba mia, ma:

  • withholding_tax.py:129 andrebbero usati i binding invece di string formatting
  • l10n_it_fatturapa_in/tests/data/IT02780790107_11004.xml:1 va ignorato perché è sbagliato volontariamente per far fallire l'import (prima lo ignorava)
  • l10n_it_fatturapa_pec/models/fetchmail.py c'era da prima ed era ignorato

Qualcuno ha cambiato la configurazione del pylint?

@eLBati
Copy link
Member

eLBati commented Mar 18, 2019

@moylop260 hi, do you know why lint is red complaining about lines not changed by this PR?

@moylop260
Copy link

“Oops, we couldn't find that build!“

Could you rebase it in order to make a new build, please?

@sherpya
Copy link
Member Author

sherpya commented Mar 18, 2019

“Oops, we couldn't find that build!“

Could you rebase it in order to make a new build, please?

@moylop260 it's already rebased, should I close this one and make new PR instead?

@eLBati
Copy link
Member

eLBati commented Mar 18, 2019

@sherpya I think you can just rebase or git commit --amend to force a new travis build

@sherpya
Copy link
Member Author

sherpya commented Mar 19, 2019

@moylop260 done

@eLBati
Copy link
Member

eLBati commented Mar 21, 2019

@moylop260 https://travis-ci.org/OCA/l10n-italy/jobs/507972110 still red for files not changed by this PR

@eLBati
Copy link
Member

eLBati commented Apr 1, 2019

@OCA/local-italy-developers direi di ignorare gli errori LINT e procedere.

Attenzione che dopo questa PR sarà necessario aggiornare pyxb alla versione 1.2.6


_logger = logging.getLogger(__name__)

try:
Copy link
Contributor

Choose a reason for hiding this comment

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

il travis si lamenta della rimozione di questo try, per quale motivo era stato tolto? scusate se non l'ho visto magari nella conversazione, non lo trovo

Copy link
Member

Choose a reason for hiding this comment

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

il travis si lamenta della rimozione di questo try

In quale riga di https://travis-ci.org/OCA/l10n-italy/jobs/507972110 vedi questo?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

scusa, L642

Copy link
Member Author

Choose a reason for hiding this comment

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

ho spostato il check e il log in __init__.py

Copy link
Member

Choose a reason for hiding this comment

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

@sergiocorato ah ok, sì, però come anche tutti gli altri import di _ds.py. Quindi direi che ce ne possiamo disinteressare

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

added xsd patch and README.md to generate new bindings

includes workaround for pyxb bug in mindate check

pyxb is unable to check order of dates if only one has timezone
checking if the date > 1970-01-01
we remove tzinfo from parsed date only types as a workaround
@sergiocorato sergiocorato mentioned this pull request Apr 3, 2019
4 tasks
@eLBati
Copy link
Member

eLBati commented Apr 8, 2019

Faccio merge visto che gli errori travis non sono collegati

@eLBati eLBati merged commit 354704d into OCA:10.0 Apr 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants