Openerp Odoo索引器:列表分配索引超出范围
我只是创建一个模块。添加值后出现问题Indexer:列表分配索引超出范围。如何修复它。请重新编辑代码。 这是我的密码:Openerp Odoo索引器:列表分配索引超出范围,openerp,odoo,Openerp,Odoo,我只是创建一个模块。添加值后出现问题Indexer:列表分配索引超出范围。如何修复它。请重新编辑代码。 这是我的密码: class calculator(osv.osv): _name = 'calculator.calculator' def get_total(self, cr, uid, ids, field_name, arg, context): res = [] perfos = self.browse(cr, uid,
class calculator(osv.osv):
_name = 'calculator.calculator'
def get_total(self, cr, uid, ids, field_name, arg, context):
res = []
perfos = self.browse(cr, uid, ids, context)
for perfo in perfos:
res[perfo.id] = perfo.p + perfo.b
return res
_columns = {
'p':fields.selection(((1,'Outstanding'), (2,'Well Above Expectations'), (3,'As Expected'), (4,'Below Expectations'), (5,'VeryPoor'), (0,'N/A')),'title'),
'b':fields.selection(((1,'Outstanding'), (2,'Well Above Expectations'), (3,'As Expected'), (4,'Below Expectations'), (5,'Very Poor'), (0,'N/A')),'title'),
'total' : fields.function(get_total, method=True, string='Total Mark'),
}
您需要返回函数字段的字典。您将
res
定义为列表,并尝试将其指定为字典res[perfo.id]
被视为列表,在res
列表中找不到索引值perfo.id
。这就是错误所说的。现在代码将是
class calculator(osv.osv):
_name = 'calculator.calculator'
def get_total(self, cr, uid, ids, field_name, arg, context):
res = {}
for perfos in self.browse(cr, uid, ids, context):
res[perfos.id] = perfos.p + perfos.b
return res
_columns = {
'p':fields.selection(((1,'Outstanding'), (2,'Well Above Expectations'), (3,'As Expected'), (4,'Below Expectations'), (5,'VeryPoor'), (0,'N/A')),'title'),
'b':fields.selection(((1,'Outstanding'), (2,'Well Above Expectations'), (3,'As Expected'), (4,'Below Expectations'), (5,'Very Poor'), (0,'N/A')),'title'),
'total' : fields.function(get_total, method=True, string='Total Mark'),
}
对于上面的代码,您可能会得到以下js错误错误:[uu.sprintf]需要数字,但找到字符串
我不明白把两个选择字段相加有什么意义。在unicode格式中,密钥将以1+1的形式加起来
下面的代码将向您介绍函数字段的基本概念
class calculator(osv.osv):
_name = 'calculator.calculator'
def get_total(self, cr, uid, ids, field_name, arg, context):
res = {}
for perfos in self.browse(cr, uid, ids, context):
res[perfos.id] = perfos.p + perfos.b
return res
_columns = {
'p':fields.integer('A'),
'b':fields.integer('B'),
'total' : fields.function(get_total, method=True, string='Total Mark'),
}
你可能需要看看
如何在计算器中给出p值/p的形式值?现在它看起来像计算器/计算器。计算器,12你可能需要看看兄弟,请检查图片。我想用calculator/firstfield替换。请帮帮我。为此,您需要指定一个
名称
字段或\u rec\u name
或名称
。如果没有其中任何一个,您将始终获得model.name,id
。