Sum times odoo 9

烂漫一生 提交于 2019-12-06 03:55:52

Just do one change in that,

Store that field in database and it will show you the sum of that field.

total_time = fields.Float(string='Total minutes', placeholder="Total", compute='onchange_time', store=True)

And then remove onchange and insted use depends

@api.depends('start_time', 'finish_time') 
def onchange_time(self):
    time1 = datetime.strptime(self.start_time, "%Y-%m-%d %H:%M:%S")
    time2 = datetime.strptime(self.finish_time, "%Y-%m-%d %H:%M:%S")
    self.total_time = (time2 - time1).seconds / float(60*60)

There is reason behind that scenario is, group by operation required field in database because odoo frameworks prepared query for group by and then get result back from the database. So if the field is not there in database then how it can show you result.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!