akretion / xsdata-odoo

Odoo abstract model generator from xsd schemas using xsdata
MIT License
9 stars 8 forks source link

naive <xs:choice> support #6

Closed rvalyi closed 1 year ago

rvalyi commented 1 year ago

should be enough to be on par with the old generateds-odoo where we had 'choice' attributes (native from generateDS itself) in fields like https://github.com/OCA/l10n-brazil/blob/14.0/l10n_br_nfe_spec/models/v4_00/leiauteNFe.py because of the xs:choice tags in the schema https://github.com/akretion/nfelib/blob/master-xsdata/nfelib/schemas/nfe/v4_0/leiauteNFe_v4.00.xsd

we don't try yet to generate fields such as

    nfe40_choice16 = fields.Selection([
        ('nfe40_vBC', 'vBC'),
        ('nfe40_pCOFINS', 'pCOFINS'),
        ('nfe40_qBCProd', 'qBCProd'),
        ('nfe40_vAliqProd', 'vAliqProd')],
        "vBC/pCOFINS/qBCProd/vAliqProd")

because the choice numbering was a bit arbitrary, depending on generateDS internals and would not match. Instead we assume to add these fields manually in overrides where they matter and according to the legacy numbering. We also assume we have no more than one choice per complexType which is the case with the Brazilian Electronic Invoice and we set the name of the complexType for the choice instead of some arbitrary number.

cc @renatonlima @marcelsavegnago @antoniospneto @felipemotter

rvalyi commented 1 year ago

this should save us from having to do this kind of hack when moving to xsdata https://github.com/OCA/l10n-brazil/pull/1979/commits/02b130bd6cd6e425304ab22489f17d821f2e5e0f

codecov[bot] commented 1 year ago

Codecov Report

Merging #6 (d0e0f34) into master (93e7fc6) will increase coverage by 0.54%. The diff coverage is 97.61%.

@@            Coverage Diff             @@
##           master       #6      +/-   ##
==========================================
+ Coverage   83.29%   83.84%   +0.54%     
==========================================
  Files           6        6              
  Lines         467      489      +22     
  Branches      124      132       +8     
==========================================
+ Hits          389      410      +21     
  Misses         49       49              
- Partials       29       30       +1     
Impacted Files Coverage Δ
xsdata_odoo/generator.py 86.95% <97.36%> (+3.95%) :arrow_up:
xsdata_odoo/filters.py 84.72% <100.00%> (-1.06%) :arrow_down:

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

rvalyi commented 1 year ago

This choice/xsd_choice_required branch is what is used to successfuly implement the Brazilian Electronic Invoicing using xsdata instead of generateDS mixins here https://github.com/OCA/l10n-brazil/pull/1979 so merging

cc @renatonlima @marcelsavegnago @felipemotter