我有这个班级
name = fields.Char("Name")
sequence = fields.Integer("Sequence")
description = fields.Text("Description")
我需要一种搜索方法来查找序列较低的id
答案 0 :(得分:2)
res = self.env['your.model'].search([], limit=1, order='sequence desc')
应该诀窍
答案 1 :(得分:0)
我认为这个搜索功能可以解决问题。
def _find_register(self, operator, value):
lowest_sequence_id = False
lowest_sequence = False
for state in self.env['ags.traffic.operation.state'].search([('id','>',0)]):
if not lowest_sequence:
lowest_sequence_id = state.id
lowest_sequence = state.sequence
elif state.sequence < lowest_sequence:
lowest_sequence = state.sequence
return [('id', '=', lowest_sequence_id)]