Odoo Help

0

Best way to access Model from outside the inherited osv class?

By
roman onosovski
on 6/16/14, 9:17 AM 1,925 views

I am writing an application to service Dropbox webhooks and I have a controller class:

class webhook(http.Controller):

   _cp_path="/pathto"

   @http.request

   def index(self, req, **kwargs):

      """Need to access database tables here"""

 

So I figured out that I need a cr, uid, and some other parameters,

I defined the following and have gotten it to work:

 

cr = openerp.sql_db.db_connect("DBNAME").cursor()

pool=openerp.pooler.RegistryManager.get("DBNAME")

result=pool.get("model.path").search(cr,1,[])

cr.close()

 

Is this the best way to do this?

2
PY
On 2/24/15, 8:37 AM

Hi !

As said in 

https://www.odoo.com/documentation/8.0/howtos/website.html#accessing-the-data

you can acces you models with:

http.request.env['your.model']

Regards

0
Gustavo Seluja
On 9/22/15, 10:54 AM

Hi, I'm writing a controller for V7 and I have the same problem. I want to get the database name and the cursor but I can't because there is no a "request" parameter like in V8 to get the cr value and I can't obtain database name from anywhere. Is it possible to do it in anyway?

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

Question tools

1 follower(s)

Stats

Asked: 6/16/14, 9:17 AM
Seen: 1925 times
Last updated: 9/22/15, 10:54 AM