diff --git a/l10n_br_account/models/document.py b/l10n_br_account/models/document.py index 9b5a376160cf..cb9db39be9b3 100644 --- a/l10n_br_account/models/document.py +++ b/l10n_br_account/models/document.py @@ -9,7 +9,10 @@ from odoo.exceptions import UserError from odoo.addons.l10n_br_fiscal.constants.fiscal import ( + DOCUMENT_ISSUER_COMPANY, DOCUMENT_ISSUER_PARTNER, + MODELO_FISCAL_CTE, + MODELO_FISCAL_NFE, SITUACAO_EDOC_EM_DIGITACAO, ) @@ -169,6 +172,14 @@ def _document_correction(self, justificative): self.message_post(body=msg) return result + def _document_deny(self): + msg = _( + "Canceled due to the denial of document %(document_number)s", + document_number=self.document_number, + ) + self.cancel_move_ids() + self.message_post(body=msg) + def action_document_confirm(self): result = super().action_document_confirm() if not self._context.get("skip_post"): @@ -181,3 +192,13 @@ def action_document_back2draft(self): if self.move_ids: self.move_ids.button_draft() return result + + def exec_after_SITUACAO_EDOC_DENEGADA(self, old_state, new_state): + self.ensure_one() + models_cancel_on_deny = [MODELO_FISCAL_NFE, MODELO_FISCAL_CTE] + if ( + self.document_type_id.code in models_cancel_on_deny + and self.issuer == DOCUMENT_ISSUER_COMPANY + ): + self._document_deny() + return super().exec_after_SITUACAO_EDOC_DENEGADA(old_state, new_state)