Skip to content

Commit

Permalink
[18.0][MIG] account_avatax_oca: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kobros-tech committed Jan 3, 2025
1 parent b66d2ce commit 75219d1
Show file tree
Hide file tree
Showing 21 changed files with 937 additions and 321 deletions.
302 changes: 152 additions & 150 deletions account_avatax_oca/README.rst

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion account_avatax_oca/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Avalara Avatax Certified Connector",
"version": "17.0.1.3.1",
"version": "18.0.1.0.0",
"author": "Open Source Integrators, Fabrice Henrion,"
"Sodexis, Odoo Community Association (OCA)",
"summary": "Compute Sales Tax using the Avalara Avatax Service",
Expand Down
19 changes: 12 additions & 7 deletions account_avatax_oca/demo/avatax_demo.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<odoo>
<!-- fake avatax API configuraation -->
<record id="avatax_api_configuraation" model="avalara.salestax">
<field name="company_id" ref="base.main_company" />
<field name="account_number">123456789</field>
<field name="license_key">avatax_key</field>
</record>

<record id="avatax_customer" model="res.partner">
<field name="name">Washington Customer</field>
Expand All @@ -24,21 +30,20 @@

<record id="avatax_product_sku1" model="product.product">
<field name="name">Test Item P0000000</field>
<field name="detailed_type">product</field>
<field name="type">consu</field>
<field name="list_price">100.0</field>
<field name="tax_code_id" ref="avatax_product_taxcodeP" />
<field name="tax_code_id" ref="account_avatax_oca.avatax_product_taxcodeP" />
</record>
<record id="avatax_product_sku2" model="product.product">
<field name="name">Test Item NT</field>
<field name="detailed_type">product</field>
<field name="type">consu</field>
<field name="list_price">100.0</field>
<field name="tax_code_id" ref="avatax_product_taxcodeNT" />
<field name="tax_code_id" ref="account_avatax_oca.avatax_product_taxcodeNT" />
</record>
<record id="avatax_product_freight" model="product.product">
<field name="name">Common Carrier FR020100</field>
<field name="detailed_type">service</field>
<field name="type">service</field>
<field name="list_price">50.0</field>
<field name="tax_code_id" ref="avatax_product_taxcodeF" />
<field name="tax_code_id" ref="account_avatax_oca.avatax_product_taxcodeF" />
</record>

</odoo>
18 changes: 9 additions & 9 deletions account_avatax_oca/models/account_move.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import logging

from odoo import _, api, fields, models
from odoo import api, fields, models
from odoo.exceptions import UserError
from odoo.tests.common import Form

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -268,12 +267,11 @@ def _avatax_compute_tax(self, commit=False):

# Set Taxes on lines in a way that properly triggers onchanges
# This same approach is also used by the official account_taxcloud connector
with Form(self) as move_form:
for index, taxes in taxes_to_set:
with move_form.invoice_line_ids.edit(index) as line_form:
line_form.tax_ids.clear()
for tax in taxes:
line_form.tax_ids.add(tax)
for index, taxes in taxes_to_set:
# Access the invoice line by index
line = self.invoice_line_ids[index]
# Update the tax_ids field
line.write({"tax_ids": [(6, 0, [tax.id for tax in taxes])]})

return tax_result

Expand Down Expand Up @@ -316,7 +314,9 @@ def _post(self, soft=True):
if not addr.date_validation:
# The Validate action will be interrupted
# if the address is not validated
raise UserError(_("Avatax address is not validated!"))
raise UserError(

Check warning on line 317 in account_avatax_oca/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_avatax_oca/models/account_move.py#L317

Added line #L317 was not covered by tests
self.env._("Avatax address is not validated!")
)
# We should compute taxes before validating the invoice
# to ensure correct account moves
# However, we can't save the invoice because it wasn't assigned a
Expand Down
8 changes: 4 additions & 4 deletions account_avatax_oca/models/account_tax.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from math import copysign

from odoo import _, api, exceptions, fields, models
from odoo import api, exceptions, fields, models
from odoo.tools.float_utils import float_compare


Expand All @@ -25,7 +25,7 @@ def _get_avalara_tax_domain(self, tax_rate, doc_type):

@api.model
def _get_avalara_tax_name(self, tax_rate, doc_type=None):
return _("{}%*").format(str(tax_rate))
return self.env._("{}%*").format(str(tax_rate))

@api.model
def get_avalara_tax(self, tax_rate, doc_type):
Expand All @@ -38,7 +38,7 @@ def get_avalara_tax(self, tax_rate, doc_type):
tax_template = self.search(domain, limit=1)
if not tax_template:
raise exceptions.UserError(
_("Please configure Avatax Tax for Company %s:")
self.env._("Please configure Avatax Tax for Company %s:")
% self.env.company.name
)
# If you get a unique constraint error here,
Expand Down Expand Up @@ -105,7 +105,7 @@ def compute_all(
if avatax_amount is None:
avatax_amount = 0.0
raise exceptions.UserError(

Check warning on line 107 in account_avatax_oca/models/account_tax.py

View check run for this annotation

Codecov / codecov/patch

account_avatax_oca/models/account_tax.py#L106-L107

Added lines #L106 - L107 were not covered by tests
_(
self.env._(
"Incorrect retrieval of Avatax amount for Invoice "
"%(avatax_invoice)s: product %(product.display_name)s, "
"price_unit %(-price_unit)f , quantity %(quantity)f"
Expand Down
22 changes: 14 additions & 8 deletions account_avatax_oca/models/avalara_salestax.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

from odoo import _, api, fields, models
from odoo import api, fields, models
from odoo.exceptions import UserError

from .avatax_rest_api import AvaTaxRESTService
Expand Down Expand Up @@ -214,7 +214,7 @@ def create_transaction(
if not partner.customer_code:
if not avatax_config.auto_generate_customer_code:
raise UserError(

Check warning on line 216 in account_avatax_oca/models/avalara_salestax.py

View check run for this annotation

Codecov / codecov/patch

account_avatax_oca/models/avalara_salestax.py#L216

Added line #L216 was not covered by tests
_(
self.env._(
"Customer Code for customer %(partner.name)s not defined.\n\n "
"You can edit the Customer Code in customer profile. "
'You can fix by clicking "Generate Customer Code" '
Expand All @@ -226,12 +226,14 @@ def create_transaction(

if not shipping_address:
raise UserError(

Check warning on line 228 in account_avatax_oca/models/avalara_salestax.py

View check run for this annotation

Codecov / codecov/patch

account_avatax_oca/models/avalara_salestax.py#L228

Added line #L228 was not covered by tests
_("There is no source shipping address defined for partner %s.")
self.env._(
"There is no source shipping address defined for partner %s."
)
% partner.name
)

if not ship_from_address:
raise UserError(_("There is no Company address defined."))
raise UserError(self.env._("There is no Company address defined."))

Check warning on line 236 in account_avatax_oca/models/avalara_salestax.py

View check run for this annotation

Codecov / codecov/patch

account_avatax_oca/models/avalara_salestax.py#L236

Added line #L236 was not covered by tests

if avatax_config.validation_on_save:
for address in [partner, shipping_address, ship_from_address]:
Expand All @@ -246,27 +248,31 @@ def create_transaction(
):
if not shipping_address.date_validation:
raise UserError(

Check warning on line 250 in account_avatax_oca/models/avalara_salestax.py

View check run for this annotation

Codecov / codecov/patch

account_avatax_oca/models/avalara_salestax.py#L250

Added line #L250 was not covered by tests
_(
self.env._(
"Please validate the shipping address for the partner "
"%(partner.name)s."
)
)

# if not avatax_config.address_validation:
if not ship_from_address.date_validation:
raise UserError(_("Please validate the origin warehouse address."))
raise UserError(

Check warning on line 259 in account_avatax_oca/models/avalara_salestax.py

View check run for this annotation

Codecov / codecov/patch

account_avatax_oca/models/avalara_salestax.py#L259

Added line #L259 was not covered by tests
self.env._("Please validate the origin warehouse address.")
)

if avatax_config.disable_tax_calculation:
_logger.info(

Check warning on line 264 in account_avatax_oca/models/avalara_salestax.py

View check run for this annotation

Codecov / codecov/patch

account_avatax_oca/models/avalara_salestax.py#L264

Added line #L264 was not covered by tests
"Avatax tax calculation is disabled. Skipping %s %s.",
self.env._("Avatax tax calculation is disabled. Skipping %s %s."),
doc_code,
doc_type,
)
return False

Check warning on line 269 in account_avatax_oca/models/avalara_salestax.py

View check run for this annotation

Codecov / codecov/patch

account_avatax_oca/models/avalara_salestax.py#L269

Added line #L269 was not covered by tests

if commit and avatax_config.disable_tax_reporting:
_logger.warning(

Check warning on line 272 in account_avatax_oca/models/avalara_salestax.py

View check run for this annotation

Codecov / codecov/patch

account_avatax_oca/models/avalara_salestax.py#L272

Added line #L272 was not covered by tests
_("Avatax commiting document %s, but it tax reporting is disabled."),
self.env._(
"Avatax commiting document %s, but it tax reporting is disabled."
),
doc_code,
)

Expand Down
5 changes: 3 additions & 2 deletions account_avatax_oca/models/avatax_rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pprint
import socket

from odoo import _, fields, tools
from odoo import _, fields
from odoo.exceptions import UserError

_logger = logging.getLogger(__name__)
Expand All @@ -26,6 +26,7 @@ def __init__(
config=None,
):
self.config = config
self.env = config and config.env or None
self.timeout = not config and timeout or config.request_timeout
self.is_log_enabled = enable_log or config and config.logging
# Set elements adapter defaults
Expand Down Expand Up @@ -250,7 +251,7 @@ def get_tax(
lineslist = [
{
"number": line["id"].id,
"description": tools.ustr(line.get("description", ""))[:255],
"description": str(line.get("description", ""))[:255],
"itemCode": line.get("itemcode"),
"quantity": line.get("qty", 1),
"amount": line.get("amount", 0.0),
Expand Down
13 changes: 9 additions & 4 deletions account_avatax_oca/models/partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import time
from random import random

from odoo import _, api, fields, models
from odoo import api, fields, models
from odoo.exceptions import UserError

from .avatax_rest_api import AvaTaxRESTService
Expand All @@ -22,7 +22,7 @@ class ResPartner(models.Model):
def _onchange_property_exemption_contry_wide(self):
if self.property_exemption_country_wide:
message = (

Check warning on line 24 in account_avatax_oca/models/partner.py

View check run for this annotation

Codecov / codecov/patch

account_avatax_oca/models/partner.py#L24

Added line #L24 was not covered by tests
_(
self.env._(
"Enabling the exemption status for all states"
" may have tax compliance risks,"
" and should be carefully considered.\n\n"
Expand All @@ -31,7 +31,12 @@ def _onchange_property_exemption_contry_wide(self):
" for every state this Partner may have transactions."
),
)
return {"warning": {"title": _("Tax Compliance Risk"), "message": message}}
return {

Check warning on line 34 in account_avatax_oca/models/partner.py

View check run for this annotation

Codecov / codecov/patch

account_avatax_oca/models/partner.py#L34

Added line #L34 was not covered by tests
"warning": {
"title": self.env._("Tax Compliance Risk"),
"message": message,
}
}

date_validation = fields.Date(
"Last Validation Date",
Expand Down Expand Up @@ -101,7 +106,7 @@ def check_exemption_number(self):
partner.property_exemption_code_id or partner.property_exemption_number
):
raise UserError(

Check warning on line 108 in account_avatax_oca/models/partner.py

View check run for this annotation

Codecov / codecov/patch

account_avatax_oca/models/partner.py#L108

Added line #L108 was not covered by tests
_(
self.env._(
"Please enter either Exemption Number or Exemption Code"
" for marking customer as Exempt."
)
Expand Down
7 changes: 4 additions & 3 deletions account_avatax_oca/models/res_company.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

from odoo import _, models
from odoo import models

_LOGGER = logging.getLogger(__name__)

Expand All @@ -18,11 +18,12 @@ def get_avatax_config_company(self):
)
if len(res) > 1:
_LOGGER.warning(

Check warning on line 20 in account_avatax_oca/models/res_company.py

View check run for this annotation

Codecov / codecov/patch

account_avatax_oca/models/res_company.py#L20

Added line #L20 was not covered by tests
_("Company %s has too many Avatax configurations!"),
self.env._("Company %s has too many Avatax configurations!"),
self.display_name,
)
if len(res) < 1:
_LOGGER.warning(

Check warning on line 25 in account_avatax_oca/models/res_company.py

View check run for this annotation

Codecov / codecov/patch

account_avatax_oca/models/res_company.py#L25

Added line #L25 was not covered by tests
_("Company %s has no Avatax configuration."), self.display_name
self.env._("Company %s has no Avatax configuration."),
self.display_name,
)
return res and res[0]
2 changes: 2 additions & 0 deletions account_avatax_oca/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@
- Murtuza Saleh
- Sodexis
- Atchuthan Ubendran
- Kencove (<https://www.kencove.com>)
- Mohamed Alkobrosli \<<[email protected]>\>
Loading

0 comments on commit 75219d1

Please sign in to comment.