Openerp function fields

百般思念 提交于 2019-12-30 13:26:50

问题


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.

_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

回答1:


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



回答2:


Start here : Documentation of fields




回答3:


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.



来源:https://stackoverflow.com/questions/7318813/openerp-function-fields

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!