Skip to content

Commit

Permalink
Merge branch 14.0-imp-tax-manual-values PR OCA#2559
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniospneto committed May 30, 2024
2 parents 207362e + f64f248 commit 6df8adc
Show file tree
Hide file tree
Showing 8 changed files with 1,194 additions and 471 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 @@ -422,7 +422,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 @@ -451,6 +451,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 @@ -5,6 +5,10 @@

from odoo import api, fields, models

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 @@ -369,6 +373,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 @@ -391,6 +399,7 @@ def _get_price_total_and_subtotal(
icms_origin=self.icms_origin,
ind_final=self.ind_final,
icms_relief_value=self.icms_relief_value,
**manual_tax_values,
),
)._get_price_total_and_subtotal(
price_unit=price_unit or self.price_unit,
Expand All @@ -403,6 +412,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 @@ -444,6 +464,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 @@ -470,6 +491,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 Down Expand Up @@ -497,7 +519,47 @@ def _onchange_fiscal_document_line_id(self):
# override the default product uom (set by the onchange):
self.product_uom_id = self.fiscal_document_line_id.uom_id.id

@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
Loading

0 comments on commit 6df8adc

Please sign in to comment.