OpenERP: XML-RPC Web services (CRUD Example)


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  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)

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.