Skip to Content
Menu
Dette spørgsmål er blevet anmeldt
2 Besvarelser
5375 Visninger

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
Kassér
Bedste svar

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


Avatar
Kassér
Forfatter

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

Bedste svar

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
Kassér
Related Posts Besvarelser Visninger Aktivitet
3
maj 20
12793
3
okt. 15
6587
2
jul. 25
1477
1
maj 24
2751
2
feb. 24
2232