odoo获取最大数组索引的值

时间:2016-08-23 03:26:34

标签: python openerp

我有一个函数将数据附加到数组中:

def _get_state(self, cr, uid, context=None):
    idemployee = _default_employee(self, cr, uid, context=None)
    sql = " SELECT C.id AS id, C.sequence, C.name \
                   FROM wf_group_member A \
           LEFT JOIN wf_group B ON B.id = A.group_id \
           LEFT JOIN wf_process BB ON BB.id = B.process_id\
           LEFT JOIN wf_state C ON C.group_id = B.id \
           LEFT JOIN hr_employee D ON D.id = A.member_id \
           WHERE LOWER(code) = 'ca' AND member_id = %s ORDER BY sequence "
    res = []
    cr.execute(sql, [(idemployee)])
    ardata = cr.fetchall()
    for data in ardata:
        res.append((data[1], data[2]))
    return res

然后我尝试获取最大数组索引的值:

def _get_maxstate(self, cr, uid, context=None):
    res = []
    arr_state = _get_state(self, cr, uid, context)
    states = len(arr_state) - 1
    res = arr_state[0][states]
    return res

但是当我在操作按钮中调用_get_maxstate时,会引发错误:

res = arr_state[0][states]
IndexError: tuple index out of range

我的代码出了什么问题,请帮帮我

1 个答案:

答案 0 :(得分:1)

statesarr_state的最后一个元素的索引。但是,您不会将arr_statestates编入索引,而是使用0对其进行索引,然后使用states将结果编入索引。看起来您可能只想反过来索引,即arr_state[states][0]