我有一个场景在这里,我需要读取/检索元素从openerp/odoo使用xml-rpc外部id。我使用的技术是php。下面是我从odoo读取/检索数据的代码函数:
public function read($ids, $fields, $model_name, $context=array() ) {
$client = new xmlrpc_client($this->server."object");
// ['execute','userid','password','module.name',{values....}]
$client->return_type = 'phpvals';
$id_val = array();
$count = 0;
foreach ($ids as $id)
$id_val[$count++] = new xmlrpcval($id, "int");
$fields_val = array();
$count = 0;
foreach ($fields as $field)
$fields_val[$count++] = new xmlrpcval($field, "string");
$msg = new xmlrpcmsg('execute');
$msg->addParam(new xmlrpcval($this->database, "string")); //* database name */
$msg->addParam(new xmlrpcval($this->uid, "int")); /* useid */
$msg->addParam(new xmlrpcval($this->password, "string"));/** password */
$msg->addParam(new xmlrpcval($model_name, "string"));/** model name where operation will be held * */
$msg->addParam(new xmlrpcval("read", "string"));/** method which u like to execute */
$msg->addParam(new xmlrpcval($id_val, "array"));/** ids of record which to be updated...This array must be xmlrpcval array */
$msg->addParam(new xmlrpcval($fields_val, "array"));/** parameters of the methods with values....*/
//values added
$ctx = array();
foreach($context as $k=>$v){
$ctx[$k] = new xmlrpcval( xmlrpc_get_type($v) );
}
//end
if(!empty($context)){
// $msg->addParam(new xmlrpcval(array("lang" => new xmlrpcval("nl_NL", "string"),'pricelist'=>new xmlrpcval($context['pricelist'], xmlrpc_get_type($context['pricelist']) )) , "struct"));
}
$resp = $client->send($msg);
print_r($resp);
if ($resp->faultCode())
return -1; /* if the record is not writable or not existing the ids or not having permissions*/
else
return $resp->value();
}
它只给出了id和名称在我这边没有给我odoo中数据的特定外部id我试图从odoo中读取
在odoo中ir_model_data是存储外部id,模型及其数据库id的模型。
尝试从ir_model_data获取记录id后,从搜索结果,您可以读取该记录以获得该记录的数据库id