Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][l10n_br_account] fwp 3272 #3440

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions l10n_br_account/models/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 @@ -185,6 +188,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"):
Expand All @@ -197,3 +208,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)
6 changes: 6 additions & 0 deletions l10n_br_account/tests/test_account_move_lc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1726,3 +1726,9 @@ def test_change_states(self):
document_id.action_document_back2draft()
self.assertEqual(self.move_out_venda.state, "draft")
self.assertEqual(document_id.state, "em_digitacao")

def test_document_deny(self):
document_id = self.move_out_venda.fiscal_document_id
self.assertEqual(self.move_out_venda.state, "draft")
document_id.exec_after_SITUACAO_EDOC_DENEGADA("em_digitacao", "denegada")
self.assertEqual(self.move_out_venda.state, "cancel")
Loading