Source code for odoo_xmlrpc_twisted.functions.create_user

"""
Create a new user in Odoo for a customer.
"""


# 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]
odoo_password = result[3]
models       = result[4]


import os
import configparser


# ------- get all parameter from the file "parameter_user.ini" -------

# Name and full path of the settings file
filename  = "parameter_user.ini"
path_name = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))  # Go up to repo root
config_path = os.path.join(path_name, 'config')
fullpath  = os.path.join(config_path, filename)

config = configparser.ConfigParser()
config.read(fullpath)


# Value for lang = Default value
custom_lang = config.get('create_user', 'lang')

# Value for country_id = Default value
custom_country_id = int(config.get('create_user', 'country_id'))

# Value for company_id = Default value
custom_company_id = int(config.get('create_user', 'company_id'))

# Value for default Payment Condition
custom_payment_term_id = int(config.get('create_user', 'payment_term_id'))

# Value for default Category
custom_category_id = int(config.get('create_user', 'category_id'))

# Value for Account Receivable
custom_account_receivable_id = int(config.get('create_user', 'account_receivable_id'))

# Value for Account Payable
custom_account_payable_id = int(config.get('create_user', 'account_payable_id'))

# Value for User is an inactive user
custom_user_active = int(config.get('create_user', 'user_active'))

# Value for the Portal User
custom_user_share = int(config.get('create_user', 'user_share'))

# Value for Partner is an active Partner
custom_partner_active = int(config.get('create_user', 'partner_active'))


# ------- end of the initialisation ------- 

    
[docs] def create_user(name, login, email, password): """ Function creates a "res.users" record to store in the odoo ERP system database. Together with the user record a corresponding "res_partner" record is created. The user will be created as a "Portal User" ("share" = "True"). Returns: tuple: (result, user_id, partner_id) where: - result (str): 'True' if successful, 'False' if failed - user_id (int or None): ID of created user, None if failed - partner_id (int or None): ID of created partner, None if failed """ result = 'False' user_id = None partner_id = None if name != '': try: # first a new partner record will be created in the odoo table "res.partner" custom_partner_id = models.execute_kw(db,uid, odoo_password,'res.partner', 'create', [{'active': custom_partner_active, 'lang': custom_lang, 'name': name, 'email': email, 'property_payment_term_id': custom_payment_term_id, 'country_id': custom_country_id,}]) partner_id = custom_partner_id # Store partner_id for return # create the relationship in the table "res_partner_res_partner_category_rel" # so that the customer gets the category "Transfer Order Customers" models.execute_kw(db,uid, odoo_password, 'res.partner.category', 'write', [[custom_category_id], {'partner_ids': [(4, custom_partner_id)],}]) # than a new user record in the odoo table "res.users" will be created custom_user_id = models.execute_kw(db,uid, odoo_password,'res.users', 'create', [{'company_id' : custom_company_id, 'lang' : custom_lang, 'login' : login, 'name' : name, 'partner_id' : custom_partner_id, 'property_account_receivable_id' : custom_account_receivable_id, 'property_account_payable_id' : custom_account_payable_id, 'password' : password, 'x_activate_complete' : False, # default value, user must be activated in a separate step }]) user_id = custom_user_id # Store user_id for return # update the "res.users" record to set the user as a portal user models.execute_kw(db,uid, odoo_password, 'res.users', 'write', [[custom_user_id], {'share': custom_user_share, # True = shared user 'sel_groups_1_10_11': 10, # 10 = portal user }]) result = 'True' except: result = 'False' else: result = 'False' return(result, user_id, partner_id)