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
1=== modified file 'hr_timesheet_sheet/hr_timesheet_sheet.py'
2--- hr_timesheet_sheet/hr_timesheet_sheet.py 2014-04-23 11:25:54 +0000
3+++ hr_timesheet_sheet/hr_timesheet_sheet.py 2014-04-24 14:37:29 +0000
4@@ -20,10 +20,11 @@
5 ##############################################################################
6
7 import time
8-from datetime import datetime, timedelta
9+from datetime import datetime
10 from dateutil.relativedelta import relativedelta
11
12 from openerp.osv import fields, osv
13+from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT
14 from openerp.tools.translate import _
15 from openerp import netsvc
16
17@@ -390,18 +391,21 @@
18 attendance_ids.extend([row[0] for row in cr.fetchall()])
19 return attendance_ids
20
21+ def _get_current_sheet(self, cr, uid, employee_id, date=False, context=None):
22+ if not date:
23+ date = time.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
24+ date_to = date[0:10]+' 00:00:00'
25+ # limit=1 because only one sheet possible for an employee between 2 dates
26+ sheet_ids = self.pool.get('hr_timesheet_sheet.sheet').search(cr, uid, [
27+ ('date_to', '>=', date_to), ('date_from', '<=', date),
28+ ('employee_id', '=', employee_id)
29+ ], limit=1, context=context)
30+ return sheet_ids and sheet_ids[0] or False
31+
32 def _sheet(self, cursor, user, ids, name, args, context=None):
33- sheet_obj = self.pool.get('hr_timesheet_sheet.sheet')
34 res = {}.fromkeys(ids, False)
35 for attendance in self.browse(cursor, user, ids, context=context):
36- date_to = datetime.strftime(datetime.strptime(attendance.name[0:10], '%Y-%m-%d'), '%Y-%m-%d %H:%M:%S')
37- sheet_ids = sheet_obj.search(cursor, user,
38- [('date_to', '>=', date_to), ('date_from', '<=', attendance.name),
39- ('employee_id', '=', attendance.employee_id.id)],
40- context=context)
41- if sheet_ids:
42- # [0] because only one sheet possible for an employee between 2 dates
43- res[attendance.id] = sheet_obj.name_get(cursor, user, sheet_ids, context=context)[0]
44+ res[attendance.id] = self._get_current_sheet(cursor, user, attendance.employee_id.id, attendance.name, context=context)
45 return res
46
47 _columns = {
48@@ -420,16 +424,15 @@
49 def create(self, cr, uid, vals, context=None):
50 if context is None:
51 context = {}
52- if 'sheet_id' in context:
53- ts = self.pool.get('hr_timesheet_sheet.sheet').browse(cr, uid, context['sheet_id'], context=context)
54+
55+ sheet_id = context.get('sheet_id') or self._get_current_sheet(cr, uid, vals.get('employee_id'), vals.get('name'), context=context)
56+ if sheet_id:
57+ ts = self.pool.get('hr_timesheet_sheet.sheet').browse(cr, uid, sheet_id, context=context)
58 if ts.state not in ('draft', 'new'):
59- raise osv.except_osv(_('Error!'), _('You cannot modify an entry in a confirmed timesheet.'))
60- res = super(hr_attendance,self).create(cr, uid, vals, context=context)
61- if 'sheet_id' in context:
62- if context['sheet_id'] != self.browse(cr, uid, res, context=context).sheet_id.id:
63- raise osv.except_osv(_('User Error!'), _('You cannot enter an attendance ' \
64- 'date outside the current timesheet dates.'))
65- return res
66+ raise osv.except_osv(_('Error!'), _('You can not enter an attendance in a submitted timesheet. Ask your manager to reset it before adding attendance.'))
67+ elif ts.date_from > vals.get('name') or ts.date_to < vals.get('name'):
68+ raise osv.except_osv(_('User Error!'), _('You can not enter an attendance date outside the current timesheet dates.'))
69+ return super(hr_attendance,self).create(cr, uid, vals, context=context)
70
71 def unlink(self, cr, uid, ids, *args, **kwargs):
72 if isinstance(ids, (int, long)):