Openerp功能字段

时间:2011-09-06 11:01:05

标签: python xml openerp

嘿,我是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

3 个答案:

答案 0 :(得分: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

答案 1 :(得分:2)

从这里开始:Documentation of fields

答案 2 :(得分:-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

可以直接使用浏览方法和访问该记录附带的数据列表。