تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
5330 أدوات العرض

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
مايو 20
12752
3
أكتوبر 15
6540
2
يوليو 25
1406
1
مايو 24
2688
2
فبراير 24
2189