Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
2 Відповіді
5346 Переглядів

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?
Аватар
Відмінити
Найкраща відповідь

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


Аватар
Відмінити
Автор

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

Найкраща відповідь

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()
Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
3
трав. 20
12769
3
жовт. 15
6568
2
лип. 25
1412
1
трав. 24
2706
2
лют. 24
2193