From 6c78541978336ae8ad4dc43f7051c19bf1ad4f7d Mon Sep 17 00:00:00 2001
From: Denis Ledoux <dle@odoo.com>
Date: Thu, 8 Jan 2015 14:16:08 +0100
Subject: [PATCH] [FIX] calendar: prevent updating event with a start date
 greater than the end date

Setting a constraint on an old api style computed field is broken in Odoo 8.0
The constraint is checked with the old value of the computed field, not the new one
So, it was possible to update an event with a start date greater than the stop date
And once done, it was impossible to correct the mistake
---
 addons/calendar/calendar.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/addons/calendar/calendar.py b/addons/calendar/calendar.py
index 3d9ab8b3d3f8..af7f13ee84dd 100644
--- a/addons/calendar/calendar.py
+++ b/addons/calendar/calendar.py
@@ -971,12 +971,14 @@ class calendar_event(osv.Model):
 
     def _check_closing_date(self, cr, uid, ids, context=None):
         for event in self.browse(cr, uid, ids, context=context):
-            if event.stop < event.start:
+            if event.start_datetime and event.stop_datetime < event.start_datetime:
+                return False
+            if event.start_date and event.stop_date < event.start_date:
                 return False
         return True
 
     _constraints = [
-        (_check_closing_date, 'Error ! End date cannot be set before start date.', ['start', 'stop'])
+        (_check_closing_date, 'Error ! End date cannot be set before start date.', ['start_datetime', 'stop_datetime', 'start_date', 'stop_date'])
     ]
 
     def onchange_allday(self, cr, uid, ids, start=False, end=False, starttime=False, endtime=False, startdatetime=False, enddatetime=False, checkallday=False, context=None):
-- 
GitLab