Community mailing list archives

community@mail.odoo.com

Re: Full API Spec / Exmaples?

by
Anders Wallenquist
- 03/31/2015 08:22:32

On 2015-03-31 12:49, Mark Benson wrote:
> Hi,
>
> I am examining the Odoo API to determine how easy or hard it will be 
> to integrate wit our website ordering system (many years in the making 
> and honed specifically to our client needs). I am a competent and 
> experienced developer but I find the API section of the documentation 
> woefully inadequate for working out how to interface with the API. 
> Also I am not able to find the database specs for Odoo so I actually 
> know what to ask for.
>
> Are there any better, more comprehensive documents for this? Do I need 
> to read the whole developer doc set, just to understand the API (I am 
> not writing stuff to fit inside Odoo, so a lot of that would be 
> redundant??)

This is the general documentation

https://www.odoo.com/documentation/8.0/

This is the specifics for webservice-api

https://www.odoo.com/documentation/8.0/api_integration.html

There are examples for several languages, but all languages that have 
XMLRPC will do.

It helps to understand Odoo ORM-implemenation (common API for python and 
webservice)

https://www.odoo.com/documentation/8.0/reference/orm.html#common-orm-methods

Usually you need to use the search, read, create, write and other 
methods interacting with your classes.
You can extend any class with your own methods if it makes the 
integration more easy.

You have all installed classes in a searchable view within your 
Odoo-installation.
Activate Technical Features for a user and use the menu Settings / 
Technical / Database  / Models to browse your installation.


If you dont want to use the Odoo API there are some other nice 
libraries, for example oerplib

aw@maggie:~$ sudo pip install oerplib

#!/usr/bin/python

import  oerplib

# Prepare the connection to the server
oerp  =  oerplib.OERP('localhost',  protocol='xmlrpc',  port=8069)

# Check available databases
print(oerp.db.list())

# Login (the object returned is a browsable record)
user  =  oerp.login('user',  'passwd',  'db_name')
print(user.name)             # name of the user connected
print(user.company_id.name)  # the name of its company

# Simple 'raw' query
user_data  =  oerp.execute('res.users',  'read',  [user.id])
print(user_data)

# Use all methods of an OSV class
order_obj  =  oerp.get('sale.order')
order_ids  =  order_obj.search([])
for  order  in  order_obj.browse(order_ids):
     print(order.name)
     products  =  [line.product_id.name  for  line  in  order.order_line]
     print(products)

# Update data through a browsable record
user.name  =  "Brian Jones"
oerp.write_record(user)

https://github.com/osiell/oerplib/blob/master/examples/example.py

Regards,
Anders Wallenquist
Vertel AB
>
> It seems very unfortunate for an Open Source project to have no clear, 
> comprehensive API docs.
>
> Also, if anyone replies to offer services we are open top using UK 
> companies ONLY, thanks.
>
> -- 
>
> Mark Benson
>
> _______________________________________________
> Mailing-List: https://www.odoo.com/groups/community-59
> Post to: mailto:community@mail.odoo.com
> Unsubscribe: https://www.odoo.com/groups?unsubscribe
>