From 8f80bfed1610886081014435ae81d59574e608c7 Mon Sep 17 00:00:00 2001 From: michel Date: Fri, 10 Nov 2017 15:59:48 +0100 Subject: [PATCH] Duration fail --- models/event.py | 13 ++++++------- views/event_views.xml | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/models/event.py b/models/event.py index a8929a1..c00327c 100644 --- a/models/event.py +++ b/models/event.py @@ -17,7 +17,7 @@ class Event(models.Model): date_start = fields.Date(default=fields.Date.context_today, required=True) date_end = fields.Date(required=True) - duration = fields.Float() + duration = fields.Float(compute='_compute_duration') @api.constrains('date_end') @@ -26,9 +26,8 @@ class Event(models.Model): if self.date_start > self.date_end: raise ValidationError(_('Date most be supperior to to start date')) - # - # @api.constrains('duration') - # def _check_duration(self): - # """Calcul du temps entre date_start et date_end ne heure""" - # for event in self: - # self.date_start.hour - self.date_end-hour: + + @api.depends('date_start', 'date_end') + def _compute_duration(self): + for event in self: + event.duration = event.date_end - event.date_start diff --git a/views/event_views.xml b/views/event_views.xml index ad20cdf..addc252 100644 --- a/views/event_views.xml +++ b/views/event_views.xml @@ -14,7 +14,7 @@ - +