In previous blog i have discussed about the xml-rpc connection using PHP.
now i am going to discuss about read, write and search methods.
Read Method
$dbname = 'dbname'; $user = 'admin'; $pwd = 'pwd'; // it's a demo openerp server url $url = 'http://demo.openerp.com:8069'; $sock = new xmlrpc_client("http://demo.openerp.com:8069/xmlrpc/common"); $client = new xmlrpc_client("http://demo.openerp.com:8069/xmlrpc/object"); // for $user_id we have already done in previous blog... $partner_id = 1; $id_list[0]= new xmlrpcval($partner_id, 'int'); $key = array(new xmlrpcval('name', 'string')); $msg = new xmlrpcmsg('execute'); $msg->addParam(new xmlrpcval($dbname, "string")); $msg->addParam(new xmlrpcval($user_id, "int")); $msg->addParam(new xmlrpcval($pwd, "string")); $msg->addParam(new xmlrpcval("res.partner", "string")); $msg->addParam(new xmlrpcval("read", "string")); $msg->addParam(new xmlrpcval($id_list, "struct")); // sending id which is to be read $msg->addParam(new xmlrpcval($key, "struct")); // sending an array of field $resp = $client->send($msg); $val = $resp->value(); $ids = $val->scalarval(); $id = $ids[0]->me; // here we get the customer name $customer_name = $id["struct"]["name"]->me["string"];
Search Method
$key = array(new xmlrpcval (array(new xmlrpcval('name' , "string"), // field name new xmlrpcval('=',"string"), // operator new xmlrpcval('your company',"string")),"array" ), ); $msg = new xmlrpcmsg('execute'); $msg->addParam(new xmlrpcval($dbname, "string")); $msg->addParam(new xmlrpcval($user_id, "int")); $msg->addParam(new xmlrpcval($pwd, "string")); $msg->addParam(new xmlrpcval('res.partner', "string")); $msg->addParam(new xmlrpcval("search", "string")); $msg->addParam(new xmlrpcval($key, "array")); $resp = $client->send($msg); $val = $resp->value(); $ids = $val->scalarval(); // here we will get the return ids
Write Method
$id_list[0]= new xmlrpcval($partner_id, 'int');// array of openerp customer id $customer_data = array( 'name'=>new xmlrpcval('Openerp customer', "string"), 'email'=>new xmlrpcval('[email protected]', "string") ); $msg = new xmlrpcmsg('execute'); $msg->addParam(new xmlrpcval($dbname, "string")); $msg->addParam(new xmlrpcval($user_id, "int")); $msg->addParam(new xmlrpcval($pwd, "string")); $msg->addParam(new xmlrpcval('res.partner', "string")); $msg->addParam(new xmlrpcval("write", "string")); $msg->addParam(new xmlrpcval($id_list, "array")); $msg->addParam(new xmlrpcval($customer_data, "struct")); $resp = $client->send($msg); $val = $resp->value(); $record = $val->scalarval();
$domain_filter = array ( new xmlrpcval(
array(
array(new xmlrpcval(‘is_company’ , “string”),
new xmlrpcval(‘!=’,”string”),
new xmlrpcval(‘True’,”string”)
),
array(new xmlrpcval(‘name’ , “string”),
new xmlrpcval(‘ilike’,”string”),
new xmlrpcval(‘X’,”string”)
)),”array”
),
);