Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odgovori
5314 Prikazi

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
Opusti
Best Answer

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


Avatar
Opusti
Avtor

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

Best Answer

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
Opusti
Related Posts Odgovori Prikazi Aktivnost
3
maj 20
12735
3
okt. 15
6529
2
jul. 25
1397
1
maj 24
2673
2
feb. 24
2177