Ondřej Severa
Ondřej Severa

Reputation: 379

Set many2many property via PHP XML-RPC

I am trying to create a new customer via XML-RPC. I followed the tutorial here

https://www.odoo.com/documentation/8.0/api_integration.html

I am able to create new res.Partner and fill all the contact information. I failed with setting the Tags (category_id).

$resp = $models->execute_kw($db, $uid, $password, 'res.partner', 'write',
    array(array($userID), 
        array('category_id'=>array(4,array($tagID),0))
        ));

The question is how to set many2many relation using PHP and XML-RPC? I am aware of the API here

https://www.odoo.com/documentation/8.0/reference/orm.html#openerp.models.Model.write

but there is no description how to call it from PHP.

Upvotes: 1

Views: 736

Answers (1)

Daniel Schulz
Daniel Schulz

Reputation: 36

I had the same problem, but was finally able to solve this question. I tried to create a new partner via a XML-RPC request and assign certain tags to the Partner and I came up with the following:

$category_id = array();
$category_id[] = new xmlrpcval(6, "int");
$category_id[] = new xmlrpcval(0, "int");   

$cat_id = array();
$cat_id[] = new xmlrpcval(1, "int");
$cat_id[] = new xmlrpcval(4, "int");

$category_id[] = new xmlrpcval($cat_id, "array");

"category_id"   => new xmlrpcval(array(new xmlrpcval($category_id, "array")), "array")

Then you can finally send the request and the tags are assigned.

Upvotes: 2

Related Questions