From 0ae67777a691e93eaf2814ef6c46721055d8efc3 Mon Sep 17 00:00:00 2001 From: michel Date: Mon, 13 Nov 2017 16:29:34 +0100 Subject: [PATCH] / --- models/event.py | 16 ++++++++++------ views/event_views.xml | 1 + 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/models/event.py b/models/event.py index 5e6b77c..ac5e89c 100644 --- a/models/event.py +++ b/models/event.py @@ -12,28 +12,32 @@ class Event(models.Model): _order = 'id desc' title = fields.Char(required=True) - # manager = fields.Many2one('coworker.users', 'Manager', required=True, index=True) - + # manager = fields.Many2one('coworker.users','Manager', required=True, index=True) date_start = fields.Datetime(default=fields.Date.context_today, required=True) date_end = fields.Datetime(required=True) duration = fields.Float(compute='_compute_duration') + description = fields.Text() + # statut = fields.Selection([('draft', 'Draft'), + # ('confirmed', 'Confirmed'), + # ('canceled', 'Canceled')]) @api.constrains('date_end') def _check_date_end(self): """Test si la modification de la date n'est pas postérieur à la date de début""" if self.date_start > self.date_end: - raise ValidationError(_('Date most be supperior to to start date')) + raise ValidationError( + _('Date most be supperior to to start date')) @api.depends('date_start', 'date_end') def _compute_duration(self): for event in self: if event.date_start and event.date_end: - t1 = fields.Datetime.from_string(event.date_end) - t2 = fields.Datetime.from_string(event.date_start) - delta = t1 - t2 + date_end_py = fields.Datetime.from_string(event.date_end) + date_start_py = fields.Datetime.from_string(event.date_start) + delta = date_end_py - date_start_py event.duration = delta.days * 24.0 + round(float(delta.seconds) / 3600.0) else: event.duration = 0.0 diff --git a/views/event_views.xml b/views/event_views.xml index ad20cdf..e4f0b55 100644 --- a/views/event_views.xml +++ b/views/event_views.xml @@ -15,6 +15,7 @@ +