diff --git a/l10n_br_account/tests/common.py b/l10n_br_account/tests/common.py index bc755c0417ae..7f477b4ab800 100644 --- a/l10n_br_account/tests/common.py +++ b/l10n_br_account/tests/common.py @@ -143,28 +143,129 @@ def setUpClass(cls, chart_template_ref=None): } ) + 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" 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" + + 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 diff --git a/l10n_br_account/tests/test_account_move_lc.py b/l10n_br_account/tests/test_account_move_lc.py index 0ac71e96704b..8dc31df6413a 100644 --- a/l10n_br_account/tests/test_account_move_lc.py +++ b/l10n_br_account/tests/test_account_move_lc.py @@ -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", diff --git a/l10n_br_fiscal/models/document_fiscal_line_mixin.py b/l10n_br_fiscal/models/document_fiscal_line_mixin.py index a3f76bcf53ce..1ac41117f2b5 100644 --- a/l10n_br_fiscal/models/document_fiscal_line_mixin.py +++ b/l10n_br_fiscal/models/document_fiscal_line_mixin.py @@ -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( @@ -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", ) diff --git a/l10n_br_fiscal/models/document_fiscal_line_mixin_methods.py b/l10n_br_fiscal/models/document_fiscal_line_mixin_methods.py index b5cbf67a0901..908733da8da2 100644 --- a/l10n_br_fiscal/models/document_fiscal_line_mixin_methods.py +++ b/l10n_br_fiscal/models/document_fiscal_line_mixin_methods.py @@ -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 diff --git a/l10n_br_fiscal/tests/test_fiscal_document_generic.py b/l10n_br_fiscal/tests/test_fiscal_document_generic.py index 2dfb931c87cc..385cbef63037 100644 --- a/l10n_br_fiscal/tests/test_fiscal_document_generic.py +++ b/l10n_br_fiscal/tests/test_fiscal_document_generic.py @@ -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() @@ -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( @@ -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)