Skip to content

Commit

Permalink
[IMP] l10n_br_fiscal: add product.tag test
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiago370 committed Nov 14, 2024
1 parent 267ba5a commit 25b5a8d
Show file tree
Hide file tree
Showing 4 changed files with 226 additions and 4 deletions.
20 changes: 20 additions & 0 deletions l10n_br_fiscal/data/operation_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,18 @@
<field name="state">approved</field>
<field name="product_type">00</field>
</record>
<record id="product_tag_st" model="l10n_br_fiscal.product.tag">
<field name="name">ST</field>
</record>

<record id="tax_icms_regulation_other_state_st" model="l10n_br_fiscal.tax.definition">
<field name="tax_group_id" ref="l10n_br_fiscal.tax_group_icmsst" />
<field name="is_taxed" eval="True" />
<field name="is_debit_credit" eval="True" />
<field name="custom_tax" eval="True" />
<field name="tax_id" ref="l10n_br_fiscal.tax_icmsst_p30_50" />
<field name="state">approved</field>
</record>
<record id="fo_venda_revenda_st_substituido" model="l10n_br_fiscal.operation.line">
<field name="fiscal_operation_id" ref="l10n_br_fiscal.fo_venda" />
<field name="name">Revenda ST contribuinte substituído</field>
Expand All @@ -70,6 +81,15 @@
<field name="cfop_external_id" ref="l10n_br_fiscal.cfop_6404" />
<field name="state">approved</field>
<field name="product_type">00</field>
<field
name="product_fiscal_tag_ids"
eval="[(6,0,[ref('l10n_br_fiscal.product_tag_st')])]"
/>
<field name="tax_icms_or_issqn">icms</field>
<field
name="tax_definition_ids"
eval="[(6, 0, [ref('l10n_br_fiscal.tax_icms_regulation_other_state_st')])]"
/>
</record>

<record
Expand Down
55 changes: 52 additions & 3 deletions l10n_br_fiscal/demo/fiscal_document_demo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<field name="partner_id" ref="l10n_br_base.res_partner_cliente1_sp" />
<field name="user_id" ref="base.user_demo" />
<field name="fiscal_operation_type">out</field>
<!-- <field name="file_xml_autorizacao_id" ref="dummy_file_1"/> FIXME: Este é um campo related!!!!-->
<!-- <field name="file_xml_autorizacao_id" ref="dummy_file_1"/> FIXME: Este é um campo related!!!!-->
</record>

<record id="demo_nfe_line_same_state_1-1" model="l10n_br_fiscal.document.line">
Expand Down Expand Up @@ -285,7 +285,7 @@
/>
<field name="company_id" ref="l10n_br_base.empresa_lucro_presumido" />
<field name="document_serie">1</field>
<field name="partner_id" ref="l10n_br_base.res_partner_cliente9_mg" />
<field name="partner_id" ref="l10n_br_base.res_partner_cliente9_mg" />
<field name="user_id" ref="base.user_demo" />
<field name="fiscal_operation_type">out</field>
</record>
Expand Down Expand Up @@ -385,7 +385,7 @@
/>
<field name="company_id" ref="l10n_br_base.empresa_lucro_presumido" />
<field name="document_serie">1</field>
<field name="partner_id" ref="l10n_br_base.res_partner_cliente9_mg" />
<field name="partner_id" ref="l10n_br_base.res_partner_cliente9_mg" />
<field name="user_id" ref="base.user_demo" />
<field name="fiscal_operation_type">out</field>
</record>
Expand Down Expand Up @@ -946,5 +946,54 @@
<value eval="[ref('demo_nfe_purchase_line_same_state_1-1')]" />
</function>

<!-- NFe Test - Empresa Contribuinte - Outro Estado ST -->
<record id="demo_nfe_other_state_st" model="l10n_br_fiscal.document">
<field name="fiscal_operation_id" ref="l10n_br_fiscal.fo_venda" />
<field name="document_type_id" ref="l10n_br_fiscal.document_55" />
<field
name="document_serie_id"
ref="l10n_br_fiscal.empresa_lc_document_55_serie_1"
/>
<field name="company_id" ref="l10n_br_base.empresa_lucro_presumido" />
<field name="document_serie">1</field>
<field name="partner_id" ref="l10n_br_base.res_partner_cliente5_pe" />
<field name="user_id" ref="base.user_demo" />
<field name="fiscal_operation_type">out</field>
</record>

<record id="demo_nfe_line_other_state_st_1-1" model="l10n_br_fiscal.document.line">
<field name="document_id" ref="demo_nfe_other_state_st" />
<field name="name">Teste ST</field>
<field name="product_id" ref="l10n_br_fiscal.product_delivery_02_st" />
<field name="uom_id" ref="uom.product_uom_unit" />
<field name="price_unit">100</field>
<field name="quantity">1</field>
<field name="fiscal_operation_type">out</field>
<field name="fiscal_operation_id" ref="l10n_br_fiscal.fo_venda" />
<field name="icms_tax_id" ref="l10n_br_fiscal.tax_icms_12_st" />
<field
name="fiscal_operation_line_id"
ref="l10n_br_fiscal.fo_venda_revenda_st_substituido"
/>
</record>

<function model="l10n_br_fiscal.document.line" name="_onchange_product_id_fiscal">
<value eval="[ref('demo_nfe_line_other_state_st_1-1')]" />
</function>

<record id="demo_nfe_line_other_state_st_1-1" model="l10n_br_fiscal.document.line">
<field name="price_unit">100</field>
</record>

<function model="l10n_br_fiscal.document.line" name="_onchange_fiscal_operation_id">
<value eval="[ref('demo_nfe_line_other_state_st_1-1')]" />
</function>

<function
model="l10n_br_fiscal.document.line"
name="_onchange_fiscal_operation_line_id"
>
<value eval="[ref('demo_nfe_line_other_state_st_1-1')]" />
</function>

</odoo>
60 changes: 60 additions & 0 deletions l10n_br_fiscal/demo/product_demo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1978,4 +1978,64 @@
<field name="company_id" ref="l10n_br_base.empresa_lucro_presumido" />
</record>

<!-- Product ST -->
<record id="product_delivery_02_st" model="product.product">
<field name="name">Office Lamp ST</field>
<field name="tax_icms_or_issqn">icms</field>
<field name="categ_id" ref="product.product_category_5" />
<field name="standard_price">35.0</field>
<field name="list_price">40.0</field>
<field name="type">consu</field>
<field name="weight">0.01</field>
<field name="uom_id" ref="uom.product_uom_unit" />
<field name="uom_po_id" ref="uom.product_uom_unit" />
<field name="default_code">FURN_8889</field>
<field
name="operation_line_tag_ids"
eval="[(6,0,[ref('l10n_br_fiscal.product_tag_st')])]"
/>
<field
name="image_1920"
type="base64"
file="product/static/img/product_lamp.png"
/>
<field name="ncm_id" ref="l10n_br_fiscal.ncm_94052000" />
<field name="cest_id" ref="l10n_br_fiscal.cest_2112400" />
<field name="fiscal_genre_id" ref="l10n_br_fiscal.product_genre_94" />
<field name="company_id" ref="l10n_br_base.empresa_lucro_presumido" />
</record>
<!-- fiscal_type property for product_delivery_02_st for lucro presumido company -->
<record
forcecreate="True"
id="fiscal_type_product_delivery_02_st"
model="ir.property"
>
<field name="name">fiscal_type</field>
<field name="fields_id" ref="field_product_template__fiscal_type" />
<field name="value">00</field>
<field name="type">selection</field>
<field
eval="'product.template,'+str(obj().env.ref('l10n_br_fiscal.product_delivery_02_st').product_tmpl_id.id)"
model="product.template"
name="res_id"
/>
<field name="company_id" ref="l10n_br_base.empresa_lucro_presumido" />
</record>
<!-- icms_origin property for product_delivery_01 for simples nacional company -->
<record
forcecreate="True"
id="icms_origin_product_delivery_02_st"
model="ir.property"
>
<field name="name">icms_origin</field>
<field name="fields_id" ref="field_product_template__icms_origin" />
<field name="value">5</field>
<field name="type">selection</field>
<field
eval="'product.template,'+str(obj().env.ref('l10n_br_fiscal.product_delivery_02_st').product_tmpl_id.id)"
model="product.template"
name="res_id"
/>
<field name="company_id" ref="l10n_br_base.empresa_lucro_presumido" />
</record>
</odoo>
95 changes: 94 additions & 1 deletion l10n_br_fiscal/tests/test_fiscal_document_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def setUpClass(cls):
# Contribuinte
cls.nfe_same_state = cls.env.ref("l10n_br_fiscal.demo_nfe_same_state")
cls.nfe_other_state = cls.env.ref("l10n_br_fiscal.demo_nfe_other_state")
cls.nfe_other_state_st = cls.env.ref("l10n_br_fiscal.demo_nfe_other_state_st")
cls.nfe_not_taxpayer = cls.env.ref("l10n_br_fiscal.demo_nfe_nao_contribuinte")

cls.nfe_not_taxpayer_pf = cls.env.ref(
Expand Down Expand Up @@ -174,7 +175,7 @@ def test_nfe_other_state(self):

self.nfe_other_state._onchange_document_serie_id()
self.nfe_other_state._onchange_fiscal_operation_id()

self.nfe_other_state.action_document_confirm()
for line in self.nfe_other_state.fiscal_line_ids:
line._onchange_product_id_fiscal()
line._onchange_commercial_quantity()
Expand Down Expand Up @@ -291,6 +292,98 @@ def test_nfe_other_state(self):
"from COFINS 3% for Venda de Contribuinte p/ Fora do Estado.",
)

def test_nfe_other_state_st(self):
"""Testing NFe in another state with tax substitution."""
empresa_lucro_presumido = self.env.ref("l10n_br_base.empresa_lucro_presumido")
self.nfe_other_state_st._onchange_document_serie_id()
self.nfe_other_state_st._onchange_fiscal_operation_id()

for line in self.nfe_other_state_st.fiscal_line_ids:
line.with_company(empresa_lucro_presumido.id)._onchange_product_id_fiscal()
line.with_company(
empresa_lucro_presumido.id
)._onchange_commercial_quantity()
line.with_company(empresa_lucro_presumido.id)._onchange_ncm_id()
line.with_company(
empresa_lucro_presumido.id
)._onchange_fiscal_operation_id()
line.with_company(
empresa_lucro_presumido.id
)._onchange_fiscal_operation_line_id()
line.with_company(empresa_lucro_presumido.id)._onchange_fiscal_taxes()

if "Revenda" in line.fiscal_operation_line_id.name:
self.assertEqual(
line.cfop_id.code,
"6404",
"Error to mapping CFOP 6404"
" for Revenda de Contribuinte p/ Fora do Estado.",
)

# ICMS
if line.product_id.icms_origin not in ICMS_ORIGIN_TAX_IMPORTED:
line.write(
{
"icms_tax_id": self.env.ref("l10n_br_fiscal.tax_icms_12_st").id,
}
)
line.with_company(empresa_lucro_presumido.id)._onchange_fiscal_taxes()
self.assertEqual(
line.icms_tax_id.name,
"ICMS 010 12%",
"Error to mapping ICMS 010 12%"
" for Venda de Contribuinte p/ Fora do Estado.",
)
self.assertEqual(
line.icmsst_tax_id.name,
"ICMS 30% MVA 50",
"Error to mapping ICMS 30% MVA 50"
" for Venda de Contribuinte p/ Fora do Estado.",
)
self.assertEqual(
line.icms_cst_id.code,
"10",
"Error to mapping CST 00 from ICMS 7%"
" for Venda de Contribuinte p/ Fora do Estado.",
)

# ICMS FCP
self.assertFalse(
line.icmsfcp_tax_id,
"Error to mapping ICMS FCP 2%"
" for Venda de Contribuinte Dentro do Estado.",
)

# PIS
self.assertEqual(
line.pis_tax_id.name,
"PIS 0,65%",
"Error to mapping PIS 0,65%"
" for Venda de Contribuinte p/ Fora do Estado.",
)
self.assertEqual(
line.pis_cst_id.code,
"01",
"Error to mapping CST 01 - Operação Tributável com Alíquota"
" Básica from PIS 0,65% for"
" Venda de Contribuinte p/ Fora do Estado.",
)

# PIS
self.assertEqual(
line.cofins_tax_id.name,
"COFINS 3%",
"Error to mapping COFINS 3%"
" for Venda de Contribuinte p/ Fora do Estado.",
)
self.assertEqual(
line.cofins_cst_id.code,
"01",
"Error to mapping CST 01 -"
" Operação Tributável com Alíquota Básica"
"from COFINS 3% for Venda de Contribuinte p/ Fora do Estado.",
)

def test_nfe_not_taxpayer(self):
"""Test NFe not taxpayer."""

Expand Down

0 comments on commit 25b5a8d

Please sign in to comment.