Source code for odoo_xmlrpc_twisted.support.support_create_user
"""Supporting program to test the module :func:`odoo_xmlrpc_twisted.functions.create_user`."""importsysimportos# Add functions directory to path for importing custom modulessys.path.append(os.path.join(os.path.dirname(__file__),'..','functions'))fromcreate_userimportcreate_userfromget_settings_odooimportget_settings_odoo# Call the function "get_settings_odoo" to get the parameters# for the logging of the model on the "odoo Webservice API"result=get_settings_odoo()db=result[0]uid=result[1]password=result[3]models=result[4]
[docs]defsupport_create_user(custom_name,custom_login,custom_email,custom_password):""" Function to test the module "create_user". As a prerequisite, it will be checked if the dedicated user already exist. If yes, the user will be deleted in the tables 'res.users' and 'res.partner'. Then the function 'create_user' will be called to test if a new dedicated user could be created. Returns: tuple: (result, user_id, partner_id) where: - result: 'True' if user created successfully, 'False' otherwise - user_id: ID of the created user in res.users table - partner_id: ID of the created partner in res.partner table """ifcustom_name!='':# find the user in the table 'res.users' with the login = custom_loginres_users_id=models.execute_kw(db,uid,password,'res.users','search_read',[[['login','=',custom_login],]],{'fields':['partner_id']},)# if a user exist, then find the user and afterwards delete the user# in the tables 'res.users' and 'res.partner'.iflist(res_users_id):forkey,valueinlist(res_users_id[0].items()):ifkey=="id":custom_user_id=valueifkey=="partner_id":custom_partner_id=value[0]models.execute_kw(db,uid,password,'res.users','unlink',[[custom_user_id],])models.execute_kw(db,uid,password,'res.partner','unlink',[[custom_partner_id],])# call the function 'create_user' to see if it works# create_user now returns a tuple (result, user_id, partner_id)result,user_id,partner_id=create_user(custom_name,custom_login,custom_email,custom_password)return(result,user_id,partner_id)