开发者

Openerp function fields

开发者 https://www.devze.com 2023-04-02 12:59 出处:网络
Hey I\'m new to openerp and I need help开发者_JAVA技巧 to create a function field called Total that calculates the sum of all the fields of the same object...

Hey I'm new to openerp and I need help开发者_JAVA技巧 to create a function field called Total that calculates the sum of all the fields of the same object... eg.

_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


Start here : Documentation of fields


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号