2011-09-06 5 views
1

안녕하세요 저는 openerp을 처음 사용 했으므로 같은 객체의 모든 필드 합계를 계산하는 Total이라는 함수 필드를 만드는 데 도움이 필요합니다 ... 예. 여기Openerp 함수 필드

_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 
+0

스택 오버플로에 오신 것을 환영합니다. @lesalami. QGerome이 링크 된 문서를 확인한 다음, 도움이 필요하면 질문을 구체적으로 작성하십시오. –

답변

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
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 

하나는 직접 탐색 방법 및 그 기록에 첨부 된 데이터의 액세스 목록을 사용할 수 있습니다.