Merge lp:~openerp-dev/openobject-addons/7.0-fixtimesheet-dle into lp:openobject-addons/7.0

Proposed by Denis Ledoux (OpenERP)
Status: Work in progress
Proposed branch: lp:~openerp-dev/openobject-addons/7.0-fixtimesheet-dle
Merge into: lp:openobject-addons/7.0
Diff against target: 67 lines (+25/-7)
2 files modified
hr_attendance/hr_attendance.py (+15/-7)
hr_timesheet_sheet/hr_timesheet_sheet.py (+10/-0)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/7.0-fixtimesheet-dle
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+184106@code.launchpad.net
To post a comment you must log in.
9416. By Launchpad Translations on behalf of openerp

Launchpad automatic translations update.

9417. By Denis Ledoux (OpenERP)

[FIX]hr_attendance: change alternance constraint, now taking account of the sheet_id

Unmerged revisions

9417. By Denis Ledoux (OpenERP)

[FIX]hr_attendance: change alternance constraint, now taking account of the sheet_id

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hr_attendance/hr_attendance.py'
2--- hr_attendance/hr_attendance.py 2012-12-10 11:16:54 +0000
3+++ hr_attendance/hr_attendance.py 2013-09-06 12:50:16 +0000
4@@ -63,6 +63,16 @@
5 'employee_id': _employee_get,
6 }
7
8+ def _get_next_and_prev(self, att):
9+ cr = att._cr
10+ uid = att._uid
11+ context = att._context
12+ prev_att_ids = self.search(cr, uid, [('employee_id', '=', att.employee_id.id), ('name', '<', att.name), ('action', 'in', ('sign_in', 'sign_out'))], limit=1, order='name DESC')
13+ next_add_ids = self.search(cr, uid, [('employee_id', '=', att.employee_id.id), ('name', '>', att.name), ('action', 'in', ('sign_in', 'sign_out'))], limit=1, order='name ASC')
14+ prev_atts = self.browse(cr, uid, prev_att_ids, context=context)
15+ next_atts = self.browse(cr, uid, next_add_ids, context=context)
16+ return (prev_atts and prev_atts[0] or None, next_atts and next_atts[0] or None)
17+
18 def _altern_si_so(self, cr, uid, ids, context=None):
19 """ Alternance sign_in/sign_out check.
20 Previous (if exists) must be of opposite action.
21@@ -70,20 +80,18 @@
22 """
23 for att in self.browse(cr, uid, ids, context=context):
24 # search and browse for first previous and first next records
25- prev_att_ids = self.search(cr, uid, [('employee_id', '=', att.employee_id.id), ('name', '<', att.name), ('action', 'in', ('sign_in', 'sign_out'))], limit=1, order='name DESC')
26- next_add_ids = self.search(cr, uid, [('employee_id', '=', att.employee_id.id), ('name', '>', att.name), ('action', 'in', ('sign_in', 'sign_out'))], limit=1, order='name ASC')
27- prev_atts = self.browse(cr, uid, prev_att_ids, context=context)
28- next_atts = self.browse(cr, uid, next_add_ids, context=context)
29+
30+ prev_atts, next_atts = self._get_next_and_prev(att)
31 # check for alternance, return False if at least one condition is not satisfied
32- if prev_atts and prev_atts[0].action == att.action: # previous exists and is same action
33+ if prev_atts and prev_atts.action == att.action: # previous exists and is same action
34 return False
35- if next_atts and next_atts[0].action == att.action: # next exists and is same action
36+ if next_atts and next_atts.action == att.action: # next exists and is same action
37 return False
38 if (not prev_atts) and (not next_atts) and att.action != 'sign_in': # first attendance must be sign_in
39 return False
40 return True
41
42- _constraints = [(_altern_si_so, 'Error ! Sign in (resp. Sign out) must follow Sign out (resp. Sign in)', ['action'])]
43+ _constraints = [(lambda s, *a, **kw: s._altern_si_so(*a, **kw), 'Error ! Sign in (resp. Sign out) must follow Sign out (resp. Sign in)', ['action'])]
44 _order = 'name desc'
45
46 hr_attendance()
47
48=== modified file 'hr_timesheet_sheet/hr_timesheet_sheet.py'
49--- hr_timesheet_sheet/hr_timesheet_sheet.py 2013-05-08 08:59:38 +0000
50+++ hr_timesheet_sheet/hr_timesheet_sheet.py 2013-09-06 12:50:16 +0000
51@@ -429,6 +429,16 @@
52 raise osv.except_osv(_('Error!'), _('You cannot modify an entry in a confirmed timesheet'))
53 return True
54
55+ def _get_next_and_prev(self, att):
56+ cr = att._cr
57+ uid = att._uid
58+ context = att._context
59+ prev_att_ids = self.search(cr, uid, [('employee_id', '=', att.employee_id.id), ('name', '<', att.name), ('action', 'in', ('sign_in', 'sign_out')), ('sheet_id', '=', att.sheet_id.id)], limit=1, order='name DESC')
60+ next_add_ids = self.search(cr, uid, [('employee_id', '=', att.employee_id.id), ('name', '>', att.name), ('action', 'in', ('sign_in', 'sign_out')), ('sheet_id', '=', att.sheet_id.id)], limit=1, order='name ASC')
61+ prev_atts = self.browse(cr, uid, prev_att_ids, context=context)
62+ next_atts = self.browse(cr, uid, next_add_ids, context=context)
63+ return (prev_atts and prev_atts[0] or None, next_atts and next_atts[0] or None)
64+
65 hr_attendance()
66
67 class hr_timesheet_sheet_sheet_day(osv.osv):