Skip to content

Commit

Permalink
[FIX] tax included/excluded for imported documents
Browse files Browse the repository at this point in the history
  • Loading branch information
rvalyi committed Nov 14, 2023
1 parent 4ea193c commit 24a03b7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
41 changes: 36 additions & 5 deletions l10n_br_account/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ def _inject_shadowed_fields(self, vals_list):

@api.model_create_multi
def create(self, vals_list):
inv_line_index = -1
for values in vals_list:
inv_line_index_old = inv_line_index
if values.get("product_id"):
inv_line_index += 1
if values.get("fiscal_document_line_id"):
fiscal_line_data = (
self.env["l10n_br_fiscal.document.line"]
Expand Down Expand Up @@ -212,16 +216,38 @@ def create(self, vals_list):
cfop_id = (
self.env["l10n_br_fiscal.cfop"].browse(cfop) if cfop else False
)

if move_id.imported_document and inv_line_index != inv_line_index_old:

amount_tax_included = (
move_id.fiscal_document_id.fiscal_line_ids[
inv_line_index
].icms_value
+ move_id.fiscal_document_id.fiscal_line_ids[
inv_line_index
].pis_value
+ move_id.fiscal_document_id.fiscal_line_ids[
inv_line_index
].cofins_value
)

amount_tax_not_included = (
move_id.fiscal_document_id.fiscal_line_ids[
inv_line_index
].ipi_value
)
else:
amount_tax_included = values.get("amount_tax_included")
amount_tax_not_included = values.get("amount_tax_not_included")

values.update(
self._get_amount_credit_debit_model(
move_id,
exclude_from_invoice_tab=values.get(
"exclude_from_invoice_tab", False
),
amount_tax_included=values.get("amount_tax_included", 0),
amount_tax_not_included=values.get(
"amount_tax_not_included", 0
),
amount_tax_included=amount_tax_included,
amount_tax_not_included=amount_tax_not_included,
amount_total=fiscal_line.amount_total,
currency_id=move_id.currency_id,
company_id=move_id.company_id,
Expand Down Expand Up @@ -417,7 +443,7 @@ def _get_price_total_and_subtotal_model(

insurance_value = self.env.context.get("insurance_value", 0)
other_value = self.env.context.get("other_value", 0)
freight_value = self.env.context.get("other_value", 0)
freight_value = self.env.context.get("other_value", 0) # TODO freight_value?
ii_customhouse_charges = self.env.context.get("ii_customhouse_charges", 0)

# Compute 'price_total'.
Expand Down Expand Up @@ -581,6 +607,11 @@ def _get_amount_credit_debit(
# The formatting was a little strange, but I tried to make it as close as
# possible to the logic adopted by native Odoo.
# Example: _get_fields_onchange_subtotal
if self._is_imported():
# this will get the Credit side correct for imported fiscal documents:
amount_tax_included = self.icms_value + self.pis_value + self.cofins_value
amount_tax_not_included = self.ipi_value

return self._get_amount_credit_debit_model(
move_id=self.move_id if move_id is None else move_id,
exclude_from_invoice_tab=self.exclude_from_invoice_tab
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def _update_taxes(self):
line.estimate_tax = compute_result.get("estimate_tax", 0.0)
if self._is_imported():
continue

for tax in line.fiscal_tax_ids:
computed_tax = computed_taxes.get(tax.tax_domain, {})
if hasattr(line, "%s_tax_id" % (tax.tax_domain,)):
Expand Down

0 comments on commit 24a03b7

Please sign in to comment.