Sie sind auf Seite 1von 2

External API XML-RPC

1.Odoo Configuration and Connection


Provide server URL,DB name,odoo User Name, password
import xmlrpc.client
url="http://localhost:8069"
db ="odoo12"
username ="murugan.mu@gmail.com"
password="9677@balamurugan"
2.Find the server version , Authentication and return user identifier
common=xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url))
print(common.version())
uid=common.authenticate(db,username,password,{})
print("user identifier=",uid)
output: {'server_version': '12.0-20190806', 'server_version_info': [12, 0, 0, 'final', 0, ''],
'server_serie': '12.0', 'protocol_version': 1}
output: user identifier= 2
3.Call the methods of odoo model using execute_kw RPC function, if model is not
existing return false, otherwise read the particular model
models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url))
print("Method Calling:",models.execute_kw(db, uid, password,'res.partner',
'check_access_rights',['read'], {'raise_exception': False}))
output: Method Calling: True
4.List out the particular model records using search()
print("List of records=",models.execute_kw(db, uid, password,'res.partner',
'search',[[['is_company', '=', True], ['customer', '=', True]]]))
where , ‘res.partner'Model name
'is_company'Field Name
Output: List of records= [14, 10, 11, 15, 13]
5.Count Total Records using search_count()
print("Total record Count=",models.execute_kw(db, uid, password,'res.partner',
'search_count',[[['is_company', '=', True], ['customer', '=', True]]]))
output: Total record Count= 5
6.Read the records using read() and search() method
ids = models.execute_kw(db, uid, password,'res.partner', 'search',[[['is_company', '=', True],
['customer', '=', True]]],{'limit': 1})
[record] = models.execute_kw(db, uid, password,'res.partner', 'read', [ids])
# count the number of fields fetched by default
print("read records",len(record))
Output: read records 96
7.Getting specific field of records ,List out the records based on attributes
print("Specific Field
Records",models.execute_kw(db,uid,password,'res.partner','read',[ids],{'fields':['category_id','
name','create_date']}))
print("Listing Record Fields",models.execute_kw(db, uid, password, 'res.partner',
'fields_get',[], {'attributes': ['string', 'help', 'type']}))
Output:Specific Field Records [{'id': 14, 'category_id': [5], 'name': 'Azure Interior',
'create_date': '2019-08-07 04:40:33'}]
Listing Record Fields
{'name': {'type': 'char', 'string': 'Name'},
'display_name': {'type': 'char', 'string': 'Display Name'},
'date': {'type': 'date', 'string': 'Date'},
'title': {'type': 'many2one', 'string': 'Title'},
'parent_id': {'type': 'many2one', 'string': 'Related Company'},
'parent_name': {'type': 'char', 'string': 'Parent name'},
'child_ids': {'type': 'one2many', 'string': 'Contacts'},
'ref': {'type': 'char', 'string': 'Internal Reference'},
'lang': {'type': 'selection', 'help': 'All the emails and documents sent to this contact will be
translated in this language.', 'string': 'Language'}}