gpt4 book ai didi

python - Openerp 函数字段

转载 作者:太空宇宙 更新时间:2023-11-04 08:19:52 26 4
gpt4 key购买 nike

嘿,我是 openerp 的新手,我需要帮助来创建一个名为 Total 的函数字段,该字段计算同一对象的所有字段的总和...例如。

_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

最佳答案

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

关于python - Openerp 函数字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7318813/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com