2016-08-19 5 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') 
関連する問題