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.
Example:
Source:
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 IN TREE VIEW WHEN MANUAL CHANGE VALUE IN FORM VIEW
@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)
Just do one change in that,
Store that field in database and it will show you the sum of that field.
And then remove onchange and insted use depends