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

How to invoke model and cursor inside controller? Openerp Version 7

By
Gustavo Seluja
on 9/22/15, 11:06 AM 854 views

I'm writing a controller for V7 and I have this 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 too. As you can see, I hardcoded the database name just for testing but I have to get it programatically or get the cursor value.  How can I do that? Following, the actual code:

class firmaController(http.Controller): 
_cp_path = '/x_firma'

@http.httprequest
def index(self, request, **post):

     db_name = 'GRP-MRREE'
     cr = openerp.pooler.get_db(db_name).cursor()
     bd_obj = openerp.pooler.get_pool(db_name)
     firma_obj = bd_obj.get('x_firma')
     id_transaccion = post['id_transaction']
     documento = firma_obj.invocar_ws_obtenerDocumentosFirmados(cr, SUPERUSER_ID, id_transaccion)
     cr.commit()
     cr.close()
     return werkzeug.utils.redirect('/')
firmaController()

Hi Axel, I'm really new with openerp and particularly, with controllers. What do you mean with "authenticated sessions" and how can I do that? For what I've been doing with the debugger tool, request.session._db  is coming with False value. Do you have any example how to implement authenticated sessions?

Gustavo Seluja
on 9/22/15, 12:32 PM

Authenticated sessions are those that needs a previous login on the specific database for the user

Axel Mendoza
on 9/22/15, 12:58 PM
2

Axel Mendoza

--Axel Mendoza--
10318
| 7 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

Axel Mendoza
On 9/22/15, 12:03 PM

Hi @Gustavo Seluja

Normally you need to work with authenticated sessions on your methods in a controller. If that is the case you could get the db_name from the OpenERPSession object like:

db_name = request.session._db

If you are not working with an authenticated session you could always get the db_name as a parameter in your method definition like:

class firmaController(http.Controller): 
    _cp_path = '/x_firma'
    @http.httprequest
    def index(self, request, db=None, **post):

Using the former your url need to add an ?db=db_name as a querystring

Hope this solve your problem

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

2 follower(s)

Stats

Asked: 9/22/15, 11:06 AM
Seen: 854 times
Last updated: 9/26/15, 2:00 AM