简体   繁体   English

Openerp功能栏位

[英]Openerp function fields

Hey I'm new to openerp and I need help to create a function field called Total that calculates the sum of all the fields of the same object... eg. 嗨,我是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

从这里开始: 字段文档

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

One can directly use browse method and access list of data attached with that record. 可以直接使用浏览方法并访问与该记录关联的数据列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM