I need help with XMLRPC , I'm using python , i'm trying to create product variant and i need to assign value to field many2many , here's my code
idProductLineAttributeLine =
models.execute_kw(db,uid,password,'product.attribute.line','create',
[{'product_tmpl_id':idProduct,'attribute_id':idAttr,'value_ids': (6,0,
[idValue])}])
if i'm assign normal field everythings work fine but when it comes to many2many field or one2many field its show arrow like this
in __dump\nTypeError: cannot marshal <type 'builtin_function_or_method'> objects\n", "message": "cannot marshal <type 'builtin_function_or_method'> objects", "name": "exceptions.TypeError", "arguments": ["cannot marshal <type 'builtin_function_or_method'> objects"]}}}
what did i do wrong? please help me :) , thank's in advanced
In the book odoo essential its said i must use this one too assign many2many value or one2many value but still no luck
(0,_ ,{' field': value}): This creates a new record and links it to this one
(1, id,{' field': value}): This updates values on an already linked record
(2, id,_): This unlinks and deletes a related record
(3, id,_): This unlinks but does not delete a related record
(4, id,_): This links an already existing record
(5,_,_): This unlinks but does not delete all linked records
(6,_,[ ids]): This replaces the list of linked records with the provided list
updated I manage to solve this problem by adding [] thx to dccdany for pointing this out :), and the product variant added to product
models.execute_kw(db,uid,password,'product.attribute.line','create', [{'product_tmpl_id':idProduct,'attribute_id':idAttr,'value_ids': (6,0, [idValue])}])
, but the the product variant does not auto generate , i still need to manually refresh the product by editing and saved any idea why?
as seen in the screenshot there's 4 product variant but the status near top right only said 3 variant did i miss something here??
In above code you are just adding new product.attribute.line.Technically odoo will create new attribute line but when product template write method will call at that time system will call method create_variant_ids and create new variants.
Following is the simplest way to create or update variants.
models.execute_kw(db,uid,password,'product.attribute.line','create', [{'product_tmpl_id':idProduct,'attribute_id':idAttr,'value_ids': (6,0, [idValue])}])
models.execute_kw(db,uid,password,'product.template','write',{'active':True})
When you call product template write method system will call method of create_variant_ids.
This may help you.