ORM in odoo framework
Question:
How to change the below sql query to ODOO orm
select max(dnddate) from ink where id = 23 and type= 'h' and kar not in ("5") group by customer;
Answers:
To create your query using Odoo ORM, we should use the read_group function.
inks = self.env['ink'].read_group([
('id', '=', 23),
('type', '=', 'h'),
('kar', 'not in', ("5"))], ['dnddate:max'], ['customer'])
Read about Model.read_group()
https://www.odoo.com/documentation/13.0/reference/orm.html#search-read
How to change the below sql query to ODOO orm
select max(dnddate) from ink where id = 23 and type= 'h' and kar not in ("5") group by customer;
To create your query using Odoo ORM, we should use the read_group function.
inks = self.env['ink'].read_group([
('id', '=', 23),
('type', '=', 'h'),
('kar', 'not in', ("5"))], ['dnddate:max'], ['customer'])
Read about Model.read_group()
https://www.odoo.com/documentation/13.0/reference/orm.html#search-read