问题描述
我们有 odoo9 实例,其中每个电话号码都是唯一的记录 - [field_name = 'phone']。
我正在尝试查找找到 (ex. $phone = '8009999999') $phone 或 ('1' . $phone) 的任何记录。如果找到更新记录 > 否则创建新记录。
到目前为止,我能够获得新记录
execute_kw($dbname,$uid,$password,'res.partner','create',array(array($arraymerge)));
上班。
//Converts to Array
$i =0;
$arraymerge = array();
foreach($merge_vars as $mergefield) {
$arraymerge = array_merge($arraymerge,array( $mergefield['name'] => $mergefield['value'] ) );
$i++;
}
if(substr($url,-1) !='/') $url.='/'; //adds slash to url
$uid = odoo9_login($username,$dbname,$url);
if($uid != false) {
$models = ripcord::client($url.'xmlrpc/2/object');
// (_) method to lookup contact | looks up id by phone number then saves contact var
$phone = $arraymerge['phone'];
$contact = $models->execute_kw(
$dbname,'search_read',array(
array(
array('phone','=',$phone)
),array('fields'=>array('id','phone')),// replace to get phone and id field
NULL,NULL,'id'
)
);
//check again fo contact with leading '1' in phone
$phone_1 = '1' . $arraymerge['phone'];
$contact_1 = $models->execute_kw(
$dbname,'id'
)
);
// if cannot find existing phone contact or phone contact w/ leading 1 > create new | else check which found and update
if(empty($contact) && empty($contact_1)) {
$id = $models->execute_kw($dbname,array(array($arraymerge)));
}
else {
// see if there's any contacts matching with leading '1'
$contact_arr = empty($contact_1) ? $contact : $contact_1;
// loop through all $contact->results
foreach($contact_arr as $pos) {
// if contact_position['phone'] === $arraymerge['phone'] use then break
$pos_obj = json_decode($pos,true);
if($pos_obj['phone'] == $arraymerge['phone']) {
$id = $models->execute_kw($dbname,'write',array(
array($pos_obj['id']),array($arraymerge)
)
);
break;
}
}
}
// echo('RESULT:<br/>');
// foreach ($id as $id) {
// echo $id.'<br/>';
// }
} else {
debug_email_lead('Odoo9','Error',$merge_vars);
return false;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)