Skip to content

Commit 3ed14a9

Browse files
committed
[IMP] account_avatax_oca: support addresses with only Lat/Long coords
1 parent c816411 commit 3ed14a9

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

Diff for: account_avatax_oca/models/avatax_rest_api.py

+3-14
Original file line numberDiff line numberDiff line change
@@ -263,20 +263,8 @@ def get_tax(
263263
doc_date = fields.Date.to_string(doc_date)
264264
create_transaction = {
265265
"addresses": {
266-
"shipFrom": {
267-
"city": origin.city,
268-
"country": origin.country_id.code or None,
269-
"line1": origin.street or None,
270-
"postalCode": origin.zip,
271-
"region": origin.state_id.code or None,
272-
},
273-
"shipTo": {
274-
"city": destination.city,
275-
"country": destination.country_id.code or None,
276-
"line1": destination.street or None,
277-
"postalCode": destination.zip,
278-
"region": destination.state_id.code or None,
279-
},
266+
"shipFrom": origin.get_avatax_address(),
267+
"shipTo": destination.get_avatax_address(),
280268
},
281269
"lines": lineslist,
282270
# 'purchaseOrderNo": "2020-02-05-001"
@@ -295,6 +283,7 @@ def get_tax(
295283
"type": doc_type,
296284
"commit": commit,
297285
}
286+
298287
if is_override and invoice_date:
299288
create_transaction.update(
300289
{

Diff for: account_avatax_oca/models/partner.py

+21-4
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,25 @@ def get_valid_address_vals(self, validation_on_save=False):
156156
)
157157
return valid_address
158158

159+
def get_avatax_address(self):
160+
# Format an address according to Avatax API for CreateTransaction
161+
# https://developer.avalara.com
162+
# /api-reference/avatax/rest/v2/models/AddressLocationInfo/
163+
if self.partner_latitude or self.partner_longitude:
164+
res = {
165+
"latitude": self.partner_latitude,
166+
"longitude": self.partner_longitude,
167+
}
168+
else:
169+
res = {
170+
"city": self.city,
171+
"country": self.country_id.code or None,
172+
"line1": self.street or None,
173+
"postalCode": self.zip,
174+
"region": self.state_id.code or None,
175+
}
176+
return res
177+
159178
def multi_address_validation(self, validation_on_save=False):
160179
for partner in self:
161180
if not (partner.parent_id and partner.type == "contact"):
@@ -202,10 +221,8 @@ def create(self, vals_list):
202221

203222
def write(self, vals):
204223
res = super(ResPartner, self).write(vals)
205-
address_fields = ["street", "street2", "city", "zip", "state_id", "country_id"]
206-
if not self.env.context.get("avatax_writing") and any(
207-
x in vals for x in address_fields
208-
):
224+
has_address = any(vals.get(x) for x in ["street", "street2", "city", "zip"])
225+
if has_address and not self.env.context.get("avatax_writing"):
209226
partner = self.with_context(avatax_writing=True)
210227
avatax_config = self.env.company.get_avatax_config_company()
211228
if avatax_config.validation_on_save:

0 commit comments

Comments
 (0)