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

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

By
roman onosovski
on 6/16/14, 9:17 AM 1,534 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?

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

1 follower(s)

Stats

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