1
votes

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?

http://imgur.com/WGLUbQo

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??

1
Did you try with [(6, 0, [ids])]? - dccdany
aah i see i did it ,and how to update the current many2many relation?? i mean what if i want to add more value to many2many relation without replacing the value because if i try using [(6,0,[ids])]? it's keep replaceing the previous value can u give some example??how to use (0,0,{}) - dmh
You can just pass the ID and 4: [(4, ID)] - dccdany
no luck still not updated my product variant, I'm using this code to update the list models.execute_kw(db, uid, password, 'product.attribute.line', 'write',[[7],{'value_ids':(4,idValue)}]) - dmh
Remember to put [ ],. [(4, ID)] - dccdany

1 Answers

1
votes

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.