From f495432c7f7629ebc36337557faa7b5fb9ccc964 Mon Sep 17 00:00:00 2001 From: "JMA (OpenERP)" Date: Tue, 11 May 2010 16:02:48 +0530 Subject: [PATCH] [FIX] Hr_holidays : Constraint corrected for Holidays request(start date cannot be greater than end date) bzr revid: jma@tinyerp.com-20100511103248-g1s0vdpkh30w1v99 --- addons/hr_holidays/hr_holidays.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/addons/hr_holidays/hr_holidays.py b/addons/hr_holidays/hr_holidays.py index cd0d86457d9..1c8b5de2b39 100644 --- a/addons/hr_holidays/hr_holidays.py +++ b/addons/hr_holidays/hr_holidays.py @@ -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={}):