From 6254e2a068a231adcb1836cead9ee24c9978c2f9 Mon Sep 17 00:00:00 2001 From: Diego Paradeda Date: Fri, 18 Oct 2024 16:50:20 -0300 Subject: [PATCH] [IMP] l10n_br_fiscal: allow operation tax base override --- l10n_br_fiscal/models/operation_line.py | 10 ++++++++++ l10n_br_fiscal/models/tax.py | 18 +++++++++++++++--- l10n_br_fiscal/views/operation_line_view.xml | 3 +++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/l10n_br_fiscal/models/operation_line.py b/l10n_br_fiscal/models/operation_line.py index a94c8a459208..0a94a8806723 100644 --- a/l10n_br_fiscal/models/operation_line.py +++ b/l10n_br_fiscal/models/operation_line.py @@ -117,6 +117,16 @@ class OperationLine(models.Model): string="Tax Definition", ) + # Behavior for additional values and costs + additional_values_definition = fields.Selection( + selection=[ + ("add", "Include"), + ("do_not_add", "Do not Include"), + ], + 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}" /> + + +