0

I have a scenario here in which I need to read/retrieve elements from openerp/odoo by external id using xml-rpc. The technology which I am using is php. Here is my code function of the read/retrieve of data from 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();

}

It comes to give just the id and the name which in my side doesn't give me the specific external id of the data in odoo which I attempted to read from odoo.

John Conde
  • 217,595
  • 99
  • 455
  • 496

1 Answers1

0

In odoo ir_model_data is the model which stores the external id, model along with it's database ID.

try to search the external id from ir_model_data after getting the record id from search result you can read that record to get the database id of that record.

Atul Arvind
  • 16,054
  • 6
  • 50
  • 58