Se rendre au contenu
Menu
Cette question a été signalée
2 Réponses
5306 Vues

I want to use sql queries in CustomerPortal class controllers. I wrote following code:

request.cr.execute("""my query""")
result = request.cr.fetchall()
but I get the following error:
AttributeError: 'CustomerPortal (extended by PortalAccount, Custome' object has no attribute 'cr'a
what should I do?
Avatar
Ignorer
Meilleure réponse

Hello Arian, try to use 'request.session.cr' instead of 'request.cr'.


Avatar
Ignorer
Auteur

thanks! request.env.cr worked for me aswell.

Meilleure réponse

https://github.com/odoo/odoo/blob/13.0/addons/web/controllers/main.py#L1551

## inside try

registry = odoo.modules.registry.Registry(dbname)
with registry.cursor() as cr:
cr.execute(""" query """)
row = cr.fetchone()
Avatar
Ignorer
Publications associées Réponses Vues Activité
3
mai 20
12730
3
oct. 15
6529
2
juil. 25
1392
1
mai 24
2668
2
févr. 24
2175