Skip to content

Commit

Permalink
[MIG] account_avatax_repair_oca: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexPForgeFlow committed Aug 16, 2023
1 parent fcbc7c2 commit c795dbd
Showing 1 changed file with 56 additions and 55 deletions.
111 changes: 56 additions & 55 deletions account_avatax_repair_oca/models/repair_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,60 +170,61 @@ def _avatax_compute_tax(self):
if avatax_config.use_partner_invoice_id:
partner = self.partner_invoice_id
taxable_lines = self._avatax_prepare_lines(self.operations, self.fees_lines)
tax_result = avatax_config.create_transaction(
fields.Date.today(),
self.name,
doc_type,
partner,
warehouse.partner_id or self.company_id.partner_id,
self.tax_address_id or self.partner_id,
taxable_lines,
self.user_id,
self.exemption_code or None,
self.exemption_code_id.code or None,
currency_id=self.currency_id,
log_to_record=self,
)
tax_result_lines = {int(x["lineNumber"]): x for x in tax_result["lines"]}
for line in self.operations:
external_line_identifier = self.env.context.get(
"lineNumber", False
) # Used in tests
line_id = external_line_identifier or line.id
tax_result_line = tax_result_lines.get(line_id)
if tax_result_line:
# 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"]
tax = Tax.get_avalara_tax(rate, doc_type)
if tax not in line.tax_id:
line_taxes = (
tax
if avatax_config.override_line_taxes
else tax | line.tax_id.filtered(lambda x: not x.is_avatax)
)
line.tax_id = line_taxes
line.tax_amt_avatax = tax_result_line["tax"]
if taxable_lines:
tax_result = avatax_config.create_transaction(
fields.Date.today(),
self.name,
doc_type,
partner,
warehouse.partner_id or self.company_id.partner_id,
self.tax_address_id or self.partner_id,
taxable_lines,
self.user_id,
self.exemption_code or None,
self.exemption_code_id.code or None,
currency_id=self.currency_id,
log_to_record=self,
)
tax_result_lines = {int(x["lineNumber"]): x for x in tax_result["lines"]}
for line in self.operations:
external_line_identifier = self.env.context.get(
"lineNumber", False
) # Used in tests
line_id = external_line_identifier or line.id
tax_result_line = tax_result_lines.get(line_id)
if tax_result_line:
# 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"]
tax = Tax.get_avalara_tax(rate, doc_type)
if tax not in line.tax_id:
line_taxes = (
tax
if avatax_config.override_line_taxes
else tax | line.tax_id.filtered(lambda x: not x.is_avatax)
)
line.tax_id = line_taxes
line.tax_amt_avatax = tax_result_line["tax"]

for line in self.fees_lines:
tax_result_line = tax_result_lines.get(line.id)
if tax_result_line:
# 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"]
tax = Tax.get_avalara_tax(rate, doc_type)
if tax not in line.tax_id:
line_taxes = (
tax
if avatax_config.override_line_taxes
else tax | line.tax_id.filtered(lambda x: not x.is_avatax)
)
line.tax_id = line_taxes
line.tax_amt_avatax = tax_result_line["tax"]
for line in self.fees_lines:
tax_result_line = tax_result_lines.get(line.id)
if tax_result_line:
# 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"]
tax = Tax.get_avalara_tax(rate, doc_type)
if tax not in line.tax_id:
line_taxes = (
tax
if avatax_config.override_line_taxes
else tax | line.tax_id.filtered(lambda x: not x.is_avatax)
)
line.tax_id = line_taxes
line.tax_amt_avatax = tax_result_line["tax"]

self.amount_tax_avatax = tax_result.get("totalTax")
self.amount_tax_avatax = tax_result.get("totalTax")
return True

def avalara_compute_taxes(self):
Expand Down Expand Up @@ -317,9 +318,9 @@ def write(self, vals):

def copy(self, default=None):
repair = super().copy(default)
if self.partner_id.property_tax_exempt:
repair.exemption_code = self.partner_id.property_exemption_number
repair.exemption_code_id = self.partner_id.property_exemption_code_id
repair.onchange_partner_id()
repair._compute_onchange_exemption()

avatax_config = self.env.company.get_avatax_config_company()
if (
avatax_config.repair_calculate_tax
Expand Down

0 comments on commit c795dbd

Please sign in to comment.