Openerp 函数字段
嘿,我刚接触openerp,需要帮助来创建一个叫做“总计”的函数字段,这个字段可以计算同一个对象中所有字段的总和……比如说。
_name = 'hr.performanzze'
_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'),
}
def get_total(self, cr, uid, field_name, arg, context):
#want to calculate the sum of p and b
return the answer
3 个回答
-1
def get_total(self, cr, uid, field_name, arg, context):
for obj in self.browse(cr, uid, ids, context=context):
return obj.p + obj.b
你可以直接使用浏览方法,来查看与那个记录相关联的数据列表。
2
从这里开始:字段的文档
5
在编程中,有时候我们会遇到一些问题,尤其是在使用特定的工具或库时。比如,有人可能在使用某个库的时候,发现它的某些功能没有按照预期工作。这种情况下,通常需要检查代码,看看是不是哪里出错了。
有些人会建议查看文档,了解这个库的使用方法和限制。文档就像是使用说明书,里面有详细的介绍和例子,可以帮助我们更好地理解如何使用这个工具。
此外,社区论坛也是一个很好的资源。在这些地方,很多开发者会分享他们的经验和解决方案。如果你遇到的问题别人也遇到过,可能会找到现成的答案。
总之,遇到问题时,不要着急,先检查代码,看看文档,再去社区寻求帮助。这样一步步来,问题就能迎刃而解。
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