如何在函数减法中将两个浮点字段“完成 - 启动”
start = fields.Float(string='Star')
finish = fields.Float(string='Fin')
total = fields.Float(string='Total')
@api.one
def total_sum(self):
??????
答案 0 :(得分:2)
应该是这样,
total = fields.Float(string='Total', compute=_set_total)
@api.multi
def _set_total(self):
for rec in self:
rec.total = float(rec.finish or 0.0) - float(rec.start or 0.0)
但是,您也可以创建该字段正常不起作用
total = fields.Float(string='Total')
@api.onchange('finish','start')
def _set_total(self):
self.total = float(self.finish or 0.00) - float(self.start or 0.00)
答案 1 :(得分:0)
def total_sum(self, cr, uid, ids, start, finish, context=None):
res = {}
res['total'] = finish - start
return {'value': res}