Search 获取具有最低序列的记录的id

Search 获取具有最低序列的记录的id,search,openerp,odoo-8,Search,Openerp,Odoo 8,我有这门课 name = fields.Char("Name") sequence = fields.Integer("Sequence") description = fields.Text("Description") 我需要一个搜索方法来查找序列较低的id我认为这个搜索函数可以解决这个问题 def _find_register(self, operator, value): lowest_sequence_id = False lowest_sequence = Fals

我有这门课

name = fields.Char("Name")
sequence = fields.Integer("Sequence")
description = fields.Text("Description")

我需要一个搜索方法来查找序列较低的id

我认为这个搜索函数可以解决这个问题

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)]
def\u find\u寄存器(自身、运算符、值):
最低\u序列\u id=False
最低顺序=错误
对于self.env['ags.traffic.operation.state'].search([('id','>',0)])中的状态:
如果不是最低顺序:
最低\u序列\u id=state.id
最低顺序=state.sequence
elif state.sequence<最低顺序:
最低顺序=state.sequence
返回[('id','=',最低的\u序列\u id)]

我认为这个搜索功能会起作用

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)]
def\u find\u寄存器(自身、运算符、值):
最低\u序列\u id=False
最低顺序=错误
对于self.env['ags.traffic.operation.state'].search([('id','>',0)])中的状态:
如果不是最低顺序:
最低\u序列\u id=state.id
最低顺序=state.sequence
elif state.sequence<最低顺序:
最低顺序=state.sequence
返回[('id','=',最低的\u序列\u id)]
你应该去玩这个把戏


我不明白这是怎么回事。在一种方法中,我需要“寄存器”的ID,下面的序列是
sequence=fields.Integer(“sequence”)
。。是序列数组吗?例如state_id=self.env['ags.traffic.operation.state'].search([]).get('id')not work state_id=self.env['ags.traffic.operation.state'].search([]).id not work state_id=self.env['ags.traffic.operation.state'].search(['name','go'])not work work state
class-transport\u-traffic\u-state\u-type(Model):\u-name=“ags.traffic.operation.state”_order='sequence asc'name=fields.Char(“name”)sequence=fields.Integer(“sequence”)description=fields.Text(“description”)state_type=fields.Selection([('beging','beging'),('notification','notification'),('ending','ending'),'type'))
我不明白。在一种方法中,我需要“寄存器”的ID,下面的序列是
sequence=fields.Integer(“序列”)
。是序列数组吗?例如state\u ID=self.env['ags.traffic.operation.state']。search([])。get('ID')not work state\u ID=self.env['ags.traffic.operation.state']。search([]).id不工作状态\u id=self.env['ags.traffic.operation.state'].search(['name','=','Gone'])不工作
class transport\u traffic\u state\u type(models.Model):\u name=“ags.traffic.operation.state”\u order='sequence asc'name=fields.Char(“name”)sequence=fields.Integer(“sequence”)description=fields.Text(“description”)state_type=fields.Selection([('beging','beging'),('notification','notification'),('ending','ending'),'type')
最后我把“asc”改成了“desc”,但这是我想要的,非常感谢