本文介绍了总和Odoo 9的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在树状视图中使用计算时,总和不可见.当使用onChange sum可见时,任何解决方案都如何解决.从.csv插入数据后,我需要自动填充time_total字段进行计算.
When use compute in tree view sum is not visible. When use onChange sum is visible any solution how fix it. I need compute after insert data from .csv automaticly populate time_total fields.
示例:
来源:
class my_data(models.Model):
_name = "my.data"
_description = "My Data"
user = fields.Char(string = 'User')
date = fields.Date(string = 'Date')
start_time = fields.Datetime(string='Start', placeholder="Start", default="2016-01-01 00:00:00.624139")
finish_time = fields.Datetime(string='Finish', placeholder="Finish", default="2016-01-01 00:00:00.624139")
total_time = fields.Float(string='Total minutes', placeholder="Total", compute='onchange_time')
#total_time = fields.Float(string='Total minutes', placeholder="Total minutes")
@api.multi
@api.onchange('start_time', 'finish_time')
def onchange_time(self):
for rec in self:
time1 = datetime.strptime(rec.start_time, "%Y-%m-%d %H:%M:%S")
time2 = datetime.strptime(rec.finish_time, "%Y-%m-%d %H:%M:%S")
rec.total_time = (time2 - time1).seconds / float(60*60)
在表单视图中手动更改值时,树视图中的显示总和
@api.onchange('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)
推荐答案
只需对此做一个更改,
将该字段存储在数据库中,它将显示该字段的总和.
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)
然后删除onchange和insted使用取决于
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)
这篇关于总和Odoo 9的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!