Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
5317 Widoki

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?
Awatar
Odrzuć
Najlepsza odpowiedź

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


Awatar
Odrzuć
Autor

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

Najlepsza odpowiedź

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()
Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
3
maj 20
12739
3
paź 15
6529
2
lip 25
1398
1
maj 24
2673
2
lut 24
2178