Поля функции Openerp - PullRequest
       5

Поля функции Openerp

1 голос
/ 06 сентября 2011

Эй, я новичок в 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 ]

5 голосов
/ 18 сентября 2011
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 голосов
/ 06 сентября 2011
0 голосов
/ 10 июня 2014
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

Можно напрямую использовать метод просмотра и получить доступ к списку данных, прикрепленных к этой записи.

...