This commit is contained in:
michel 2017-11-10 17:35:10 +01:00
parent 05f69c4aec
commit 5d650a71cb

View File

@ -30,8 +30,10 @@ class Event(models.Model):
@api.depends('date_start', 'date_end') @api.depends('date_start', 'date_end')
def _compute_duration(self): def _compute_duration(self):
for event in self: for event in self:
if event.duration is True: if event.date_start and event.date_end:
t1 = fields.Datetime.from_string(event.date_end) t1 = fields.Datetime.from_string(event.date_end)
t2 = fields.Datetime.from_string(event.date_start) t2 = fields.Datetime.from_string(event.date_start)
delta = t1 - t2 delta = t1 - t2
hours = delta.days * 24.0 + round(float(delta.seconds) / 3600.0) event.duration = delta.days * 24.0 + round(float(delta.seconds) / 3600.0)
else:
event.duration = 0.0