2016-08-19 2 views
0

필드 기능에 오류가 있습니다. 내 함수에서, 내 변수 total에서 float 값을 반환하고 싶습니다. 그리고 나는 이미 그것을 찾았고 대답은 here 이었지만 여전히 설명을 이해하지 못합니다. 여기에 내 오류가 있습니다.Odoo에서 필드 기능을 사용하여 사전을 반환하는 방법

ValueError: dictionary update sequence element #0 has length 1; 2 is required 

여기 내 코드입니다.

@api.multi 
@api.depends('total_eec', 'total_tec') 
def _consumption_actual_value(self): 
    res = {} 
    total = 0.0 
    for i in self: 
     total = i.total_eec + i.total_tec 
     res[i.id] = total 
    return res 

_columns = {'consumption_actual': fields.function(_consumption_actual_value, string='Consumption (kWh) Actual'), # TEC + EEC} 

도와주세요.

답변

2

api를 모두 섞어서, 이전 api로 필드를 선언했으며 새 API로 작성된 함수를 작성했습니다. 다음을 시도해야합니다.

@api.multi 
@api.depends('total_eec', 'total_tec') 
def _consumption_actual_value(self): 
    for i in self: 
     total = i.total_eec + i.total_tec 
     i.consumption_actual = total or 0.0 


consumption_actual = fields.Float(compute=_consumption_actual_value, string='Consumption (kWh) Actual') 
관련 문제