Skip to content

Commit

Permalink
Merge PR #371 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by dreispt
  • Loading branch information
OCA-git-bot committed Oct 10, 2023
2 parents c5f2d49 + 16f7d84 commit 35ac7cf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
23 changes: 16 additions & 7 deletions account_avatax_oca/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ def _avatax_prepare_lines(self, doc_type=None):
# Same as v12
def _avatax_compute_tax(self, commit=False):
"""Contact REST API and recompute taxes for a Sale Order"""
# Override to handle lines with split taxes (e.g. TN)
self and self.ensure_one()
avatax_config = self.company_id.get_avatax_config_company()
if not avatax_config:
Expand Down Expand Up @@ -255,18 +256,26 @@ def _avatax_compute_tax(self, commit=False):
for index, line in enumerate(lines):
tax_result_line = tax_result_lines.get(line.id)
if tax_result_line:
rate = tax_result_line.get("rate", 0.0)
# rate = tax_result_line.get("rate", 0.0)
tax_calculation = 0.0
if tax_result_line["taxableAmount"]:
tax_calculation = (
tax_result_line["taxCalculated"]
/ tax_result_line["taxableAmount"]
)
rate = round(tax_calculation * 100, 4)
tax = Tax.get_avalara_tax(rate, doc_type)
if tax and tax not in line.tax_ids:
line_taxes = (
tax
if avatax_config
else line.tax_ids.filtered(lambda x: not x.is_avatax)
)
line_taxes = line.tax_ids.filtered(lambda x: not x.is_avatax)
taxes_to_set.append((index, line_taxes | tax))
line.avatax_amt_line = tax_result_line["tax"]
self.avatax_amount = tax_result["totalTax"]
self.with_context(check_move_validity=False).avatax_amount = tax_result[
"totalTax"
]
container = {"records": self}
self.with_context(
avatax_invoice=self, check_move_validity=False
)._sync_dynamic_lines(container)
self.line_ids.mapped("move_id")._check_balanced(container)

# Set Taxes on lines in a way that properly triggers onchanges
Expand Down
10 changes: 9 additions & 1 deletion account_avatax_sale_oca/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def _avatax_prepare_lines(self, order_lines, doc_type=None):

def _avatax_compute_tax(self):
"""Contact REST API and recompute taxes for a Sale Order"""
# Override to handle lines with split taxes (e.g. TN)
self and self.ensure_one()
doc_type = self._get_avatax_doc_type()
Tax = self.env["account.tax"]
Expand Down Expand Up @@ -201,7 +202,14 @@ def _avatax_compute_tax(self):
# Should we check the rate with the tax amount?
# tax_amount = tax_result_line["taxCalculated"]
# rate = round(tax_amount / line.price_subtotal * 100, 2)
rate = tax_result_line["rate"]
# rate = tax_result_line["rate"]
tax_calculation = 0.0
if tax_result_line["taxableAmount"]:
tax_calculation = (
tax_result_line["taxCalculated"]
/ tax_result_line["taxableAmount"]
)
rate = round(tax_calculation * 100, 4)
tax = Tax.get_avalara_tax(rate, doc_type)
if tax not in line.tax_id:
line_taxes = (
Expand Down

0 comments on commit 35ac7cf

Please sign in to comment.