跳至內容
選單
此問題已被標幟
2 回覆
5331 瀏覽次數

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
12752
3
10月 15
6540
2
7月 25
1406
1
5月 24
2688
2
2月 24
2189