Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Odoo Web Services

3,068 views

Published on

Web services are a set of tools available over the internet or intranet networks which use the standardized messaging system to transfer data between applications or systems.
Web services allow interaction between different systems or applications using standard libraries such as HTML, XML, WSDL, and SOAP.

Published in: Business
  • Be the first to comment

  • Be the first to like this

Odoo Web Services

  1. 1. www.cybrosys.com Odoo Web Services
  2. 2. INTRODUCTION • Web services are a set of tools available over the internet or intranet networks which use the standardized messaging system to transfer data between applications or systems. • Web services allow interaction between different systems or applications using standard libraries such as HTML, XML, WSDL, and SOAP. • Web services are not limited to a single programming language. • Odoo web services can be of two types –> XML-RPC and JSON-RPC
  3. 3. XML-RPC • XML-RPC allows to connect programs running on different programming languages and systems working on different operating systems. • XML-RPC can be used with programming languages like Python, Java, C, C++, PHP, Perl, Ruby, .Net etc. • Discussing how to use xml-rpc in Python
  4. 4. Connecting With Database • To connect with an Odoo database we have to define URL of Odoo server, a name of the database used, username and password. • A simple way to check whether authentication is correct or not is to check the version of Odoo running. • If authentication is correct we will need the user id to access data. • It can be read using “uid = common. Authenticate (dB, user, pwd, {})”
  5. 5. Example: To connect to a local host and read the version of Odoo service running
  6. 6. Reading Records Records of a model can be read using the search function. First, we need to define a model. models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url)) To search for record in a model, models.execute_kw(db, uid, pwd,'model.name','search',[[[any_domain]]]) Here domain is a mandatory field. You should keep it empty(like this [[[]]] ) if no domain is required. Also, we can keep limit for the number of records we need to get using limit.
  7. 7. Example: Print ids of 3 records from model account. Invoice with origin field equals false
  8. 8. Note: To read or write a record the logged user should have permission for read and write respectively To get count we can use search_count instead of search for getting the number of records in our search. To read a record we can use read instead of search and we need to define all fields in model which we need. models.execute_kw(db, uid, pwd,'model.name','read',[ids],{'fields':['field_1', 'field_2']}) we can also use search_read which is equalant to search followed by read models.execute_kw(db, uid, pwd,'model.name','search_read',[[[domain]]],{'fields':['field_1', 'field_2']})
  9. 9. Example: Print name and state of all invoices against customer agrolait
  10. 10. Managing Records To create, update or unlink a record we can use create(), write(), and unlink() respectively models.execute_kw(db, uid, pwd, 'model.name','create', [{'field_name':'field_value'}]) models.execute_kw(db, uid, pwd, 'model.name', 'write', [[id]],[{'field_name':'field_value'}]) models.execute_kw(db, uid, pwd,'model.name','unlink',[[id]])
  11. 11. Example: Create a customer named “test user”, update his name to “User 23”. And finally delete his record. Note : When creating records of a model we might want to define all required fields(if they are not given by default in Odoo). In the above example, we need to define login for the user.
  12. 12. Json-RPC Similar to XML-RPC we can interact with Odoo server using Json-RPC. General working is to establish a connection between two peers. During connection, a peer may invoke methods from other by sending the request. And receiver will reply with a response.
  13. 13. In Odoo Json-RPC can be implemented using standard python libraries(like json, random, urllib2) or using package jsonrpclib. To connect with Odoo server using jsonrpclib we can use url = “host url with port” server = jsonrpclib.Server(url)
  14. 14. Refer this link for more: https://www.cybrosys.com/blog/odoo-web-services
  15. 15. Thank You ! Cybrosys Technologies Pvt. Ltd. Neospace, Kinfra Techno Park, Kakkancherry, Calicut University P.O. Calicut Kerala, India - 673635. Cybrosys Ltd 15, ST Antonys Road, Forest Gate, London England, E79QA. Cybrosys Technologies Pvt. Ltd. 1st Floor, Thapasya Building, Infopark, Kakkanad, Kochi, Kerala, India-682030.

×