Skip to content

Commit

Permalink
[IMP] cancel invoice on fiscal document denial
Browse files Browse the repository at this point in the history
  • Loading branch information
DiegoParadeda committed Aug 16, 2024
1 parent 534f6e5 commit ca88bfa
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions l10n_br_account/models/fiscal_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down Expand Up @@ -180,3 +183,21 @@ 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]

Check warning on line 189 in l10n_br_account/models/fiscal_document.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_account/models/fiscal_document.py#L188-L189

Added lines #L188 - L189 were not covered by tests
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)

Check warning on line 195 in l10n_br_account/models/fiscal_document.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_account/models/fiscal_document.py#L194-L195

Added lines #L194 - L195 were not covered by tests

def _document_deny(self):
msg = _(

Check warning on line 198 in l10n_br_account/models/fiscal_document.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_account/models/fiscal_document.py#L198

Added line #L198 was not covered by tests
"Canceled due to the denial of document %(document_number)s",
document_number=self.document_number,
)
self.cancel_move_ids()
self.message_post(body=msg)

Check warning on line 203 in l10n_br_account/models/fiscal_document.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_account/models/fiscal_document.py#L202-L203

Added lines #L202 - L203 were not covered by tests

0 comments on commit ca88bfa

Please sign in to comment.