总和时间 odoo 9
Sum times odoo 9
在树视图中使用计算时,总和不可见。当使用 onChange sum 时,任何解决方案都是可见的,如何修复它。我需要在从 .csv 插入数据后自动填充 time_total 字段后进行计算。
示例:
来源:
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)
只做一处改变,
将该字段存储在数据库中,它将显示该字段的总和。
total_time = fields.Float(string='Total minutes', placeholder="Total", compute='onchange_time', store=True)
然后删除 onchange 并改为使用 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.
在树视图中使用计算时,总和不可见。当使用 onChange sum 时,任何解决方案都是可见的,如何修复它。我需要在从 .csv 插入数据后自动填充 time_total 字段后进行计算。
示例:
来源:
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)
只做一处改变,
将该字段存储在数据库中,它将显示该字段的总和。
total_time = fields.Float(string='Total minutes', placeholder="Total", compute='onchange_time', store=True)
然后删除 onchange 并改为使用 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.