Repository navigation
feat(nfse): add the 1.01 layout bindings (IBSCBS groups) - #169
Draft
antoniospneto wants to merge 4 commits into
Draft
antoniospneto wants to merge 4 commits into
antoniospneto wants to merge 4 commits into
Conversation
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.
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! |
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
O pacote oficial
NFSe-ESQUEMAS_XSD-v1.01-20260209traz 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.v1_01), em vez de substituir av1_0: o 1.01 não lê tudo do 1.00 (oexplRode outros grupos sumiram) e os dois leiautes são aceitos ao mesmo tempo. Av1_0não foi alterada. Se preferir outro nome de pasta, ajusto.TSSerieDPSno 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 umDps1.00 virava 1.01. Agora vale a classe do pacote de quem chamou. Passarclsdireto ao parser mudaria o retorno deTnfeProc.from_xml,Tcte.from_xmle outros, que passariam a devolver o tipo em vez do elemento. O_get_schema_pathtambém passa a usar o XSD da versão.Motivação: a OCA/l10n-brazil#5328 precisou escrever um parser XPath porque o
v1_0não tem IBSCBS.🤖 Generated with Claude Code