This question has been flagged
1 Reply
6585 Views
  • Search

/**
 * $client = xml-rpc handler
 * $relation = name of the relation ex: res.partner
 * $attribute = name of the attribute ex:code
 * $operator = search term operator ex: ilike, =, !=
 * $key=search for
 */

function search($client,$relation,$attribute,$operator,$keys) {
     var $user = 'admin';
     var $password = 'admin';
     var $userId = -1;
     var $dbname = 'db_name';
     var $server_url = 'http://localhost:8069/xmlrpc/';

     $key = array(new xmlrpcval(array(new xmlrpcval($attribute , "string"),
              new xmlrpcval($operator,"string"),
              new xmlrpcval($keys,"string")),"array"),
        );

     if($userId<=0) {
     connect();
     }

     $msg = new xmlrpcmsg('execute');
     $msg->addParam(new xmlrpcval($dbname, "string"));
     $msg->addParam(new xmlrpcval($userId, "int"));
     $msg->addParam(new xmlrpcval($password, "string"));
     $msg->addParam(new xmlrpcval($relation, "string"));
     $msg->addParam(new xmlrpcval("search", "string"));
     $msg->addParam(new xmlrpcval($key, "array"));

     $resp = $client->send($msg);
     $val = $resp->value();
     $ids = $val->scalarval();

     return $ids;
}

In this fucntion what is the  " client = xml-rpc handler" here what is the xml rpc handler for serach method?i want to know what is xml rpc handler?

Avatar
Discard
Best Answer

$url = <insert server URL>;

$db = <insert database name>;

$username = "admin";

$password = <insert password for your admin user (default: admin)>;

$common = ripcord::client("$url/xmlrpc/2/common");

$common->version();

{

"server_version": "8.0",

"server_version_info": [8, 0, 0, "final", 0],

"server_serie": "8.0",

"protocol_version": 1,

}

$models->execute_kw($db, $uid, $password, 'res.partner', 'search', array( array(array('is_company', '=', true), array('customer', '=', true))));

Calling methods

The second endpoint is xmlrpc/2/object, is used to call methods of odoo models via the execute_kw RPC function.Each call to execute_kw takes the following parameters:

the database to use, a string

the user id (retrieved through authenticate), an integer

the user's password, a string

the model name, a string

the method name, a string

an array/list of parameters passed by position

a mapping/dict of parameters to pass by keyword (optional)

List records

Records can be listed and filtered via search().search() takes a mandatory domain filter (possibly empty), and returns the database identifiers of all records matching the filter. To list customer companies for instance:

Pagination

By default a search will return the ids of all records matching the condition, which may be a huge number. offset and limit parameters are available to only retrieve a subset of all matched records.


Avatar
Discard