[FIX] Hr_holidays : Constraint corrected for Holidays request(start date cannot be...
authorJMA (OpenERP) <jma@tinyerp.com>
Tue, 11 May 2010 10:32:48 +0000 (16:02 +0530)
committerJMA (OpenERP) <jma@tinyerp.com>
Tue, 11 May 2010 10:32:48 +0000 (16:02 +0530)
bzr revid: jma@tinyerp.com-20100511103248-g1s0vdpkh30w1v99

addons/hr_holidays/hr_holidays.py

index cd0d864..1c8b5de 100644 (file)
@@ -163,14 +163,16 @@ class hr_holidays(osv.osv):
                     self.unlink(cr,uid,list_ids)
 
     def _check_date(self, cr, uid, ids):
-        if ids:
-            cr.execute('select number_of_days_temp from hr_holidays where id in ('+','.join(map(str, ids))+')')
-            res =  cr.fetchall()
-            if res and res[0][0] < 0:
+        for rec in self.read(cr, uid, ids, ['number_of_days','date_from','date_to']):
+            if rec['number_of_days'] < 0:
+                return False
+            date_from = time.strptime(rec['date_from'], '%Y-%m-%d %H:%M:%S')
+            date_to = time.strptime(rec['date_to'], '%Y-%m-%d %H:%M:%S')
+            if date_from > date_to:
                 return False
         return True
-
-    _constraints = [(_check_date, 'Start date should not be larger than end date! ', ['number_of_days'])]
+    
+    _constraints = [(_check_date, 'Start date should not be larger than end date!\nNumber of Days should be greater than 1!', ['number_of_days'])]
 
 
     def unlink(self, cr, uid, ids, context={}):