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

[15.0][l10n_br_fiscal] Oca port from 14.0 to 15.0 pr 3109 #3194

Merged
merged 3 commits into from
Jul 29, 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
113 changes: 107 additions & 6 deletions l10n_br_account/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,28 +143,129 @@
}
)

cls.fo_sale_with_icms_reduction = cls.env[
"l10n_br_fiscal.operation.line"
].create(
{
"name": "Venda com ICMS 12 e Redução de 26,57",
"ind_ie_dest": "1",
"cfop_internal_id": cls.env.ref("l10n_br_fiscal.cfop_5101").id,
"cfop_external_id": cls.env.ref("l10n_br_fiscal.cfop_6101").id,
"cfop_export_id": cls.env.ref("l10n_br_fiscal.cfop_7101").id,
"state": "approved",
"product_type": "04",
"fiscal_operation_id": cls.env.ref("l10n_br_fiscal.fo_venda").id,
}
)

@classmethod
def setup_company_data(cls, company_name, chart_template=None, **kwargs):
"""
You might want to override it to force a single chart_template.
The default behavior here is to load one for the SN and another for the LC.
"""
cnpj_cpf = kwargs.get("cnpj_cpf", "")
if company_name == "company_2_data":
company_name = "empresa 2 Simples Nacional"
chart_template = cls.env.ref(
"l10n_br_coa_simple.l10n_br_coa_simple_chart_template"
)
cnpj_cpf = "30.360.463/0001-25"

Check warning on line 173 in l10n_br_account/tests/common.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_account/tests/common.py#L173

Added line #L173 was not covered by tests
elif company_name == "company_1_data":
company_name = "empresa 1 Lucro Presumido"
chart_template = cls.env.ref(
"l10n_br_coa_generic.l10n_br_coa_generic_template"
)
return super().setup_company_data(
company_name,
chart_template,
country_id=cls.env.ref("base.br").id,
currency_id=cls.env.ref("base.BRL").id,
**kwargs
cnpj_cpf = "18.751.708/0001-40"

Check warning on line 179 in l10n_br_account/tests/common.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_account/tests/common.py#L179

Added line #L179 was not covered by tests

kwargs.update(
{
"country_id": cls.env.ref("base.br").id,
"currency_id": cls.env.ref("base.BRL").id,
"is_industry": True,
"cnpj_cpf": cnpj_cpf,
"state_id": cls.env.ref("base.state_br_sp").id,
}
)
return super().setup_company_data(company_name, chart_template, **kwargs)

@classmethod
def configure_normal_company_taxes(cls):
# Tax configuration for normal company
tax_def_model = cls.env["l10n_br_fiscal.tax.definition"]
doc_serie_model = cls.env["l10n_br_fiscal.document.serie"]
cls.pis_tax_definition_empresa_lc = tax_def_model.create(
{
"company_id": cls.company_data["company"].id,
"tax_group_id": cls.env.ref("l10n_br_fiscal.tax_group_pis").id,
"is_taxed": True,
"is_debit_credit": True,
"custom_tax": True,
"tax_id": cls.env.ref("l10n_br_fiscal.tax_pis_0_65").id,
"cst_id": cls.env.ref("l10n_br_fiscal.cst_pis_01").id,
"state": "approved",
}
)

cls.cofins_tax_definition_empresa_lc = tax_def_model.create(
{
"company_id": cls.company_data["company"].id,
"tax_group_id": cls.env.ref("l10n_br_fiscal.tax_group_cofins").id,
"is_taxed": True,
"is_debit_credit": True,
"custom_tax": True,
"tax_id": cls.env.ref("l10n_br_fiscal.tax_cofins_3").id,
"cst_id": cls.env.ref("l10n_br_fiscal.cst_cofins_01").id,
"state": "approved",
}
)

cls.icms_tax_definition_empresa_lc_icms_reduction = tax_def_model.create(
{
"company_id": cls.company_data["company"].id,
"tax_group_id": cls.env.ref("l10n_br_fiscal.tax_group_icms").id,
"is_taxed": True,
"is_debit_credit": True,
"custom_tax": True,
"tax_id": cls.env.ref("l10n_br_fiscal.tax_icms_12_red_26_57").id,
"cst_id": cls.env.ref("l10n_br_fiscal.cst_icms_20").id,
"state": "approved",
"fiscal_operation_line_id": cls.fo_sale_with_icms_reduction.id,
}
)

# Tax Definition for PIS and COFINS Withholding
cls.pis_wh_tax_definition_empresa_lc = tax_def_model.create(
{
"company_id": cls.company_data["company"].id,
"tax_group_id": cls.env.ref("l10n_br_fiscal.tax_group_pis_wh").id,
"is_taxed": True,
"is_debit_credit": True,
"custom_tax": True,
"tax_id": cls.env.ref("l10n_br_fiscal.tax_pis_wh_0_65").id,
"state": "expired",
}
)

cls.cofins_wh_tax_definition_empresa_lc = tax_def_model.create(
{
"company_id": cls.company_data["company"].id,
"tax_group_id": cls.env.ref("l10n_br_fiscal.tax_group_cofins_wh").id,
"is_taxed": True,
"is_debit_credit": True,
"custom_tax": True,
"tax_id": cls.env.ref("l10n_br_fiscal.tax_cofins_wh_3").id,
"state": "expired",
}
)

cls.empresa_lc_document_55_serie_1 = doc_serie_model.create(
{
"code": "1",
"name": "Série 1",
"document_type_id": cls.env.ref("l10n_br_fiscal.document_55").id,
"active": True,
}
)

@classmethod
Expand Down
101 changes: 1 addition & 100 deletions l10n_br_account/tests/test_account_move_lc.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,106 +14,7 @@ class AccountMoveLucroPresumido(AccountMoveBRCommon):
def setUpClass(cls):
super().setUpClass()

cls.fo_sale_with_icms_reduction = cls.env[
"l10n_br_fiscal.operation.line"
].create(
{
"name": "Venda com ICMS 12 e Redução de 26,57",
"ind_ie_dest": "1",
"cfop_internal_id": cls.env.ref("l10n_br_fiscal.cfop_5101").id,
"cfop_external_id": cls.env.ref("l10n_br_fiscal.cfop_6101").id,
"cfop_export_id": cls.env.ref("l10n_br_fiscal.cfop_7101").id,
"state": "approved",
"product_type": "04",
"fiscal_operation_id": cls.env.ref("l10n_br_fiscal.fo_venda").id,
}
)

cls.pis_tax_definition_empresa_lc = cls.env[
"l10n_br_fiscal.tax.definition"
].create(
{
"company_id": cls.company_data["company"].id,
"tax_group_id": cls.env.ref("l10n_br_fiscal.tax_group_pis").id,
"is_taxed": True,
"is_debit_credit": True,
"custom_tax": True,
"tax_id": cls.env.ref("l10n_br_fiscal.tax_pis_0_65").id,
"cst_id": cls.env.ref("l10n_br_fiscal.cst_pis_01").id,
"state": "approved",
}
)

cls.cofins_tax_definition_empresa_lc = cls.env[
"l10n_br_fiscal.tax.definition"
].create(
{
"company_id": cls.company_data["company"].id,
"tax_group_id": cls.env.ref("l10n_br_fiscal.tax_group_cofins").id,
"is_taxed": True,
"is_debit_credit": True,
"custom_tax": True,
"tax_id": cls.env.ref("l10n_br_fiscal.tax_cofins_3").id,
"cst_id": cls.env.ref("l10n_br_fiscal.cst_cofins_01").id,
"state": "approved",
}
)

cls.icms_tax_definition_empresa_lc_icms_reduction = cls.env[
"l10n_br_fiscal.tax.definition"
].create(
{
"company_id": cls.company_data["company"].id,
"tax_group_id": cls.env.ref("l10n_br_fiscal.tax_group_icms").id,
"is_taxed": True,
"is_debit_credit": True,
"custom_tax": True,
"tax_id": cls.env.ref("l10n_br_fiscal.tax_icms_12_red_26_57").id,
"cst_id": cls.env.ref("l10n_br_fiscal.cst_icms_20").id,
"state": "approved",
"fiscal_operation_line_id": cls.fo_sale_with_icms_reduction.id,
}
)

# Tax Definition for PIS and COFINS Withholding
cls.pis_wh_tax_definition_empresa_lc = cls.env[
"l10n_br_fiscal.tax.definition"
].create(
{
"company_id": cls.company_data["company"].id,
"tax_group_id": cls.env.ref("l10n_br_fiscal.tax_group_pis_wh").id,
"is_taxed": True,
"is_debit_credit": True,
"custom_tax": True,
"tax_id": cls.env.ref("l10n_br_fiscal.tax_pis_wh_0_65").id,
"state": "expired",
}
)

cls.cofins_wh_tax_definition_empresa_lc = cls.env[
"l10n_br_fiscal.tax.definition"
].create(
{
"company_id": cls.company_data["company"].id,
"tax_group_id": cls.env.ref("l10n_br_fiscal.tax_group_cofins_wh").id,
"is_taxed": True,
"is_debit_credit": True,
"custom_tax": True,
"tax_id": cls.env.ref("l10n_br_fiscal.tax_cofins_wh_3").id,
"state": "expired",
}
)

cls.empresa_lc_document_55_serie_1 = cls.env[
"l10n_br_fiscal.document.serie"
].create(
{
"code": "1",
"name": "Série 1",
"document_type_id": cls.env.ref("l10n_br_fiscal.document_55").id,
"active": True,
}
)
cls.configure_normal_company_taxes()

cls.move_out_venda = cls.init_invoice(
"out_invoice",
Expand Down
10 changes: 7 additions & 3 deletions l10n_br_fiscal/models/document_fiscal_line_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,12 @@ def _operation_domain(self):
)

price_gross = fields.Monetary(
string="Gross Product/Service Amount",
help=(
"Total value of products or services (quantity x unit price)"
"before any discounts."
),
compute="_compute_amounts",
string="Amount Gross",
help="Amount without discount.",
)

amount_untaxed = fields.Monetary(
Expand All @@ -223,7 +226,8 @@ def _operation_domain(self):
)

financial_total_gross = fields.Monetary(
string="Amount Financial Gross",
string="Financial Gross Amount",
help="Total amount before any discounts are applied.",
compute="_compute_amounts",
)

Expand Down
14 changes: 4 additions & 10 deletions l10n_br_fiscal/models/document_fiscal_line_mixin_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,13 @@ def fields_view_get(
def _compute_amounts(self):
for record in self:
round_curr = record.currency_id or self.env.ref("base.BRL")
# Valor dos produtos

amount_subtotal = round_curr.round(record.price_unit * record.quantity)
# Total value of products or services
record.price_gross = round_curr.round(record.price_unit * record.quantity)

record.price_gross = (
amount_subtotal
+ record.amount_tax_not_included
- record.amount_tax_withholding
)

record.amount_untaxed = amount_subtotal - record.discount_value
record.amount_untaxed = record.price_gross - record.discount_value

record.amount_fiscal = amount_subtotal - record.discount_value
record.amount_fiscal = record.price_gross - record.discount_value

record.amount_tax = record.amount_tax_not_included

Expand Down
15 changes: 15 additions & 0 deletions l10n_br_fiscal/tests/test_fiscal_document_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,16 @@ def test_nfe_same_state(self):
self.nfe_same_state._onchange_fiscal_operation_id()

for line in self.nfe_same_state.fiscal_line_ids:
# Save the original price_unit value of the line as defined in
# the NFe demo data.
original_price_unit = line.price_unit

line._onchange_product_id_fiscal()

# Restore the original price_unit value,
# as the product change might have altered it.
line.price_unit = original_price_unit

line._onchange_commercial_quantity()
line._onchange_ncm_id()
line._onchange_fiscal_operation_id()
Expand Down Expand Up @@ -158,6 +167,9 @@ def test_nfe_same_state(self):
" Básica to COFINS 3% de Venda de Contribuinte Dentro do Estado.",
)

product_total = line.price_unit * line.quantity
self.assertEqual(line.price_gross, product_total)

self.nfe_same_state.action_document_confirm()

self.assertEqual(
Expand All @@ -174,6 +186,9 @@ def test_nfe_same_state(self):
"Document is not in Authorized state",
)

# Total value of the products
self.assertEqual(self.nfe_same_state.amount_price_gross, 200)

result = self.nfe_same_state.action_document_cancel()
self.assertTrue(result)

Expand Down
Loading