Odoo ORM has limited methods and sometimes it is difficult to fetch certain data from the ORM. In these cases, you can fetch data in the desired format and you need to perform an operation on the data to get a certain result. Due to this, it becomes slower. To handle these special cases, you can execute SQL queries in the database. In this recipe, we will explore how you can run SQL queries from Odoo.
Accessing records through database queries
How to do it...
You can perform database queries through the self._cr.execute method:
self._cr.execute("SELECT id, name, date_release FROM library_book WHERE name ilike %s", ('%odoo%',))
data = self._cr.fetchall()
print(data)
Output:
[(7, 'Odoo basics', datetime...