Skip to content

feat(nfse): add the 1.01 layout bindings (IBSCBS groups) - #169

Draft
antoniospneto wants to merge 4 commits into
akretion:masterfrom
antoniospneto:master-nfse-v1_01
Draft

antoniospneto wants to merge 4 commits into
akretion:masterfrom
antoniospneto:master-nfse-v1_01

Conversation

@antoniospneto

Copy link
Copy Markdown
Contributor

O pacote oficial NFSe-ESQUEMAS_XSD-v1.01-20260209 traz dois leiautes, e só o 1.01 tem os grupos IBSCBS da reforma (NT SE/CGNFS-e 004). A nota gerada pela Sefin já sai em 1.01, mesmo a partir de uma DPS 1.00.

  • Pasta própria (v1_01), em vez de substituir a v1_0: o 1.01 não lê tudo do 1.00 (o explRod e outros grupos sumiram) e os dois leiautes são aceitos ao mesmo tempo. A v1_0 não foi alterada. Se preferir outro nome de pasta, ajusto.
  • Patch no XSD oficial: o padrão do TSSerieDPS no 1.01 é ^0{0,4}\d{1,5}$. Em regex de XSD, ^ e $ são literais, então o lxml rejeita qualquer série.
  • CommonMixin.from_xml: com dois pacotes no mesmo namespace, o xsdata devolvia a classe importada por último, e um Dps 1.00 virava 1.01. Agora vale a classe do pacote de quem chamou. Passar cls direto ao parser mudaria o retorno de TnfeProc.from_xml, Tcte.from_xml e outros, que passariam a devolver o tipo em vez do elemento. O _get_schema_path também passa a usar o XSD da versão.

Motivação: a OCA/l10n-brazil#5328 precisou escrever um parser XPath porque o v1_0 não tem IBSCBS.

🤖 Generated with Claude Code

Generate nfelib.nfse.bindings.v1_01 from the 1.01 layout of the national
NFS-e package "NFSe-ESQUEMAS_XSD-v1.01-20260209" (directory Schemas/1.01),
the layout with the IBSCBS groups of the tax reform (NT SE/CGNFS-e 004).

The 1.01 layout does not supersede v1_0 as the 2 digits rule would ask:

- both layouts are accepted at the same time (the IBSCBS groups are optional
  since NT 004 v2.00), and the Sefin already returns NFS-e 1.01 wrapping a
  DPS 1.00;
- 1.01 cannot read every 1.00 document: explRod (toll) and other groups are
  gone.

So it gets its own folder next to v1_0, which is left untouched. The schemas
are copied as published. A synthetic NFS-e sample carries the IBSCBS groups
of the note and of the DPS, with a round-trip test.

The existing 1.00 tests now give XmlParser the target class: with two
packages for the same namespace, the root class lookup returns the class
imported last.

Source: https://www.gov.br/nfse/pt-br/biblioteca/documentacao-tecnica/documentacao-atual/nfse-esquemas_xsd-v1-01-20260209.zip
The published tiposSimples_v1.01.xsd declares the DPS series as
"^0{0,4}\d{1,5}$". XML Schema regular expressions are always anchored and
treat ^ and $ as plain characters, so libxml2 (lxml) rejects every series,
"00007" included, and no DPS or NFS-e 1.01 passes the schema validation.
The 1.00 layout has no such anchors.

Drop the ^ and $ from the pattern and regenerate the bindings (only the
pattern metadata changes). The sample now validates against NFSe_v1.01.xsd.
The NFS-e 1.00 and 1.01 bindings share the namespace and the root element
names. CommonMixin.from_xml let xsdata detect the root class, and xsdata
returns the class imported last: once v1_01 is imported, a 1.00 Dps.from_path
returns a 1.01 object.

Passing cls to the parser is not an option: from_xml is also called on
complexType classes (TnfeProc, Tnfe, Tcte...), and the parsed object would
then be the type instead of the element class. So when several classes match
the root element, keep the one of the package of cls; otherwise xsdata
detects the root class as before.

_get_schema_path also validated any NFS-e DPS against the 1.00 schema; a
1.01 binding now gets DPS_v1.01.xsd.

@marcelsavegnago marcelsavegnago left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

@marcelsavegnago

Copy link
Copy Markdown

ping @CristianoMafraJunior

@antoniospneto

Copy link
Copy Markdown
Contributor Author

Pessoal eu deixei em rascunho pq fiz com a ajuda de IA eu não pude testar, por hora não pretendo fazer isso, mas fiquem a vontade!

@rvalyi

rvalyi commented Oct 9, 2026

Copy link
Copy Markdown
Member

Ah bem que meu Deepseek tinha me avisado disso. Mas li rapido demais e pensei que era apenas a mais nova versao que ficava no lugar da antiga...

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants