This question has been flagged
6 Replies
11516 Views

Gi,

I need to create a Blue Color T-shirt using webservice (RPC)

I can create the product,_template(T-shirt), the product_attribute_line (Color) the product_attribute_value (Blue).

But I can't create the Blue-color-TShirt. I can't update the field  product_attribute_line.value_ids. I've tried to set it during the creation of a product_attribute_line record or after using a write method. Both didn't work. 

What is the correct way to create the product variant using RPC in Odoo v9 ?

Avatar
Discard
Best Answer

i updated the  product.attribute.line  [in php ripcode[ this way:

$existing_prodid = 59;
$existing_attribute_id = 2;
$existing_value_id = 4; 
$product_attribute_line = $models->execute($db, $uid, $password,
'product.attribute.line','create',
array('product_tmpl_id' => $existing_prodid,
'attribute_id'=>$existing_attribute_id,
'value_ids'=>array(array(6,0,array($existing_value_id)))))


In  python [using  xmlrpclib ]:


attibute_line = models.execute_kw(dbname, uid, password,

'product.attribute.line', 'create',[{

'product_tmpl_id':59,'attribute_id':2,'value_ids':[(6,0,[4])]}] )

 hope this may help you.

Avatar
Discard
Author

Thank you very much Sharma. Indeed it helps. But I can't figure out what is the structure of value_ids ? How did you find it ? Or where shall I search to find the answer. Cause same problem may happened again for other objects that I would lilke to create

Author

To be more accurate on my comment, I don't understand the constant: 6 and 0 in the value_ids. Also, please note that I was able to create my product variant thanks to your : 6,0,array($existing_value_id). So I will marked the question as answered. But I will really appreciate if you can guide on how to not get stuck in this situation. Shall I start by looking at the python method triggered by the call of /web/dataset/call_kw ?

i have used (6,0,[ids]),it's the syntax of creating many2many try this link http://stackoverflow.com/questions/31853402/filling-many2many-field-odoo-8 and https://www.odoo.com/documentation/8.0/reference/orm.html

here is my explanation http://stackoverflow.com/questions/36643092/create-a-record-into-many2many-table-using-web-service-api-in-odoo-8/36709180#36709180

Best Answer

Hi, I'm creating attribute lines with the following params: 

{ product_tmpl_id: 75, attribute_id: 13, value_ids: [(6,0,[199])] }

The attribute line has been created but the value_ids field is empty:

{ create_uid: [ 1, 'Administrator' ],    create_date: '2017-03-22 12:21:23',    __last_update: '2017-03-22 12:22:54',    value_ids: [],    write_uid: [ 1, 'Administrator' ],    product_tmpl_id: [ 75, 'todojunto' ],    attribute_id: [ 13, 'Talla' ],    write_date: '2017-03-22 12:22:54',    display_name: 'Talla',    id: 84 }

I don't know what I'm doing wrong... Any solution?


SOLVED!

The right structure is:

value_ids: [[6, 0,[191,201]]]
Avatar
Discard