Skip to Content
Menu
This question has been flagged
2 Replies
5301 Zobrazenia

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
Zrušiť
Best Answer

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


Avatar
Zrušiť
Autor

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
Zrušiť
Related Posts Replies Zobrazenia Aktivita
3
máj 20
12729
3
okt 15
6529
2
júl 25
1391
1
máj 24
2662
2
feb 24
2174