getConfig(); $_SESSION['erp'] = $oERP->getConfig(); //$_SESSION['translations'] = $oTrans->listTranslations($_SESSION['config']['default_lang_code']); //$_SESSION['countries'] = $oCountry->listCountries('priority ASC, name ASC'); //$_SESSION['activeCountries'] = $oCountry->listActiveCountries('priority ASC, name ASC'); //$_SESSION['currencies'] = $oCurrency->listCurrencies('priority ASC, name ASC'); //$_SESSION['languages'] = $oLang->listLanguages(); //$_SESSION['activeLanguages'] = $oLang->listActiveLanguages(); } // Open connection with Odoo $url = $_SESSION['erp']['url']; $db = $_SESSION['erp']['db']; $username = $_SESSION['erp']['admin_user']; $password = $_SESSION['erp']['admin_password']; $common = ripcord::client($url."xmlrpc/2/common"); $uid = $common->authenticate($db, $username, $password, array()); $models = ripcord::client($url."xmlrpc/2/object"); // Step 1. Create user admin@wefra $data = array('formRegisterFieldPassword'=>'admin', 'formRegisterFieldConfirmPassword'=>'admin', 'formRegisterFieldFirstname'=>'Admin', 'formRegisterFieldLastname'=>'Wefra', 'formRegisterFieldEmail'=>'admin@wefra', 'formRegisterFieldCountry'=>44); $name = $data['formRegisterFieldFirstname'].' '.$data['formRegisterFieldLastname']; //create user in ERP $ext_id = $models->execute_kw($db, $uid, $password, 'res.users', 'create', array(array('name'=>$name, 'email'=>$data['formRegisterFieldEmail'], 'login'=>$data['formRegisterFieldEmail'], //yes, the login IS the email, there is no mistake here 'country_id'=>(integer) $models->execute_kw($db, $uid, $password, 'res.country', 'search', array(array(array('code', '=', 'CH'))))[0], 'project_task_level_id'=>(integer) $models->execute_kw($db, $uid, $password, 'project.task.level', 'search', array(array(array('name', '=', 'White Belt'))))[0] ))); echo "ext_id has value: "; print_r($ext_id); echo "

"; //if user created in ERP, then create it in Wefra with password linked if(isset($ext_id) and !is_array($ext_id)){ //create user in Wefra and link the user to ERP $user = $oUser->createUserForWefraAdmin($data, $ext_id); echo "Wefra user status: "; print_r($user); echo "

"; if($user){ //update the password for user in ERP //.. $getUser = $oUser->getUser($user['user_id']); $models->execute_kw($db, $uid, $password, 'res.users', 'write', array(array($ext_id), array('password'=>$getUser['password'], 'password_uncrypted'=>$data['formRegisterFieldPassword']))); //.. //that way, ERP rights will be checked everytime Wefra will use ORM to allow user to to actions which will have an influence in the ERP (ie. get a task which will be assigned to his ERP's user related) $message['content'] = 'Success:

User Admin Wefra has been created in globsi-admin

'; } else { echo 'Failure:

User Admin Wefra could not been created in globsi-admin

'; } //display a confirmation message that everything went well $message['content'] = 'Success:

User Admin Wefra has been created in globsi-backend

'; } else { //if user not created in ERP, displaying a warning message to ask for a new try $message['content'] = 'Failure:

User Admin Wefra could not been created in globsi-backend

'; } echo $message['content']; echo "

Session Config
"; print_r($_SESSION['config']); echo "

Session ERP
"; print_r($_SESSION['erp']);