From bbead97ca81c89fac7beb4d24825477edce18567 Mon Sep 17 00:00:00 2001 From: ced <> Date: Fri, 13 Apr 2007 08:44:07 +0000 Subject: [PATCH] HR_TIMESHEET_SHEET: use constraints bzr revid: ced-45f8304aae8ff328257bce62332da9b3ff23fa66 --- addons/hr_timesheet_sheet/hr_timesheet_sheet.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/addons/hr_timesheet_sheet/hr_timesheet_sheet.py b/addons/hr_timesheet_sheet/hr_timesheet_sheet.py index a4c6aa766a7..0b0562ae7b7 100644 --- a/addons/hr_timesheet_sheet/hr_timesheet_sheet.py +++ b/addons/hr_timesheet_sheet/hr_timesheet_sheet.py @@ -251,10 +251,17 @@ class hr_timesheet_sheet(osv.osv): def create(self, cr, uid, vals, *args, **kwargs): if 'state' in vals and vals['state'] == 'new': vals['state']='draft' - cr.execute('select id from hr_timesheet_sheet_sheet where (date_from < %s and %s < date_to) or (date_from < %s and %s = %s and date_to <= %s)', (vals['date_from'], vals['date_from'], vals['date_to'], vals['date_to'], vals['date_from'], vals['date_to'])) - if cr.fetchall(): - raise osv.except_osv('Error !', 'A timesheet sheet already exists in this period') return super(hr_timesheet_sheet, self).create(cr, uid, vals, *args, **kwargs) + + def _sheet_date(self, cr, uid, ids): + for sheet in self.browse(cr, uid, ids): + cr.execute('select id from hr_timesheet_sheet_sheet where (date_from<%s and %s%d', (sheet.date_to, sheet.date_from, sheet.user_id.id, sheet.id)) + if cr.fetchall(): + return False + return True + _constraints = [ + (_sheet_date, 'You can not have 2 timesheets that overlaps !', ['date_from','date_to']) + ] hr_timesheet_sheet() def _get_current_sheet(self, cr, uid, context={}):