diff --git a/addons/hr_timesheet_sheet/hr_timesheet_sheet.py b/addons/hr_timesheet_sheet/hr_timesheet_sheet.py index 5a899555e5d..ea2b5017790 100644 --- a/addons/hr_timesheet_sheet/hr_timesheet_sheet.py +++ b/addons/hr_timesheet_sheet/hr_timesheet_sheet.py @@ -481,21 +481,22 @@ class hr_timesheet_line(osv.osv): 'date': _get_default_date, } - def create(self, cr, uid, vals, *args, **kwargs): - if vals.get('sheet_id', False): - ts = self.pool.get('hr_timesheet_sheet.sheet').browse(cr, uid, vals['sheet_id']) - if not ts.state in ('draft', 'new'): - raise osv.except_osv(_('Error !'), _('You can not modify an entry in a confirmed timesheet !')) - return super(hr_timesheet_line,self).create(cr, uid, vals, *args, **kwargs) + def _check_sheet_state(self, cr, uid, ids, context=None): + if context is None: + context = {} + for timesheet_line in self.browse(cr, uid, ids, context=context): + if timesheet_line.sheet_id and timesheet_line.sheet_id.state not in ('draft', 'new'): + return False + return True + + _constraints = [ + (_check_sheet_state, 'You can not modify an entry in a Confirmed/Done timesheet !.', ['state']), + ] def unlink(self, cr, uid, ids, *args, **kwargs): self._check(cr, uid, ids) return super(hr_timesheet_line,self).unlink(cr, uid, ids,*args, **kwargs) - def write(self, cr, uid, ids, *args, **kwargs): - self._check(cr, uid, ids) - return super(hr_timesheet_line,self).write(cr, uid, ids,*args, **kwargs) - def _check(self, cr, uid, ids): for att in self.browse(cr, uid, ids): if att.sheet_id and att.sheet_id.state not in ('draft', 'new'):