【问题标题】:XML-RPC read by external id外部 id 读取的 XML-RPC
【发布时间】:2015-05-18 03:17:40
【问题描述】:

我在这里有一个场景,我需要使用 xml-rpc 通过外部 id 从 openerp/odoo 读取/检索元素。我使用的技术是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 读取的 odoo 中数据的特定外部 id。

【问题讨论】:

  • 我的预期输出是能够通过外部 id 读取/检索 odoo 数据。

标签: php xml-rpc odoo


【解决方案1】:

在odoo中ir_model_data是存储外部ID的模型,模型连同它的数据库ID。

搜索结果中获取记录ID后,尝试从ir_model_data搜索外部ID,您可以读取该记录以获取数据库ID的记录。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-19
    • 2014-06-14
    • 1970-01-01
    • 1970-01-01
    • 2023-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多