Skip to content

Commit

Permalink
[IMP] l10n_br_fiscal: allow operation tax base override
Browse files Browse the repository at this point in the history
  • Loading branch information
DiegoParadeda committed Oct 18, 2024
1 parent 9ca8d5e commit 612ae89
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
13 changes: 13 additions & 0 deletions l10n_br_fiscal/models/operation_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 15 additions & 3 deletions l10n_br_fiscal/models/tax.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 208 in l10n_br_fiscal/models/tax.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_fiscal/models/tax.py#L208

Added line #L208 was not covered by tests
elif operation_line.additional_values_definition == "add":
add_value_to_base = sum([freight_value, insurance_value, other_value])

Check warning on line 210 in l10n_br_fiscal/models/tax.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_fiscal/models/tax.py#L210

Added line #L210 was not covered by tests

tax_dict["add_to_base"] += add_value_to_base
tax_dict["remove_from_base"] += sum([discount_value])

base = 0.00
Expand Down
3 changes: 3 additions & 0 deletions l10n_br_fiscal/views/operation_line_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
/>
<group>
<field name="additional_values_definition" />
</group>
</page>
<page name="extra_info" string="Extra Info">
<group>
Expand Down

0 comments on commit 612ae89

Please sign in to comment.