1

I need to create a record in mail_vote table(many2many) with fields message_id and user_id Using Web service API. I found a document here: https://www.odoo.com/documentation/8.0/reference/orm.html#openerp.models.Model.write . But i don't know how to use that in my code. Any solution pleaseenter image description here.

KbiR
  • 4,047
  • 6
  • 37
  • 103

1 Answers1

2

Below i am posting the code snippet for associating (6,0,[ids])] the Many2many record in product.attribute.line.

In Php here i have used ripcord for this task.

$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)))
                                             ))

Here the product.attribute.line have have Many2many relation with product.attribute.value

So this is how i associated a records for value_ids ['value_ids'=>array(array(6,0,array($existing_value_id)))].

In python i have used xmlrpclib for this task.

attibute_line = models.execute_kw(dbname, uid, password,
                   'product.attribute.line', 'create',
                   [{'product_tmpl_id':59,'attribute_id':2,'value_ids':[(6,0,[4])]}] )

I hope this may help in your case

Prakash Kumar
  • 2,554
  • 2
  • 18
  • 28
  • here is my requirement. need to 'like' messages in messaging module using web service API. messages are stored in 'mail.messages' , relation keeps in 'mail.vote'. – KbiR Apr 19 '16 at 06:34
  • i tried with this: execute(dbname, uid, pwd,'mail.message', 'write',[475],{'vote_user_ids':[(0,0,[6])]}). but getting error list object has no attribute get. – KbiR Apr 19 '16 at 09:20
  • [(0,0,{})] is used for adding a record in the model and [(1,id,{})] for updating the record values for the specif id , you will have to pass the dictionary in both the cases, {'vote_user_ids':[(0,0,[6])]} is not the valid syntax , please read link care fully :http://stackoverflow.com/questions/31853402/filling-many2many-field-odoo-8 – Prakash Kumar Apr 19 '16 at 09:27
  • i tried this .execute(dbname, uid, pwd,'mail.message', 'write',[475],{'vote_user_ids':[(4,6)]}) Now getting an error The operation cannot be completed, probably due to the following: - deletion: you may be trying to delete a record while other records still reference it - creation/update: a mandatory field is not correctly set [object with reference: Users - res.users]: ''> – KbiR Apr 19 '16 at 10:29
  • i am using xmlrpc/2 here is the code for it models.execute_kw(dbname, uid, password, 'mail.message', 'write',[[475],{ 'vote_user_ids':[(4,6)]}] ) – Prakash Kumar Apr 19 '16 at 10:54
  • i tried this: execute(dbname, uid, pwd,'mail.message', 'write',[498],{'vote_user_ids':[(4,uid)]}), its successfully run and returned TRUE, but no records created in 'mail.vote' (the relation table) ????????? – KbiR Apr 19 '16 at 11:52
  • when i am trying this: sock.execute(dbname, uid, pwd,'mail.message', 'write',[[511],{'vote_user_ids':[(4,uid)]}]), got this error = Fault: <Fault unhashable type: 'list': 'Traceback – KbiR Apr 22 '16 at 09:27