Odoo Help

Welcome!

This community 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.

0

Using the OpenERP ORM interactively from the python interpreter like Django?

By
P Mittal
on 5/31/13, 11:12 PM 2,243 views

I am wondering how can I use the OpenERP ORM interactively from the Python interpreter without having to use it within the module. Moreover, issuing a command (create/search/browse/...) is only allowed inside the class in the form something like this-

self.command

But I am not able to issue these commands on the object outside the class using model_name instead of self.

Example: I have a model called Bank. I want to create a bank from some python code somewhere else. Doing something this does NOT work.

Bank.create(...)

(cr, uid, etc are not available outside the class)

Things are not as simple as instantiating a Bank object like:

bank_obj = Bank(...values...)

and then issuing bank_obj.save() to save it in the database like it is in Django.

(My question is turning into..."Why does the OpenERP ORM have to be so complicated and non-pythonic? Why can't things be the Django way"), but thats not the main thing I want to ask in this question.

I want to understand how I could use the existing ORM well to do everything I could do with the Models in Django.

  • (1) Use the ORM interactively from the interpreter?
  • (2) Able to issue create, update, search, browse commands on the model, even outside the class where the model is defined?
0
Dharmesh Rathod
On 6/1/13, 1:55 AM

Hi,

You can call OpenERP API from python prompt. Use xmlrpclib library of python and call API.

Example :

import xmlrpclib s_str = 'http://localhost:8069/xmlrpc/object' sock = xmlrpclib.ServerProxy(s_str)

prod_ids = sock.execute(DBNAME, USERID, PASSWD, 'product.product','search', [])

print prod_ids

This way you can call other API like create, read, write, unlink and also method of object from python prompt.

Email : info@acespritech.com
Skype : acespritech
Blog : acespritechblog.wordpress.com

0
kalmenchia
On 6/1/13, 1:52 AM

Hi ,

I know one that you can do the calling OpenERP framework the main purpose of OpenERP tools is for installing, configuring and managing instances and servers.

it can be found here https: // launchpad.net / oerptools

and it gives you some clues of how to use ORM interactively from the interpreter. and some clue of doing CRUD as well . Hope this is what you are looking for.

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 community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 5/31/13, 11:12 PM
Seen: 2243 times
Last updated: 3/16/15, 8:10 AM