@@ -156,6 +156,25 @@ def get_valid_address_vals(self, validation_on_save=False):
156
156
)
157
157
return valid_address
158
158
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
+
159
178
def multi_address_validation (self , validation_on_save = False ):
160
179
for partner in self :
161
180
if not (partner .parent_id and partner .type == "contact" ):
@@ -202,10 +221,8 @@ def create(self, vals_list):
202
221
203
222
def write (self , vals ):
204
223
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" ):
209
226
partner = self .with_context (avatax_writing = True )
210
227
avatax_config = self .env .company .get_avatax_config_company ()
211
228
if avatax_config .validation_on_save :
0 commit comments