Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
5302 Zobrazení

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šit
Nejlepší odpověď

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


Avatar
Zrušit
Autor

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

Nejlepší odpověď

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šit
Related Posts Odpovědi Zobrazení Aktivita
3
kvě 20
12730
3
říj 15
6529
2
čvc 25
1392
1
kvě 24
2664
2
úno 24
2174