我得到了列表值的问题:
def _get_state(self, cr, uid, context=None):
idemployee = _default_employee(self, cr, uid, context=None)
# sql = " SELECT id, sequence, name FROM wf_state ORDER BY sequence "
sql = " SELECT C.id AS id, C.sequence, C.name, member_id, name_related AS employee_name, \
B.name AS group_name, C.name AS state_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]))
res.append((data[1], data[2]))
return res
array_state = _get_state
class cashadvance(osv.osv):
_name = 'ga.cashadvance'
_columns = {
'state' : fields.selection(array_state, 'Status', readonly=True, required=True),
}
_defaults={
'state' : array_state[0][0],
}
日志中的错误是: 'state':array_state [0] [0], TypeError:'function'对象没有属性'getitem _'
请帮我解决这个问题
答案 0 :(得分:1)
将您的<div id="container">
<div id="header">
<div id="menu">
<ul>
<li><a href="#">Contact</a>
</li>
<li><a href="#">About</a>
</li>
<li><a href="#">Services</a>
</li>
<li><a href="#">Home</a>
</li>
</ul>
</div>
</div>
</div>
更改为:
_defaults
你必须确保结果不是空的。
答案 1 :(得分:0)
您打算调用_get_state
函数。你应该这样做:
array_state = _get_state(args...)
您省略了括号,因此您将函数对象本身分配给array_state,而不是从_get_state
分配返回的值。
然后你实际上尝试在函数对象上放置一个索引,当然,它不支持这种操作。支持索引的对象 - 比如从_get_state
返回的对象 - 有一个名为__getitem__
的方法。