[英]How to return a dictionary using field function in Odoo
我的現場功能出現錯誤。 在我的函數中,我想從我的變量total
返回一個浮點值。 而且我已經搜索過了,並且在這里找到了答案,但我仍然不明白其解釋。 這是我的錯誤。
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}
請幫忙。
您已經混合了這兩種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')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.