Sql query in Odoo model
@api.multi def get_all_so(self, name=None): sql = "select * from sale_order where name like '%s%' order by name desc;" % name self.env.cr.execute(sql) res_all = self.env.cr.fetchall() #fetchall() will return an array of dictionaries return res_all @api.multi def get_so(self, name=None): sql = "select * from sale_order where name like '%s' order by name desc;" % name self.env.cr.execute(sql) #fetchone() will return the first element found as dictionary res_one = self.env.cr.fetchone() return res_one print(self.get_all_so(name='SO2018')) [{'name':'SO2018001','partner_id':'Customer 1',...},{'name':'SO2018002','partner_id':'Customer 2', ...}] print(self.get_so(name='SO2018001')) {'name':'SO2018001','partner_id':'Customer 1',...}
i’ve this error when i try it
NameError: name ‘self’ is not defined
what’s your code ?