Skip to Content
Menu
This question has been flagged
2 Replies
4264 Views

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

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


Avatar
Discard
Author

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
Discard
Related Posts Replies Views Activity
3
May 20
11491
3
Oct 15
5454
1
May 24
688
2
Feb 24
645
0
Dec 23
315