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

[14.0][FIX] l10n_br_account: validate move on document #3093

Merged
merged 5 commits into from
Jun 13, 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
4 changes: 2 additions & 2 deletions l10n_br_account/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ def button_draft(self):
)
move.fiscal_document_ids.filtered(
lambda d: d.state_edoc != SITUACAO_EDOC_EM_DIGITACAO
).action_document_back2draft()
).document_back2draft()
return super().button_draft()

def action_document_send(self):
Expand Down Expand Up @@ -599,7 +599,7 @@ def action_document_back2draft(self):
def _post(self, soft=True):
self.mapped("fiscal_document_id").filtered(
lambda d: d.document_type_id
).action_document_confirm()
)._document_confirm_to_send()
return super()._post(soft=soft)

def view_xml(self):
Expand Down
12 changes: 12 additions & 0 deletions l10n_br_account/models/fiscal_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,15 @@ def _document_correction(self, justificative):
msg = "Carta de correção: {}".format(justificative)
self.message_post(body=msg)
return result

def action_document_confirm(self):
result = super().action_document_confirm()
move_ids = self.move_ids.filtered(lambda move: move.state == "draft")
move_ids._post()
return result

def action_document_back2draft(self):
result = super().action_document_back2draft()
if self.move_ids:
self.move_ids.button_draft()
return result
2 changes: 2 additions & 0 deletions l10n_br_account/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def setUpClass(cls, chart_template_ref=None):
cls.env.user.groups_id |= cls.env.ref("l10n_br_fiscal.group_manager")
cls.product_a.write(
{
"default_code": "prod_a",
"standard_price": 1000.0,
"ncm_id": cls.env.ref("l10n_br_fiscal.ncm_94033000").id,
"fiscal_genre_id": cls.env.ref("l10n_br_fiscal.product_genre_94").id,
Expand Down Expand Up @@ -64,6 +65,7 @@ def setUpClass(cls, chart_template_ref=None):

cls.product_b.write(
{
"default_code": "prod_b",
"lst_price": 1000.0,
"ncm_id": cls.env.ref("l10n_br_fiscal.ncm_94013090").id,
"fiscal_genre_id": cls.env.ref("l10n_br_fiscal.product_genre_94").id,
Expand Down
37 changes: 29 additions & 8 deletions l10n_br_account/tests/test_account_move_lc.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,10 @@ def setUpClass(cls):
def setup_company_data(cls, company_name, chart_template=None, **kwargs):
if company_name == "company_1_data":
company_name = "empresa 1 Lucro Presumido"
cnpj = "62.128.834/0001-34"
else:
company_name = "empresa 2 Lucro Presumido"
cnpj = "87.396.251/0001-15"
chart_template = cls.env.ref("l10n_br_coa_generic.l10n_br_coa_generic_template")
res = super().setup_company_data(
company_name,
Expand All @@ -224,6 +226,7 @@ def setup_company_data(cls, company_name, chart_template=None, **kwargs):
**kwargs
)
res["company"].partner_id.state_id = cls.env.ref("base.state_br_sp").id
res["company"].partner_id.cnpj_cpf = cnpj
chart_template.load_fiscal_taxes()
return res

Expand All @@ -235,7 +238,7 @@ def test_venda_fiscal_lines(self):

def test_venda(self):
product_line_vals_1 = {
"name": self.product_a.name,
"name": self.product_a.display_name,
"product_id": self.product_a.id,
"account_id": self.product_a.property_account_income_id.id,
"partner_id": self.partner_a.id,
Expand Down Expand Up @@ -410,7 +413,7 @@ def test_venda(self):

def test_venda_with_icms_reduction(self):
product_line_vals_1 = {
"name": self.product_a.name,
"name": self.product_a.display_name,
"product_id": self.product_a.id,
"account_id": self.product_a.property_account_income_id.id,
"partner_id": self.partner_a.id,
Expand Down Expand Up @@ -598,7 +601,7 @@ def test_venda_with_icms_reduction_with_relief(self):
self.move_out_venda_with_icms_reduction._check_balanced()

product_line_vals_1 = {
"name": self.product_a.name,
"name": self.product_a.display_name,
"product_id": self.product_a.id,
"account_id": self.product_a.property_account_income_id.id,
"partner_id": self.partner_a.id,
Expand Down Expand Up @@ -773,7 +776,7 @@ def test_venda_with_icms_reduction_with_relief(self):

def test_simples_remessa(self):
product_line_vals_1 = {
"name": self.product_a.name,
"name": self.product_a.display_name,
"product_id": self.product_a.id,
"account_id": self.product_a.property_account_income_id.id,
"partner_id": self.partner_a.id,
Expand Down Expand Up @@ -951,7 +954,7 @@ def test_compra_para_revenda(self):
Test move with deductible taxes
"""
product_line_vals_1 = {
"name": self.product_a.name,
"name": self.product_a.display_name,
"product_id": self.product_a.id,
"account_id": self.product_a.property_account_expense_id.id,
"partner_id": self.partner_a.id,
Expand Down Expand Up @@ -1229,7 +1232,7 @@ def test_compra_para_revenda(self):
# Tax Withholding Tests
def test_venda_tax_withholding(self):
product_line_vals_1 = {
"name": self.product_a.name,
"name": self.product_a.display_name,
"product_id": self.product_a.id,
"account_id": self.product_a.property_account_income_id.id,
"partner_id": self.partner_a.id,
Expand Down Expand Up @@ -1400,7 +1403,7 @@ def test_venda_tax_withholding(self):

def test_simples_remessa_tax_withholding(self):
product_line_vals_1 = {
"name": self.product_a.name,
"name": self.product_a.display_name,
"product_id": self.product_a.id,
"account_id": self.product_a.property_account_income_id.id,
"partner_id": self.partner_a.id,
Expand Down Expand Up @@ -1574,7 +1577,7 @@ def test_compra_para_revenda_tax_withholding(self):
Test move with deductible taxes and tax withholding
"""
product_line_vals_1 = {
"name": self.product_a.name,
"name": self.product_a.display_name,
"product_id": self.product_a.id,
"account_id": self.product_a.property_account_expense_id.id,
"partner_id": self.partner_a.id,
Expand Down Expand Up @@ -1863,3 +1866,21 @@ def test_composite_move(self):
)
self.assertEqual(len(self.move_in_compra_para_revenda.line_ids), 11)
self.assertEqual(self.move_in_compra_para_revenda.amount_total, 2100)

def test_change_states(self):
# first we make a few assertions about an existing vendor bill:
document_id = self.move_out_venda.fiscal_document_id
self.assertEqual(self.move_out_venda.state, "draft")
self.assertEqual(document_id.state, "em_digitacao")
self.move_out_venda.action_post()
self.assertEqual(self.move_out_venda.state, "posted")
self.assertEqual(document_id.state, "a_enviar")
self.move_out_venda.button_draft()
self.assertEqual(self.move_out_venda.state, "draft")
self.assertEqual(document_id.state, "em_digitacao")
document_id.action_document_confirm()
self.assertEqual(self.move_out_venda.state, "posted")
self.assertEqual(document_id.state, "a_enviar")
document_id.action_document_back2draft()
self.assertEqual(self.move_out_venda.state, "draft")
self.assertEqual(document_id.state, "em_digitacao")
2 changes: 1 addition & 1 deletion l10n_br_account/tests/test_account_move_sn.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_revenda_fiscal_lines(self):

def test_revenda(self):
product_line_vals_1 = {
"name": self.product_a.name,
"name": self.product_a.display_name,
"product_id": self.product_a.id,
"account_id": self.product_a.property_account_income_id.id,
"partner_id": self.partner_a.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_compra_para_revenda(self):
Test move with deductible taxes and withholding taxes
"""
product_line_vals_1 = {
"name": self.product_a.name,
"name": self.product_a.display_name,
"product_id": self.product_a.id,
"account_id": self.product_a.property_account_expense_id.id,
"partner_id": self.partner_a.id,
Expand Down
10 changes: 8 additions & 2 deletions l10n_br_fiscal/models/document_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,14 @@ def _document_confirm(self):
else:
self._change_state(SITUACAO_EDOC_AUTORIZADA)

def action_document_confirm(self):
def _document_confirm_to_send(self):
to_confirm = self.filtered(lambda inv: inv.state_edoc != SITUACAO_EDOC_A_ENVIAR)
if to_confirm:
to_confirm._document_confirm()

def action_document_confirm(self):
self._document_confirm_to_send()

def _no_eletronic_document_send(self):
self._change_state(SITUACAO_EDOC_AUTORIZADA)

Expand All @@ -328,14 +331,17 @@ def action_document_send(self):
if to_send:
to_send._document_send()

def action_document_back2draft(self):
def document_back2draft(self):
self.xml_error_message = False
self.file_report_id = False
if self.issuer == DOCUMENT_ISSUER_COMPANY:
self._change_state(SITUACAO_EDOC_EM_DIGITACAO)
else:
self.state_edoc = SITUACAO_EDOC_EM_DIGITACAO

def action_document_back2draft(self):
self.document_back2draft()

def _document_cancel(self, justificative):
self.ensure_one()
self.cancel_reason = justificative
Expand Down
Loading