From 612ae898591a95038d7e97843b4d752e47a38686 Mon Sep 17 00:00:00 2001 From: Diego Paradeda Date: Fri, 18 Oct 2024 16:50:20 -0300 Subject: [PATCH 1/2] [IMP] l10n_br_fiscal: allow operation tax base override --- l10n_br_fiscal/models/operation_line.py | 13 +++++++++++++ l10n_br_fiscal/models/tax.py | 18 +++++++++++++++--- l10n_br_fiscal/views/operation_line_view.xml | 3 +++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/l10n_br_fiscal/models/operation_line.py b/l10n_br_fiscal/models/operation_line.py index a94c8a459208..47a5b20a5620 100644 --- a/l10n_br_fiscal/models/operation_line.py +++ b/l10n_br_fiscal/models/operation_line.py @@ -117,6 +117,19 @@ class OperationLine(models.Model): string="Tax Definition", ) + # Behavior for additional values and costs + additional_values_definition = fields.Selection( + selection=[ + ("tax", "Defined In Tax (Default)"), + ("add", "Include"), + ("do_not_add", "Do not Include"), + ], + default="tax", + required=True, + string="Include other values in tax base", + help="If left unset, value from tax group will be used", + ) + comment_ids = fields.Many2many( comodel_name="l10n_br_fiscal.comment", relation="l10n_br_fiscal_operation_line_comment_rel", diff --git a/l10n_br_fiscal/models/tax.py b/l10n_br_fiscal/models/tax.py index 1a583402aa80..d156ae0b8a05 100644 --- a/l10n_br_fiscal/models/tax.py +++ b/l10n_br_fiscal/models/tax.py @@ -193,11 +193,23 @@ def _compute_tax_base(self, tax, tax_dict, **kwargs): insurance_value = kwargs.get("insurance_value", 0.00) freight_value = kwargs.get("freight_value", 0.00) other_value = kwargs.get("other_value", 0.00) + operation_line = kwargs.get("operation_line", False) + # Initialize additional value to be added to the base + add_value_to_base = 0 + + # Check if the tax group allows additional values to be included in the base if tax.tax_group_id.base_with_additional_values: - tax_dict["add_to_base"] += sum( - [freight_value, insurance_value, other_value] - ) + add_value_to_base = sum([freight_value, insurance_value, other_value]) + + # If oper. line is set, adjust the additional values based on its definition + if operation_line: + if operation_line.additional_values_definition == "do_not_add": + add_value_to_base = 0 + elif operation_line.additional_values_definition == "add": + add_value_to_base = sum([freight_value, insurance_value, other_value]) + + tax_dict["add_to_base"] += add_value_to_base tax_dict["remove_from_base"] += sum([discount_value]) base = 0.00 diff --git a/l10n_br_fiscal/views/operation_line_view.xml b/l10n_br_fiscal/views/operation_line_view.xml index 3a2120a3d11f..1f44c189c10f 100644 --- a/l10n_br_fiscal/views/operation_line_view.xml +++ b/l10n_br_fiscal/views/operation_line_view.xml @@ -81,6 +81,9 @@ nolabel="1" context="{'tree_view_ref': 'l10n_br_fiscal.tax_definition_tree','form_view_ref': 'l10n_br_fiscal.tax_definition_form', 'default_fiscal_operation_line_id': id}" /> + + + From eeb10671ea153ee3840ebbfdda8035558131d948 Mon Sep 17 00:00:00 2001 From: Diego Paradeda Date: Tue, 5 Nov 2024 16:54:24 -0300 Subject: [PATCH 2/2] [IMP] l10n_br_account: test for additional values in tax base --- l10n_br_account/tests/test_account_move_lc.py | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/l10n_br_account/tests/test_account_move_lc.py b/l10n_br_account/tests/test_account_move_lc.py index ef008c7efb60..3d23343a541c 100644 --- a/l10n_br_account/tests/test_account_move_lc.py +++ b/l10n_br_account/tests/test_account_move_lc.py @@ -675,6 +675,82 @@ def test_venda_with_icms_reduction_with_relief(self): move_vals, ) + def test_venda_additional_values_included(self): + """Tests the inclusion of additional values in IPI tax base and price.""" + fopl_id = self.env.ref("l10n_br_fiscal.fo_venda_venda") + + # Setup invoice + additional_values_invoice = self.init_invoice( + "out_invoice", + products=[self.product_a], + document_type=self.env.ref("l10n_br_fiscal.document_55"), + document_serie_id=self.empresa_lc_document_55_serie_1, + fiscal_operation=self.env.ref("l10n_br_fiscal.fo_venda"), + fiscal_operation_lines=[fopl_id], + ) + + additional_values_invoice.invoice_line_ids[0].freight_value = 100 + additional_values_invoice.invoice_line_ids[0].insurance_value = 100 + additional_values_invoice.invoice_line_ids[0].other_value = 100 + + additional_values_invoice.invoice_line_ids._onchange_fiscal_taxes() + additional_values_invoice.line_ids._compute_amounts() + additional_values_invoice.invoice_line_ids.with_context( + check_move_validity=False + )._onchange_price_subtotal() + additional_values_invoice.with_context( + check_move_validity=False + )._recompute_dynamic_lines(recompute_all_taxes=True) + additional_values_invoice.line_ids._onchange_price_subtotal() + additional_values_invoice._check_balanced() + + # Expected inclusive value calculation + # expected = (1 + ipi_mult) * (price_unit + additional_value) + # expected = (1 + 0.05) * (1000 + 300) + expected = 1365 + + self.assertEqual(additional_values_invoice.amount_total, expected) + + def test_venda_additional_values_force_excluded(self): + """Tests forced exclusion of additional values in IPI tax base.""" + fopl_id = self.env.ref("l10n_br_fiscal.fo_venda_venda") + fopl_id.additional_values_definition = "do_not_add" + + # Setup invoice + additional_values_invoice = self.init_invoice( + "out_invoice", + products=[self.product_a], + document_type=self.env.ref("l10n_br_fiscal.document_55"), + document_serie_id=self.empresa_lc_document_55_serie_1, + fiscal_operation=self.env.ref("l10n_br_fiscal.fo_venda"), + fiscal_operation_lines=[fopl_id], + ) + + additional_values_invoice.invoice_line_ids[0].freight_value = 100 + additional_values_invoice.invoice_line_ids[0].insurance_value = 100 + additional_values_invoice.invoice_line_ids[0].other_value = 100 + + additional_values_invoice.invoice_line_ids._onchange_fiscal_taxes() + additional_values_invoice.line_ids._compute_amounts() + additional_values_invoice.invoice_line_ids.with_context( + check_move_validity=False + )._onchange_price_subtotal() + additional_values_invoice.with_context( + check_move_validity=False + )._recompute_dynamic_lines(recompute_all_taxes=True) + additional_values_invoice.line_ids._onchange_price_subtotal() + additional_values_invoice._check_balanced() + + # Expected non-inclusive value calculation + # expected = (1 + ipi_mult) * price_unit + additional_value + # expected = (1 + 0.05) * 1000 + 300 + expected = 1350 + + self.assertEqual(additional_values_invoice.amount_total, expected) + + # Reset FOPL additional values config + fopl_id.additional_values_definition = "tax" + def test_simples_remessa(self): product_line_vals_1 = { "name": self.product_a.display_name,