Skip to content

Commit

Permalink
[IMP] account_avatax_oca: support addresses with only Lat/Long coords
Browse files Browse the repository at this point in the history
  • Loading branch information
dreispt committed Jun 4, 2024
1 parent c816411 commit 3ed14a9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
17 changes: 3 additions & 14 deletions account_avatax_oca/models/avatax_rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,20 +263,8 @@ def get_tax(
doc_date = fields.Date.to_string(doc_date)
create_transaction = {
"addresses": {
"shipFrom": {
"city": origin.city,
"country": origin.country_id.code or None,
"line1": origin.street or None,
"postalCode": origin.zip,
"region": origin.state_id.code or None,
},
"shipTo": {
"city": destination.city,
"country": destination.country_id.code or None,
"line1": destination.street or None,
"postalCode": destination.zip,
"region": destination.state_id.code or None,
},
"shipFrom": origin.get_avatax_address(),
"shipTo": destination.get_avatax_address(),
},
"lines": lineslist,
# 'purchaseOrderNo": "2020-02-05-001"
Expand All @@ -295,6 +283,7 @@ def get_tax(
"type": doc_type,
"commit": commit,
}

if is_override and invoice_date:
create_transaction.update(
{
Expand Down
25 changes: 21 additions & 4 deletions account_avatax_oca/models/partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,25 @@ def get_valid_address_vals(self, validation_on_save=False):
)
return valid_address

def get_avatax_address(self):
# Format an address according to Avatax API for CreateTransaction
# https://developer.avalara.com
# /api-reference/avatax/rest/v2/models/AddressLocationInfo/
if self.partner_latitude or self.partner_longitude:
res = {

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

View check run for this annotation

Codecov / codecov/patch

account_avatax_oca/models/partner.py#L164

Added line #L164 was not covered by tests
"latitude": self.partner_latitude,
"longitude": self.partner_longitude,
}
else:
res = {

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

View check run for this annotation

Codecov / codecov/patch

account_avatax_oca/models/partner.py#L169

Added line #L169 was not covered by tests
"city": self.city,
"country": self.country_id.code or None,
"line1": self.street or None,
"postalCode": self.zip,
"region": self.state_id.code or None,
}
return res

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

View check run for this annotation

Codecov / codecov/patch

account_avatax_oca/models/partner.py#L176

Added line #L176 was not covered by tests

def multi_address_validation(self, validation_on_save=False):
for partner in self:
if not (partner.parent_id and partner.type == "contact"):
Expand Down Expand Up @@ -202,10 +221,8 @@ def create(self, vals_list):

def write(self, vals):
res = super(ResPartner, self).write(vals)
address_fields = ["street", "street2", "city", "zip", "state_id", "country_id"]
if not self.env.context.get("avatax_writing") and any(
x in vals for x in address_fields
):
has_address = any(vals.get(x) for x in ["street", "street2", "city", "zip"])
if has_address and not self.env.context.get("avatax_writing"):
partner = self.with_context(avatax_writing=True)
avatax_config = self.env.company.get_avatax_config_company()
if avatax_config.validation_on_save:
Expand Down

0 comments on commit 3ed14a9

Please sign in to comment.