跳至内容
菜单
此问题已终结
2 回复
5319 查看

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()
形象
丢弃
相关帖文 回复 查看 活动
3
5月 20
12740
3
10月 15
6529
2
7月 25
1398
1
5月 24
2673
2
2月 24
2178