Skip to content

Conversation

@felipemotter
Copy link
Contributor

Resumo

Corrige um bug onde confirmar uma fatura de entrada (issuer=partner) pela view do documento fiscal falhava com o erro:

Não é possível realizar esta operação, esta transição não é permitida:
De: autorizada
Para: autorizada

Como reproduzir

  1. Criar uma fatura de entrada (in_invoice) com um tipo de documento fiscal (ex: NF-e)
  2. Certificar que o documento fiscal tem issuer=partner (padrão para faturas de entrada)
  3. Navegar até a view do documento fiscal vinculado (l10n_br_fiscal.document)
  4. Clicar no botão "Confirmar"
  5. Antes do fix: Erro "transição não permitida: autorizada -> autorizada"
  6. Após o fix: Documento é autorizado e fatura é postada corretamente

Causa raiz

Ao confirmar pela view do documento fiscal:

  1. action_document_confirm() é chamado → documento vai para autorizada (quando issuer=partner)
  2. Isso dispara move_ids._post() para postar a fatura vinculada
  3. _post() chama action_document_confirm() novamente no documento fiscal
  4. A segunda chamada tenta fazer transição de autorizada para autorizada → erro

Solução

Alterado o filtro em _document_confirm_to_send() para processar apenas documentos no estado em_digitacao, tornando o método idempotente e seguro para ser chamado múltiplas vezes.

Obs: Confirmar pela view da fatura (account.move) funciona corretamente porque a flag de contexto skip_post previne a chamada recursiva.

…onfirm

When confirming an incoming invoice (issuer=partner) from the fiscal
document view, action_document_confirm() would be called twice:

1. First call from the document view confirms the document
2. This triggers move_ids._post() which calls action_document_confirm() again

The second call would fail with "transition not allowed: autorizada ->
autorizada" because the document was already authorized.

The fix changes the filter in _document_confirm_to_send() to only process
documents in 'em_digitacao' state, making the method idempotent and safe
to call multiple times.
Add regression test to ensure that calling action_document_confirm()
multiple times on a document with issuer='partner' does not raise
a transition error.
@OCA-git-bot
Copy link
Contributor

Hi @rvalyi, @renatonlima, @mileo,
some modules you are maintaining are being modified, check this out!

@rvalyi
Copy link
Member

rvalyi commented Jan 26, 2026

Ola @felipemotter parece OK essa mudança, mas seria interessante olhar com calma o que eu fiz aqui tb #4365 pois hoje o l10n_br_fiscal_edi ainda é um código legacy bem porco e quanto mais cedo e gente conseguir limpar menos a gente vai soffrer la na frente...

Add regression test to ensure that confirming an incoming invoice
(issuer=partner) from the fiscal document view works correctly
without causing a recursive loop error.
@felipemotter felipemotter force-pushed the 16.0-fix-document-confirm-loop branch from bbdfb34 to b4de6d1 Compare January 27, 2026 12:38
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