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 10, 2024
1 parent 267ba5a commit b9e08f4
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 4 deletions.
7 changes: 7 additions & 0 deletions l10n_br_fiscal/data/operation_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
<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="fo_venda_revenda_st_substituido" model="l10n_br_fiscal.operation.line">
<field name="fiscal_operation_id" ref="l10n_br_fiscal.fo_venda" />
Expand All @@ -70,6 +73,10 @@
<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')])]"
/>
</record>

<record
Expand Down
54 changes: 51 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,53 @@
<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="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>
59 changes: 59 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,63 @@
<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="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>
103 changes: 102 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,106 @@ def test_nfe_other_state(self):
"from COFINS 3% for Venda de Contribuinte p/ Fora do Estado.",
)

def test_nfe_other_state_st(self):
"""Test NFe other state."""
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 6102"
" for Revenda de Contribuinte p/ Fora do Estado.",
)
else:
self.assertEqual(

Check warning on line 323 in l10n_br_fiscal/tests/test_fiscal_document_generic.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_fiscal/tests/test_fiscal_document_generic.py#L323

Added line #L323 was not covered by tests
line.cfop_id.code,
"6101",
"Error to mapping CFOP 6101"
" for Venda de Contribuinte p/ Fora do Estado.",
)

# ICMS
if line.product_id.icms_origin in ICMS_ORIGIN_TAX_IMPORTED:
self.assertEqual(

Check warning on line 332 in l10n_br_fiscal/tests/test_fiscal_document_generic.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_fiscal/tests/test_fiscal_document_generic.py#L332

Added line #L332 was not covered by tests
line.icms_tax_id.name,
"ICMS 4%",
"Error to mapping ICMS 4%"
" for Venda de Contribuinte p/ Fora do Estado.",
)
self.assertEqual(

Check warning on line 338 in l10n_br_fiscal/tests/test_fiscal_document_generic.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_fiscal/tests/test_fiscal_document_generic.py#L338

Added line #L338 was not covered by tests
line.icms_cst_id.code,
"00",
"Error to mapping CST 00 from ICMS 4%"
" for Venda de Contribuinte p/ Fora do Estado.",
)
else:
self.assertEqual(
line.icms_tax_id.name,
"ICMS 7%",
"Error to mapping ICMS 7%"
" for Venda de Contribuinte p/ Fora do Estado.",
)
self.assertEqual(
line.icms_cst_id.code,
"00",
"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 b9e08f4

Please sign in to comment.