Skip to content

fix(nfe client): signed events and inutilizacao never reached the payload - #167

Merged
rvalyi merged 2 commits into
akretion:masterfrom
antoniospneto:master-fix-event-placeholders
Oct 7, 2026
Merged

rvalyi merged 2 commits into
akretion:masterfrom
antoniospneto:master-fix-event-placeholders

Conversation

@antoniospneto

Copy link
Copy Markdown
Contributor

Os placeholders vazios viram tags auto-fechadas (<evento versao="1.00"/>, <inutNFe versao="4.00"/>). As regex nunca casavam, e o prepare_payload mandava o nfeDadosMsg vazio sem avisar, então cancelamento, CC-e e inutilização pelo NfeClient não funcionavam. A CC-e ainda era montada com o tipo Tevento e saía como <TEvento xmlns="">.

  • enviar_lote_evento: monta o envEvento (idLote + evento placeholder) com o elemento global e injeta os eventos assinados, como o cliente de MD-e;
  • envia_inutilizacao: a regex aceita o placeholder auto-fechado;
  • carta_correcao: usa o elemento global evento.

Os testes mockados agora conferem que o conteúdo assinado está no payload. Testado em homologação na SVRS (pela OCA/l10n-brazil#4147): CC-e e cancelamento registrados (cStat 135), inutilização homologada (cStat 102).

🤖 Generated with Claude Code

…load

The empty placeholders serialize as self-closing tags (<evento
versao="1.00"/>, <inutNFe versao="4.00"/>), so the placeholder
expressions never matched and prepare_payload silently sent an empty
nfeDadosMsg: cancelamento, CC-e and inutilizacao could not work.

- enviar_lote_evento: build the envEvento batch (idLote + placeholder
  evento) with the global element class and inject the joined signed
  events, as the MD-e client does.
- envia_inutilizacao: also match the self-closing placeholder.
- carta_correcao: build the evento global element instead of the
  Tevento type, which serialized as <TEvento xmlns=""> with ns1
  prefixed children.

The mocked tests now assert the signed content is in the outgoing
payload. Checked against the SVRS homologation environment: CC-e and
cancelamento registered (cStat 135), inutilizacao homologated
(cStat 102).
@antoniospneto

Copy link
Copy Markdown
Contributor Author

A falha do Python 3.13 é só o test_fingerprint: o portal do CT-e publicou conteúdo novo depois do release 3.0.0 (o hash de cte mudou de 7da9ead5… pra 01cff097…). Nada a ver com este PR; os testes passam em todas as versões.

@rvalyi

rvalyi commented Oct 6, 2026

Copy link
Copy Markdown
Member

Pode ajustar o fingerprint no PR depois eu vejo de atualizar o esquema. Tem falsos positivos nesses sistema de fingerprint,mas pelo menos deteta as mudanças TB...

@antoniospneto

Copy link
Copy Markdown
Contributor Author

@rvalyi feito!

@rvalyi rvalyi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

valeu demais @antoniospneto

@rvalyi
rvalyi merged commit 08eb13a into akretion:master Oct 7, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants