Source code for odoo_xmlrpc_twisted.support.support_create_user

"""
Supporting program to test the module :func:`odoo_xmlrpc_twisted.functions.create_user`.
"""


import sys
import os

# Add functions directory to path for importing custom modules
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'functions'))
from create_user import create_user
from get_settings_odoo import get_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] def support_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 """ if custom_name != '': # find the user in the table 'res.users' with the login = custom_login res_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'. if list(res_users_id): for key, value in list(res_users_id[0].items()): if key == "id": custom_user_id = value if key == "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)