Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
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.
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' else: #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 connection.close()
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.Register
Odoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.Test it now
|Asked: 5/23/13, 4:08 PM|
|Seen: 5025 times|
|Last updated: 3/16/15, 8:10 AM|