Odoo Help


Tutorial that explains interaction with the OpenERP ORM?

P Mittal
on 5/23/13, 4:08 PM 4,214 views

I am in process of writing OpenERP modules and want to learn how:

(1) To be able to create model objects

(2) Store data or records in them via an API.

(3) Query them to retrieve data. (Just like we do in Django Models using the Queryset API)

Where can I get a good tutorial that explains the above 3 cases with all the available methods? Also, I want to interact with the ORM with the help of easy to use Python API's without using XML-RPC's as much as possible.



| 5 4 7
Baarn, Netherlands
On 5/31/13, 7:01 PM

Regarding (1): when you do a search for 'openerp create module', there are various sites (including youtube) which show and help you to create a new module. Although many of them say it is for V6 or V6.1, it also works for V7.

Regarding (2): What do you mean by this question?

Regarding (3): within the module, you can use API-like things like

model_id = model.search([('fieldname', '=', some_value')])

if there is no result, model_id will be [], otherwise [<id>]

It is not clear to me what you mean by the last sentence, but I think you want to use the openERP ORM, from script(s), without logging in into openERP. In that case, I use openerplib, a module you can install 'openerplib'. This allows you to hide the XML-RPC like code, to get some nicer looking code. Next week I can post how to install this library and an example, how to make a script using this library.

#openerplib I use Ubuntu, so if you are using Windows, change the commands to Windows commands.

To install openerplib, you need to download and install setup_tools:

wget https://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg
sudo ./setuptools-0.6c11-py2.7.egg

now you can openerplib:

sudo easy_install openerp-client-lib

usage of openerplib in a script

import openerplib
h = 'localhost'
db = 'myDB'
u = 'admin'
pw = 'verySecurePassword!'

connection = openerplib.get_connection(
    hostname=h, database=db, login=u, password=p)

#now you have a connection to the DB and can you do some things
#first get an object of your model
user_obj = connection.get_model('res.model')
# use this object to execute some action, in this case, search for user(s)
# with John in the name, but also Johnny....
user_id = user_obj.search([('name', 'in', 'John')])
if user_id == []:
    print 'No user found who has John in his name'
    #now read all the users whose IDs are in user_id
    users = user_bj.read(user_id)
    print 'There are %s user(s) with John in the name' %(len(user_id)
    for u in users:
        print 'User %s has userID %s' %(u['name'], u['id'])

#close the connection nicely

(2) I want to load a model (table) with data retrieved dynamically from an external application API. The idea is to be able to interact with the external API from within OpenERP, synchronize OpenERP model data with the API data, (when a new record is created via Openerp action, a resource is added for the same via a PUT or POST request to the external API too, and vice versa)

P Mittal
on 5/31/13, 10:17 PM

Perhaps (2) needs to be framed into a new question. The openerplib thing sounds exiting. Can you give me a link to it; get lots of stuff when I search?

P Mittal
on 5/31/13, 10:22 PM


--Borni DHIFI--
| 6 8 9
Tunis, Tunisia
--Borni DHIFI--

Techno Functional Consultant Odoo(OpenERP) 


Skype : dhifi.borni

On 5/31/13, 6:58 PM


you can start with Developer Memento OpenERP for Open Source RAD with OpenERP 7.0 and good start with ORM.

Yes, got it a day back. I got a link on one of your other answers on a question asking about Module development. This doc is perhaps the best I have see so far. Thanks, (On a sidenote, I still think there needs to be more documentation to explain module development in detail and with different examples)

P Mittal
on 5/31/13, 10:13 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 5/23/13, 4:08 PM
Seen: 4214 times
Last updated: 3/16/15, 8:10 AM