Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
2 Replies
5304 Tampilan

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?
Avatar
Buang
Jawaban Terbai

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


Avatar
Buang
Penulis

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

Jawaban Terbai

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()
Avatar
Buang
Post Terkait Replies Tampilan Aktivitas
3
Mei 20
12730
3
Okt 15
6529
2
Jul 25
1392
1
Mei 24
2664
2
Feb 24
2174