如何解决Odoo9 Web 服务 API 更新记录“写入”PHP
我们有 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 举报,一经查实,本站将立刻删除。