+ All Categories
Home > Business > Odoo Web Services

Odoo Web Services

Date post: 24-Jan-2018
Category:
Upload: celine-george
View: 1,273 times
Download: 0 times
Share this document with a friend
15
www.cybrosys.com Odoo Web Services
Transcript
Page 2: Odoo Web Services

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

Page 3: Odoo Web Services

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

Page 4: Odoo Web Services

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, {})”

Page 5: Odoo Web Services

Example: To connect to a local host and read the version of Odoo service running

Page 6: Odoo Web Services

Reading RecordsRecords 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.

Page 7: Odoo Web Services

Example: Print ids of 3 records from model account. Invoice with origin field equals

false

Page 8: Odoo Web Services

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']})

Page 9: Odoo Web Services

Example: Print name and state of all invoices against customer agrolait

Page 10: Odoo Web Services

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

Page 11: Odoo Web Services

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.

Page 12: Odoo Web Services

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.

Page 13: Odoo Web Services

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 useurl = “host url with port”server = jsonrpclib.Server(url)

Page 14: Odoo Web Services

Refer this link for more:

https://www.cybrosys.com/blog/odoo-web-services

Page 15: Odoo Web Services

Thank You !

Cybrosys Technologies Pvt. Ltd.Neospace, Kinfra Techno Park,Kakkancherry,Calicut University P.O.CalicutKerala, India - 673635.

Cybrosys Ltd15, ST Antonys Road,Forest Gate, LondonEngland,E79QA.

Cybrosys Technologies Pvt. Ltd.1st Floor, Thapasya Building,Infopark, Kakkanad,Kochi, Kerala,India-682030.


Recommended