Posted By

JustGreg on 07/29/09


Tagged

xml-rpc OpenERP


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

wnasich


OpenERP: XML-RPC Web services (CRUD Example)


 / Published in: Python
 

URL: http://doc.openerp.com/developer/6_22_XML-RPC_web_services/

  1. """
  2. :The login function is under
  3. :: http://localhost:8069/xmlrpc/common
  4. :For object retrieval use:
  5. :: http://localhost:8069/xmlrpc/object
  6. """
  7. import xmlrpclib
  8.  
  9. user = 'admin'
  10. pwd = 'admin'
  11. dbname = 'terp3'
  12. model = 'res.partner'
  13.  
  14. sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/common')
  15. uid = sock.login(dbname ,user ,pwd)
  16.  
  17. sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/object')
  18.  
  19. # CREATE A PARTNER
  20. partner_data = {'name':'Tiny', 'active':True, 'vat':'ZZZZZ'}
  21. partner_id = sock.execute(dbname, uid, pwd, model, 'create', partner_data)
  22.  
  23. # The relation between res.partner and res.partner.category is of type many2many
  24. # To add categories to a partner use the following format:
  25. partner_data = {'name':'Provider2', 'category_id': [(6,0,[3, 2, 1])]}
  26. # Where [3, 2, 1] are id fields of lines in res.partner.category
  27.  
  28. # SEARCH PARTNERS
  29. args = [('vat', '=', 'ZZZZZ'),]
  30. ids = sock.execute(dbname, uid, pwd, model, 'search', args)
  31.  
  32. # READ PARTNER DATA
  33. fields = ['name', 'active', 'vat', 'ref']
  34. results = sock.execute(dbname, uid, pwd, model, 'read', ids, fields)
  35. print results
  36.  
  37. # EDIT PARTNER DATA
  38. values = {'vat':'ZZ1ZZ'}
  39. results = sock.execute(dbname, uid, pwd, model, 'write', ids, values)
  40.  
  41. # DELETE PARTNER DATA
  42. results = sock.execute(dbname, uid, pwd, model, 'unlink', ids)

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: grizzlysmit on May 13, 2011

could some one tell me how to use xmlrpclib to add a user to a group also how to add partners to a category the above code snippet makes a reference to this but it is not clear what the 6 and the 0 are in the code snippet i.e

partnerdata = {'name':'Provider2', 'categoryid': [(6,0,[3, 2, 1])]}

Where [3, 2, 1] are id fields of lines in res.partner.category

Posted By: grizzlysmit on May 13, 2011

could some one tell me how to use xmlrpclib to add a user to a group also how to add partners to a category the above code snippet makes a reference to this but it is not clear what the 6 and the 0 are in the code snippet i.e

partnerdata = {'name':'Provider2', 'categoryid': [(6,0,[3, 2, 1])]}

Where [3, 2, 1] are id fields of lines in res.partner.category

Posted By: grizzlysmit on May 13, 2011

sorry about the duplicate refreshed page

You need to login to post a comment.