3
在树视图中使用compute时,sum不可见。当使用onChange总和时,任何解决方案都是可见的。从.csv插入数据后,我需要计算自动填充time_total字段。总和时间odoo 9
例子:
来源:
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)
SHOW SUM树视图时,在窗体视图MANUAL变化值
@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)
请在您的问题中包含您的代码,输出和预期输出;不要链接到它。 – Evert
@Evert源代码添加 – Pointer