Source code for odoo_xmlrpc_twisted.functions.update_user_address_values

"""
Module updates the user address values.
"""

# call the function "get_settings_odoo" to get the parameters
# for the logging of the model on the "odoo Webservice API"
try:
    from .get_settings_odoo import get_settings_odoo
except ImportError:
    from get_settings_odoo import get_settings_odoo
result   = get_settings_odoo()
db       = result[0]
uid      = result[1]
password = result[3]
models   = result[4] 



[docs] def update_user_address_values(partner_id, address_type, street, street_2, zip_code, city, state, country): """ Function updates the user address values by using the model 'res.partner'. Depending on the type, either a delivery addresse or invoice address will be updated or created if not already existing. """ result = False if partner_id != '' and address_type != '': # the parent_id is the partner_id so that the reference to the original partner record is given parent_id = partner_id # set the values for the address new_address_values = {'type': address_type, 'street': street, 'street2': street_2, 'zip': zip_code, 'city': city, 'state_id': state, 'country_id': country,} # Search for existing addresses of the partner of that type existing_address = models.execute_kw(db, uid, password, 'res.partner', 'search', [[['parent_id', '=', parent_id], ['type', '=', address_type]]],) # Update address if existing_address and existing_address[0]: # Assuming there is only one address existing_address_id = existing_address[0] models.execute_kw(db, uid, password, 'res.partner', 'write', [[existing_address_id], new_address_values]) else: # If there's no existing address, create a new one new_address_values['parent_id'] = parent_id new_address_id = models.execute_kw(db, uid, password, 'res.partner', 'create', [new_address_values]) result = True return(result)