Skip to content

Commit

Permalink
[IMP] l10n_br_account: manual values for taxes
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniospneto committed Sep 29, 2023
1 parent 376e0cc commit 6b0b0f4
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
3 changes: 2 additions & 1 deletion l10n_br_account/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def _compute_taxes_mapped(self, base_line):
tax_type == "purchase" and base_line.credit
)
price_unit_wo_discount = base_line.amount_currency

manual_tax_values = base_line._prepare_br_manual_tax_dict()
balance_taxes_res = base_line.tax_ids._origin.with_context(
force_sign=move._get_tax_force_sign()
).compute_all(
Expand Down Expand Up @@ -383,6 +383,7 @@ def _compute_taxes_mapped(self, base_line):
icmssn_range=base_line.icmssn_range_id,
icms_origin=base_line.icms_origin,
ind_final=base_line.ind_final,
**manual_tax_values,
)

return balance_taxes_res
Expand Down
64 changes: 63 additions & 1 deletion l10n_br_account/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
from odoo import _, api, fields, models
from odoo.exceptions import UserError

from odoo.addons.l10n_br_fiscal.models.document_fiscal_line_mixin_methods import (
FISCAL_TAX_PREFIXES,
)

from .account_move import InheritsCheckMuteLogger

# These fields have the same name in account.move.line
Expand Down Expand Up @@ -330,6 +334,10 @@ def _get_price_total_and_subtotal(
move_type=None,
):
self.ensure_one()

# get the dict with the values of the taxes entered manually.
manual_tax_values = self._prepare_br_manual_tax_dict()

return super(
AccountMoveLine,
self.with_context(
Expand All @@ -351,6 +359,7 @@ def _get_price_total_and_subtotal(
icmssn_range=self.icmssn_range_id,
icms_origin=self.icms_origin,
ind_final=self.ind_final,
**manual_tax_values,
),
)._get_price_total_and_subtotal(
price_unit=price_unit or self.price_unit,
Expand All @@ -363,6 +372,17 @@ def _get_price_total_and_subtotal(
move_type=move_type or self.move_id.move_type,
)

def _get_manual_tax_values_from_context(self):
tax_values = {}
suffixes = ["_base_manual", "_value_manual"]

for tax_prefix in FISCAL_TAX_PREFIXES:
for suffix in suffixes:
attr_name = tax_prefix + suffix
tax_values[attr_name] = self.env.context.get(attr_name)

return tax_values

@api.model
def _get_price_total_and_subtotal_model(
self,
Expand Down Expand Up @@ -403,6 +423,7 @@ def _get_price_total_and_subtotal_model(
force_sign = (
-1 if move_type in ("out_invoice", "in_refund", "out_receipt") else 1
)
manual_tax_values = self._get_manual_tax_values_from_context()
taxes_res = taxes._origin.with_context(force_sign=force_sign).compute_all(
line_discount_price_unit,
currency=currency,
Expand All @@ -429,6 +450,7 @@ def _get_price_total_and_subtotal_model(
icmssn_range=self.env.context.get("icmssn_range"),
icms_origin=self.env.context.get("icms_origin"),
ind_final=self.env.context.get("ind_final"),
**manual_tax_values,
)

result["price_subtotal"] = taxes_res["total_excluded"]
Expand All @@ -440,7 +462,47 @@ def _get_price_total_and_subtotal_model(

return result

@api.onchange("fiscal_tax_ids")
@api.onchange(
"fiscal_tax_ids",
"icms_base_manual",
"icms_value_manual",
"icmsst_base_manual",
"icmsst_value_manual",
"issqn_base_manual",
"issqn_value_manual",
"issqn_wh_base_manual",
"issqn_wh_value_manual",
"icmsst_wh_base_manual",
"icmsst_wh_value_manual",
"ipi_base_manual",
"ipi_value_manual",
"ii_base_manual",
"ii_value_manual",
"cofins_base_manual",
"cofins_value_manual",
"cofinsst_base_manual",
"cofinsst_value_manual",
"cofins_wh_base_manual",
"cofins_wh_value_manual",
"pis_base_manual",
"pis_value_manual",
"pisst_base_manual",
"pisst_value_manual",
"pis_wh_base_manual",
"pis_wh_value_manual",
"csll_base_manual",
"csll_value_manual",
"csll_wh_base_manual",
"csll_wh_value_manual",
"irpj_base_manual",
"irpj_value_manual",
"irpj_wh_base_manual",
"irpj_wh_value_manual",
"inss_base_manual",
"inss_value_manual",
"inss_wh_base_manual",
"inss_wh_value_manual",
)
def _onchange_fiscal_tax_ids(self):
"""Ao alterar o campo fiscal_tax_ids que contém os impostos fiscais,
são atualizados os impostos contábeis relacionados"""
Expand Down
2 changes: 2 additions & 0 deletions l10n_br_account/models/account_tax.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def compute_all(
icmssn_range=None,
icms_origin=None,
ind_final=FINAL_CUSTOMER_NO,
**kwargs,
):
"""Returns all information required to apply taxes
(in self + their children in case of a tax goup).
Expand Down Expand Up @@ -117,6 +118,7 @@ def compute_all(
icmssn_range=icmssn_range,
icms_origin=icms_origin or product.icms_origin,
ind_final=ind_final,
**kwargs,
)

taxes_results["amount_tax_included"] = fiscal_taxes_results["amount_included"]
Expand Down

0 comments on commit 6b0b0f4

Please sign in to comment.