Merge lp:~openerp-dev/openobject-addons/7.0-timesheet-attendance-submit-mat into lp:openobject-addons/7.0

Proposed by Martin Trigaux (OpenERP)
Status: Merged
Merged at revision: 10015
Proposed branch: lp:~openerp-dev/openobject-addons/7.0-timesheet-attendance-submit-mat
Merge into: lp:openobject-addons/7.0
Diff against target: 72 lines (+22/-19)
1 file modified
hr_timesheet_sheet/hr_timesheet_sheet.py (+22/-19)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/7.0-timesheet-attendance-submit-mat
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+217062@code.launchpad.net

Description of the change

Forbid to create an attendance in a submitted timesheet (opw 592632)

To post a comment you must log in.
Revision history for this message
Martin Trigaux (OpenERP) (mat-openerp) wrote :

Merged in 7.0

revno: 10015 [merge]
revision-id: <email address hidden>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'hr_timesheet_sheet/hr_timesheet_sheet.py'
--- hr_timesheet_sheet/hr_timesheet_sheet.py 2014-04-23 11:25:54 +0000
+++ hr_timesheet_sheet/hr_timesheet_sheet.py 2014-04-24 14:37:29 +0000
@@ -20,10 +20,11 @@
20##############################################################################20##############################################################################
2121
22import time22import time
23from datetime import datetime, timedelta23from datetime import datetime
24from dateutil.relativedelta import relativedelta24from dateutil.relativedelta import relativedelta
2525
26from openerp.osv import fields, osv26from openerp.osv import fields, osv
27from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT
27from openerp.tools.translate import _28from openerp.tools.translate import _
28from openerp import netsvc29from openerp import netsvc
2930
@@ -390,18 +391,21 @@
390 attendance_ids.extend([row[0] for row in cr.fetchall()])391 attendance_ids.extend([row[0] for row in cr.fetchall()])
391 return attendance_ids392 return attendance_ids
392393
394 def _get_current_sheet(self, cr, uid, employee_id, date=False, context=None):
395 if not date:
396 date = time.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
397 date_to = date[0:10]+' 00:00:00'
398 # limit=1 because only one sheet possible for an employee between 2 dates
399 sheet_ids = self.pool.get('hr_timesheet_sheet.sheet').search(cr, uid, [
400 ('date_to', '>=', date_to), ('date_from', '<=', date),
401 ('employee_id', '=', employee_id)
402 ], limit=1, context=context)
403 return sheet_ids and sheet_ids[0] or False
404
393 def _sheet(self, cursor, user, ids, name, args, context=None):405 def _sheet(self, cursor, user, ids, name, args, context=None):
394 sheet_obj = self.pool.get('hr_timesheet_sheet.sheet')
395 res = {}.fromkeys(ids, False)406 res = {}.fromkeys(ids, False)
396 for attendance in self.browse(cursor, user, ids, context=context):407 for attendance in self.browse(cursor, user, ids, context=context):
397 date_to = datetime.strftime(datetime.strptime(attendance.name[0:10], '%Y-%m-%d'), '%Y-%m-%d %H:%M:%S')408 res[attendance.id] = self._get_current_sheet(cursor, user, attendance.employee_id.id, attendance.name, context=context)
398 sheet_ids = sheet_obj.search(cursor, user,
399 [('date_to', '>=', date_to), ('date_from', '<=', attendance.name),
400 ('employee_id', '=', attendance.employee_id.id)],
401 context=context)
402 if sheet_ids:
403 # [0] because only one sheet possible for an employee between 2 dates
404 res[attendance.id] = sheet_obj.name_get(cursor, user, sheet_ids, context=context)[0]
405 return res409 return res
406410
407 _columns = {411 _columns = {
@@ -420,16 +424,15 @@
420 def create(self, cr, uid, vals, context=None):424 def create(self, cr, uid, vals, context=None):
421 if context is None:425 if context is None:
422 context = {}426 context = {}
423 if 'sheet_id' in context:427
424 ts = self.pool.get('hr_timesheet_sheet.sheet').browse(cr, uid, context['sheet_id'], context=context)428 sheet_id = context.get('sheet_id') or self._get_current_sheet(cr, uid, vals.get('employee_id'), vals.get('name'), context=context)
429 if sheet_id:
430 ts = self.pool.get('hr_timesheet_sheet.sheet').browse(cr, uid, sheet_id, context=context)
425 if ts.state not in ('draft', 'new'):431 if ts.state not in ('draft', 'new'):
426 raise osv.except_osv(_('Error!'), _('You cannot modify an entry in a confirmed timesheet.'))432 raise osv.except_osv(_('Error!'), _('You can not enter an attendance in a submitted timesheet. Ask your manager to reset it before adding attendance.'))
427 res = super(hr_attendance,self).create(cr, uid, vals, context=context)433 elif ts.date_from > vals.get('name') or ts.date_to < vals.get('name'):
428 if 'sheet_id' in context:434 raise osv.except_osv(_('User Error!'), _('You can not enter an attendance date outside the current timesheet dates.'))
429 if context['sheet_id'] != self.browse(cr, uid, res, context=context).sheet_id.id:435 return super(hr_attendance,self).create(cr, uid, vals, context=context)
430 raise osv.except_osv(_('User Error!'), _('You cannot enter an attendance ' \
431 'date outside the current timesheet dates.'))
432 return res
433436
434 def unlink(self, cr, uid, ids, *args, **kwargs):437 def unlink(self, cr, uid, ids, *args, **kwargs):
435 if isinstance(ids, (int, long)):438 if isinstance(ids, (int, long)):