Merge lp:~laetitia-gangloff/hr-timesheet/hr_attendance_analysis_externalise_contract_calendar_ into lp:~hr-core-editors/hr-timesheet/7.0

Proposed by Laetitia Gangloff (Acsone)
Status: Merged
Merged at revision: 62
Proposed branch: lp:~laetitia-gangloff/hr-timesheet/hr_attendance_analysis_externalise_contract_calendar_
Merge into: lp:~hr-core-editors/hr-timesheet/7.0
Diff against target: 343 lines (+62/-77)
2 files modified
hr_attendance_analysis/hr_attendance.py (+41/-52)
hr_attendance_analysis/wizard/print_calendar_report.py (+21/-25)
To merge this branch: bzr merge lp:~laetitia-gangloff/hr-timesheet/hr_attendance_analysis_externalise_contract_calendar_
Reviewer Review Type Date Requested Status
Yannick Vaucher @ Camptocamp code review, no tests Approve
Lorenzo Battistini (community) code review Approve
Guewen Baconnier @ Camptocamp Pending
Review via email: mp+195775@code.launchpad.net

This proposal supersedes a proposal from 2013-08-28.

Description of the change

In order to be able to use another calendar in some extension modules:
- rename get_active_contracts to get_reference_calendar and return the possible calendar attached to retrieve contract
- update code to take account of this change (_get_attendance_duration and print_calendar method)
- externalise store part of column in _store_rules to easily extends it

To post a comment you must log in.
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote : Posted in a previous version of this proposal

LGTM

review: Approve (code review, no test)
Revision history for this message
Lorenzo Battistini (elbati) wrote : Posted in a previous version of this proposal
review: Needs Fixing
Revision history for this message
Laetitia Gangloff (Acsone) (laetitia-gangloff) wrote : Posted in a previous version of this proposal

Oh right !
and all following lines are shifted.

Thank you for your review. I corrected this mistake.

Revision history for this message
Lorenzo Battistini (elbati) wrote : Posted in a previous version of this proposal

There are conflicts.

Your last commit
http://bazaar.launchpad.net/~laetitia-gangloff/hr-timesheet/hr_attendance_analysis_externalise_contract_calendar/revision/54
did a lot of changes

I suggest to revert to revision 53 and make the changes related to line 235 only.

Thanks

review: Needs Fixing
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote : Posted in a previous version of this proposal

There are still conflicts. Can you check ?

review: Needs Resubmitting
Revision history for this message
Laetitia Gangloff (Acsone) (laetitia-gangloff) wrote :

Sorry for the late resolution.

There is no more conflict (for the moment...).

Changes are :

- rename get_active_contracts to get_reference_calendar and return the possible calendar attached to retrieve contract
- update code to take account of this change (_get_attendance_duration and print_calendar method) -> there is many 'if' on same thing to avoid indentation problem, it can be correct in next version
- externalise store part of column in _store_rules to easily extends it
- add some context

Revision history for this message
Lorenzo Battistini (elbati) wrote :

Thanks Laetitia.
Just a little style fix:
at line 23 add spaces after ","

review: Needs Fixing
59. By Laetitia Gangloff (Acsone)

style fix

Revision history for this message
Laetitia Gangloff (Acsone) (laetitia-gangloff) wrote :

Hello,

I add spaces after "," at line 23

Revision history for this message
Lorenzo Battistini (elbati) :
review: Approve (code review)
Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

LGTM thanks

review: Approve (code review, no tests)
Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote : Posted in a previous version of this proposal

This project is now hosted on https://github.com/OCA/hr-timesheet. Please move your proposal there. This guide may help you https://github.com/OCA/maintainers-tools/wiki/How-to-move-a-Merge-Proposal-to-GitHub

review: Needs Resubmitting
Revision history for this message
Laetitia Gangloff (Acsone) (laetitia-gangloff) wrote : Posted in a previous version of this proposal

I think, the state of this mp/branch is not correct.
The purpose of this mp, is already in hr-timesheet project at revision 62.

What is the best pratice to remove the mp and the branch ?

Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote : Posted in a previous version of this proposal

This one is set as Superseeded. Seems fine. No change needed.

Revision history for this message
Laetitia Gangloff (Acsone) (laetitia-gangloff) wrote : Posted in a previous version of this proposal

Super !
Thank you, I set the branch has abandonned.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'hr_attendance_analysis/hr_attendance.py'
--- hr_attendance_analysis/hr_attendance.py 2013-08-30 10:27:51 +0000
+++ hr_attendance_analysis/hr_attendance.py 2013-11-25 08:22:35 +0000
@@ -127,7 +127,9 @@
127 res.append((start_datetime, precision))127 res.append((start_datetime, precision))
128 return res 128 return res
129 129
130 def get_active_contracts(self, cr, uid, employee_id, date=datetime.now().strftime('%Y-%m-%d')):130 def get_reference_calendar(self, cr, uid, employee_id, date=None, context=None):
131 if date is None:
132 date = fields.date.context_today(self, cr, uid, context=context)
131 contract_pool = self.pool.get('hr.contract')133 contract_pool = self.pool.get('hr.contract')
132 active_contract_ids= contract_pool.search(cr, uid, [134 active_contract_ids= contract_pool.search(cr, uid, [
133 '&',135 '&',
@@ -145,12 +147,15 @@
145 '&',147 '&',
146 ('trial_date_end', '!=', False),148 ('trial_date_end', '!=', False),
147 ('trial_date_end', '>=', date),149 ('trial_date_end', '>=', date),
148 ])150 ], context=context)
149 if len(active_contract_ids) > 1:151 if len(active_contract_ids) > 1:
150 employee = self.pool.get('hr.employee').browse(cr,uid,employee_id)152 employee = self.pool.get('hr.employee').browse(cr, uid, employee_id, context=context)
151 raise orm.except_orm(_('Error'), _(153 raise orm.except_orm(_('Error'), _(
152 'Too many active contracts for employee %s'154 'Too many active contracts for employee %s'
153 ) % employee.name)155 ) % employee.name)
156 if active_contract_ids:
157 contract = contract_pool.browse(cr, uid, active_contract_ids[0], context=context)
158 return contract.working_hours
154 return active_contract_ids159 return active_contract_ids
155160
156 def _ceil_rounding(self, rounding, datetime):161 def _ceil_rounding(self, rounding, datetime):
@@ -165,10 +170,9 @@
165170
166 def _get_attendance_duration(self, cr, uid, ids, field_name, arg, context=None):171 def _get_attendance_duration(self, cr, uid, ids, field_name, arg, context=None):
167 res = {}172 res = {}
168 contract_pool = self.pool.get('hr.contract')
169 resource_pool = self.pool.get('resource.resource')173 resource_pool = self.pool.get('resource.resource')
170 attendance_pool = self.pool.get('resource.calendar.attendance')174 attendance_pool = self.pool.get('resource.calendar.attendance')
171 precision = self.pool.get('res.users').browse(cr, uid, uid).company_id.working_time_precision175 precision = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.working_time_precision
172 # 2012.10.16 LF FIX : Get timezone from context176 # 2012.10.16 LF FIX : Get timezone from context
173 active_tz = pytz.timezone(context.get("tz","UTC") if context else "UTC")177 active_tz = pytz.timezone(context.get("tz","UTC") if context else "UTC")
174 str_now = datetime.strftime(datetime.now(), '%Y-%m-%d %H:%M:%S')178 str_now = datetime.strftime(datetime.now(), '%Y-%m-%d %H:%M:%S')
@@ -176,7 +180,7 @@
176 duration = 0.0180 duration = 0.0
177 outside_calendar_duration = 0.0181 outside_calendar_duration = 0.0
178 inside_calendar_duration = 0.0182 inside_calendar_duration = 0.0
179 attendance = self.browse(cr, uid, attendance_id)183 attendance = self.browse(cr, uid, attendance_id, context=context)
180 res[attendance.id] = {}184 res[attendance.id] = {}
181 # 2012.10.16 LF FIX : Attendance in context timezone185 # 2012.10.16 LF FIX : Attendance in context timezone
182 attendance_start = datetime.strptime(186 attendance_start = datetime.strptime(
@@ -188,9 +192,9 @@
188 if attendance.action == 'sign_in':192 if attendance.action == 'sign_in':
189 next_attendance_ids = self.search(cr, uid, [193 next_attendance_ids = self.search(cr, uid, [
190 ('employee_id', '=', attendance.employee_id.id),194 ('employee_id', '=', attendance.employee_id.id),
191 ('name', '>', attendance.name)], order='name')195 ('name', '>', attendance.name)], order='name', context=context)
192 if next_attendance_ids:196 if next_attendance_ids:
193 next_attendance = self.browse(cr, uid, next_attendance_ids[0])197 next_attendance = self.browse(cr, uid, next_attendance_ids[0], context=context)
194 if next_attendance.action == 'sign_in':198 if next_attendance.action == 'sign_in':
195 # 2012.10.16 LF FIX : Attendance in context timezone199 # 2012.10.16 LF FIX : Attendance in context timezone
196 raise orm.except_orm(_('Error'), _(200 raise orm.except_orm(_('Error'), _(
@@ -206,19 +210,18 @@
206 duration = round(duration / precision) * precision210 duration = round(duration / precision) * precision
207 res[attendance.id]['duration'] = duration211 res[attendance.id]['duration'] = duration
208 res[attendance.id]['end_datetime'] = next_attendance_date212 res[attendance.id]['end_datetime'] = next_attendance_date
209 # If contract is not specified: working days = 24/7213 # If calendar is not specified: working days = 24/7
210 res[attendance.id]['inside_calendar_duration'] = duration214 res[attendance.id]['inside_calendar_duration'] = duration
211 res[attendance.id]['outside_calendar_duration'] = 0.0215 res[attendance.id]['outside_calendar_duration'] = 0.0
212216
213 active_contract_ids = self.get_active_contracts(217 reference_calendar = self.get_reference_calendar(
214 cr, uid, attendance.employee_id.id, date=str_now[:10])218 cr, uid, attendance.employee_id.id, date=str_now[:10], context=context)
215219
216 if active_contract_ids and next_attendance_ids:220 if reference_calendar and next_attendance_ids:
217 contract = contract_pool.browse(cr, uid, active_contract_ids[0])221 if reference_calendar:
218 if contract.working_hours:
219 # TODO applicare prima arrotondamento o tolleranza?222 # TODO applicare prima arrotondamento o tolleranza?
220 if contract.working_hours.attendance_rounding:223 if reference_calendar.attendance_rounding:
221 float_attendance_rounding = float(contract.working_hours.attendance_rounding)224 float_attendance_rounding = float(reference_calendar.attendance_rounding)
222 rounded_start_hour = self._ceil_rounding(225 rounded_start_hour = self._ceil_rounding(
223 float_attendance_rounding, attendance_start)226 float_attendance_rounding, attendance_start)
224 rounded_stop_hour = self._floor_rounding(227 rounded_stop_hour = self._floor_rounding(
@@ -243,7 +246,7 @@
243 246
244 res[attendance.id]['inside_calendar_duration'] = 0.0247 res[attendance.id]['inside_calendar_duration'] = 0.0
245 res[attendance.id]['outside_calendar_duration'] = 0.0248 res[attendance.id]['outside_calendar_duration'] = 0.0
246 calendar_id = contract.working_hours.id249 calendar_id = reference_calendar.id
247 intervals_within = 0250 intervals_within = 0
248251
249 # split attendance in intervals = precision252 # split attendance in intervals = precision
@@ -273,7 +276,7 @@
273 ('calendar_id','=',calendar_id),276 ('calendar_id','=',calendar_id),
274 ('hour_to','>=',centered_attendance_hour),277 ('hour_to','>=',centered_attendance_hour),
275 ('hour_from','<=',centered_attendance_hour),278 ('hour_from','<=',centered_attendance_hour),
276 ])279 ], context=context)
277 if len(matched_schedule_ids) > 1:280 if len(matched_schedule_ids) > 1:
278 raise orm.except_orm(_('Error'),281 raise orm.except_orm(_('Error'),
279 _('Wrongly configured working schedule with id %s') % str(calendar_id))282 _('Wrongly configured working schedule with id %s') % str(calendar_id))
@@ -281,7 +284,7 @@
281 intervals_within += 1284 intervals_within += 1
282 # sign in tolerance285 # sign in tolerance
283 if intervals_within == 1:286 if intervals_within == 1:
284 calendar_attendance = attendance_pool.browse(cr, uid, matched_schedule_ids[0])287 calendar_attendance = attendance_pool.browse(cr, uid, matched_schedule_ids[0], context=context)
285 attendance_start_hour = (288 attendance_start_hour = (
286 attendance_start.hour + attendance_start.minute / 60.0289 attendance_start.hour + attendance_start.minute / 60.0
287 + attendance_start.second / 60.0 / 60.0290 + attendance_start.second / 60.0 / 60.0
@@ -302,7 +305,7 @@
302 attendance_stop.hour + attendance_stop.minute / 60.0305 attendance_stop.hour + attendance_stop.minute / 60.0
303 + attendance_stop.second / 60.0 / 60.0306 + attendance_stop.second / 60.0 / 60.0
304 )307 )
305 calendar_attendance = attendance_pool.browse(cr, uid, matched_schedule_ids[0])308 calendar_attendance = attendance_pool.browse(cr, uid, matched_schedule_ids[0], context=context)
306 if attendance_stop_hour <= (309 if attendance_stop_hour <= (
307 calendar_attendance.hour_to and310 calendar_attendance.hour_to and
308 (attendance_stop_hour - (calendar_attendance.hour_to -311 (attendance_stop_hour - (calendar_attendance.hour_to -
@@ -321,13 +324,13 @@
321 res[attendance.id]['inside_calendar_duration'],324 res[attendance.id]['inside_calendar_duration'],
322 res[attendance.id]['duration'])325 res[attendance.id]['duration'])
323326
324 if contract.working_hours.overtime_rounding:327 if reference_calendar.overtime_rounding:
325 if res[attendance.id]['outside_calendar_duration']:328 if res[attendance.id]['outside_calendar_duration']:
326 overtime = res[attendance.id]['outside_calendar_duration']329 overtime = res[attendance.id]['outside_calendar_duration']
327 if contract.working_hours.overtime_rounding_tolerance:330 if reference_calendar.overtime_rounding_tolerance:
328 overtime = self.time_sum(overtime,331 overtime = self.time_sum(overtime,
329 contract.working_hours.overtime_rounding_tolerance)332 reference_calendar.overtime_rounding_tolerance)
330 float_overtime_rounding = float(contract.working_hours.overtime_rounding)333 float_overtime_rounding = float(reference_calendar.overtime_rounding)
331 res[attendance.id]['outside_calendar_duration'] = math.floor(334 res[attendance.id]['outside_calendar_duration'] = math.floor(
332 overtime * float_overtime_rounding) / float_overtime_rounding335 overtime * float_overtime_rounding) / float_overtime_rounding
333336
@@ -337,7 +340,7 @@
337 attendance_ids = []340 attendance_ids = []
338 attendance_pool = self.pool.get('hr.attendance')341 attendance_pool = self.pool.get('hr.attendance')
339 for contract in self.pool.get('hr.contract').browse(cr, uid, ids, context=context):342 for contract in self.pool.get('hr.contract').browse(cr, uid, ids, context=context):
340 att_ids = attendance_pool.search(cr, uid, [('employee_id', '=', contract.employee_id.id)])343 att_ids = attendance_pool.search(cr, uid, [('employee_id', '=', contract.employee_id.id)], context=context)
341 for att_id in att_ids:344 for att_id in att_ids:
342 if att_id not in attendance_ids:345 if att_id not in attendance_ids:
343 attendance_ids.append(att_id)346 attendance_ids.append(att_id)
@@ -348,7 +351,7 @@
348 attendance_pool = self.pool.get('hr.attendance')351 attendance_pool = self.pool.get('hr.attendance')
349 contract_pool = self.pool.get('hr.contract')352 contract_pool = self.pool.get('hr.contract')
350 for calendar in self.pool.get('resource.calendar').browse(cr, uid, ids, context=context):353 for calendar in self.pool.get('resource.calendar').browse(cr, uid, ids, context=context):
351 contract_ids = contract_pool.search(cr, uid, [('working_hours', '=', calendar.id)])354 contract_ids = contract_pool.search(cr, uid, [('working_hours', '=', calendar.id)], context=context)
352 att_ids = attendance_pool._get_by_contracts(cr, uid, contract_ids, context=None)355 att_ids = attendance_pool._get_by_contracts(cr, uid, contract_ids, context=None)
353 for att_id in att_ids:356 for att_id in att_ids:
354 if att_id not in attendance_ids:357 if att_id not in attendance_ids:
@@ -375,45 +378,31 @@
375 ('employee_id', '=', attendance.employee_id.id),378 ('employee_id', '=', attendance.employee_id.id),
376 ('name', '<', attendance.name),379 ('name', '<', attendance.name),
377 ('action', '=', 'sign_in'),380 ('action', '=', 'sign_in'),
378 ], order='name')381 ], order='name', context=context)
379 if previous_attendance_ids and previous_attendance_ids[len(previous_attendance_ids) - 1] not in attendance_ids:382 if previous_attendance_ids and previous_attendance_ids[len(previous_attendance_ids) - 1] not in attendance_ids:
380 attendance_ids.append(previous_attendance_ids[len(previous_attendance_ids) - 1]) 383 attendance_ids.append(previous_attendance_ids[len(previous_attendance_ids) - 1])
381 return attendance_ids384 return attendance_ids
382385
383 _inherit = "hr.attendance"386 _inherit = "hr.attendance"
384387
388 _store_rules = {
389 'hr.attendance': (_get_attendances, ['name', 'action', 'employee_id'], 20),
390 'hr.contract': (_get_by_contracts, ['employee_id', 'date_start', 'date_end', 'trial_date_start', 'trial_date_end', 'working_hours'], 20),
391 'resource.calendar': (_get_by_calendars, ['attendance_ids'], 20),
392 'resource.calendar.attendance': (_get_by_calendar_attendances, ['dayofweek', 'date_from', 'hour_from', 'hour_to', 'calendar_id'], 20),
393 }
394
385 _columns = {395 _columns = {
386 'duration': fields.function(_get_attendance_duration, method=True, multi='duration', string="Attendance duration",396 'duration': fields.function(_get_attendance_duration, method=True, multi='duration', string="Attendance duration",
387 store={397 store=_store_rules),
388 'hr.attendance': (_get_attendances, ['name', 'action', 'employee_id'], 20),
389 'hr.contract': (_get_by_contracts, ['employee_id', 'date_start', 'date_end', 'trial_date_start', 'trial_date_end', 'working_hours'], 20),
390 'resource.calendar': (_get_by_calendars, ['attendance_ids'], 20),
391 'resource.calendar.attendance': (_get_by_calendar_attendances, ['dayofweek', 'date_from', 'hour_from', 'hour_to', 'calendar_id'], 20),
392 }
393 ),
394 'end_datetime': fields.function(_get_attendance_duration, method=True, multi='duration', type="datetime", string="End date time",398 'end_datetime': fields.function(_get_attendance_duration, method=True, multi='duration', type="datetime", string="End date time",
395 store={399 store=_store_rules),
396 'hr.attendance': (_get_attendances, ['name', 'action', 'employee_id'], 20),
397 'hr.contract': (_get_by_contracts, ['employee_id', 'date_start', 'date_end', 'trial_date_start', 'trial_date_end', 'working_hours'], 20),
398 'resource.calendar': (_get_by_calendars, ['attendance_ids'], 20),
399 'resource.calendar.attendance': (_get_by_calendar_attendances, ['dayofweek', 'date_from', 'hour_from', 'hour_to', 'calendar_id'], 20),
400 }),
401 'outside_calendar_duration': fields.function(_get_attendance_duration, method=True, multi='duration',400 'outside_calendar_duration': fields.function(_get_attendance_duration, method=True, multi='duration',
402 string="Overtime",401 string="Overtime",
403 store={402 store=_store_rules),
404 'hr.attendance': (_get_attendances, ['name', 'action', 'employee_id'], 20),
405 'hr.contract': (_get_by_contracts, ['employee_id', 'date_start', 'date_end', 'trial_date_start', 'trial_date_end', 'working_hours'], 20),
406 'resource.calendar': (_get_by_calendars, ['attendance_ids'], 20),
407 'resource.calendar.attendance': (_get_by_calendar_attendances, ['dayofweek', 'date_from', 'hour_from', 'hour_to', 'calendar_id'], 20),
408 }),
409 'inside_calendar_duration': fields.function(_get_attendance_duration, method=True, multi='duration',403 'inside_calendar_duration': fields.function(_get_attendance_duration, method=True, multi='duration',
410 string="Duration within working schedule",404 string="Duration within working schedule",
411 store={405 store=_store_rules),
412 'hr.attendance': (_get_attendances, ['name', 'action', 'employee_id'], 20),
413 'hr.contract': (_get_by_contracts, ['employee_id', 'date_start', 'date_end', 'trial_date_start', 'trial_date_end', 'working_hours'], 20),
414 'resource.calendar': (_get_by_calendars, ['attendance_ids'], 20),
415 'resource.calendar.attendance': (_get_by_calendar_attendances, ['dayofweek', 'date_from', 'hour_from', 'hour_to', 'calendar_id'], 20),
416 }),
417 }406 }
418407
419408
420409
=== modified file 'hr_attendance_analysis/wizard/print_calendar_report.py'
--- hr_attendance_analysis/wizard/print_calendar_report.py 2013-07-16 07:39:48 +0000
+++ hr_attendance_analysis/wizard/print_calendar_report.py 2013-11-25 08:22:35 +0000
@@ -55,7 +55,7 @@
55 'year': lambda * a: datetime.now().year,55 'year': lambda * a: datetime.now().year,
56 'from_date': lambda * a: (datetime.now()-timedelta(30)).strftime('%Y-%m-%d'),56 'from_date': lambda * a: (datetime.now()-timedelta(30)).strftime('%Y-%m-%d'),
57 'to_date': lambda * a: datetime.now().strftime('%Y-%m-%d'),57 'to_date': lambda * a: datetime.now().strftime('%Y-%m-%d'),
58 'employee_ids': lambda s, cr, uid, c: s.pool.get('hr.employee').search(cr, uid, []), 58 'employee_ids': lambda s, cr, uid, c: s.pool.get('hr.employee').search(cr, uid, [], context=None),
59 }59 }
6060
61 _name = "attendance_analysis.wizard.calendar_report"61 _name = "attendance_analysis.wizard.calendar_report"
@@ -74,12 +74,11 @@
74 if context is None:74 if context is None:
75 context = {}75 context = {}
76 attendance_pool = self.pool.get('hr.attendance')76 attendance_pool = self.pool.get('hr.attendance')
77 contract_pool = self.pool.get('hr.contract')
78 holidays_pool = self.pool.get('hr.holidays')77 holidays_pool = self.pool.get('hr.holidays')
7978
80 days_by_employee = {}79 days_by_employee = {}
81 80
82 form = self.read(cr, uid, ids)[0]81 form = self.read(cr, uid, ids, context=context)[0]
83 from_date = datetime.strptime(form['from_date'], '%Y-%m-%d')82 from_date = datetime.strptime(form['from_date'], '%Y-%m-%d')
84 to_date = datetime.strptime(form['to_date'], '%Y-%m-%d')83 to_date = datetime.strptime(form['to_date'], '%Y-%m-%d')
85 if from_date > to_date:84 if from_date > to_date:
@@ -97,7 +96,7 @@
97 current_total_attendances = 0.096 current_total_attendances = 0.0
98 current_total_overtime = 0.097 current_total_overtime = 0.0
99 current_total_leaves = 0.098 current_total_leaves = 0.0
100 current_total_due = 24.0 # If contract is not specified: working days = 24/799 current_total_due = 24.0 # If calendar is not specified: working days = 24/7
101 current_total_inside_calendar = 0.0100 current_total_inside_calendar = 0.0
102 str_current_date = current_date.strftime('%Y-%m-%d')101 str_current_date = current_date.strftime('%Y-%m-%d')
103 days_by_employee[employee_id][str_current_date] = {102 days_by_employee[employee_id][str_current_date] = {
@@ -121,9 +120,9 @@
121 ('name','>=',str_current_date_beginning),120 ('name','>=',str_current_date_beginning),
122 ('name','<=',str_current_date_end),121 ('name','<=',str_current_date_end),
123 ('action','=','sign_in'),122 ('action','=','sign_in'),
124 ])123 ], context=context)
125 # computing attendance totals124 # computing attendance totals
126 for attendance in attendance_pool.browse(cr, uid, attendance_ids):125 for attendance in attendance_pool.browse(cr, uid, attendance_ids, context=context):
127 current_total_attendances = attendance_pool.time_sum(126 current_total_attendances = attendance_pool.time_sum(
128 current_total_attendances,attendance.duration)127 current_total_attendances,attendance.duration)
129 current_total_overtime = attendance_pool.time_sum(current_total_overtime,128 current_total_overtime = attendance_pool.time_sum(current_total_overtime,
@@ -135,7 +134,7 @@
135 #printing up to 4 attendances134 #printing up to 4 attendances
136 if len(attendance_ids) < 5:135 if len(attendance_ids) < 5:
137 count = 1136 count = 1
138 for attendance in sorted(attendance_pool.browse(cr, uid, attendance_ids),137 for attendance in sorted(attendance_pool.browse(cr, uid, attendance_ids, context=context),
139 key=lambda x: x['name']):138 key=lambda x: x['name']):
140 days_by_employee[employee_id][str_current_date][139 days_by_employee[employee_id][str_current_date][
141 'signin_'+str(count)] = attendance.name[11:16]140 'signin_'+str(count)] = attendance.name[11:16]
@@ -152,14 +151,13 @@
152 'overtime'151 'overtime'
153 ] = current_total_overtime152 ] = current_total_overtime
154 153
155 active_contract_ids = attendance_pool.get_active_contracts(154 reference_calendar = attendance_pool.get_reference_calendar(
156 cr, uid, int(employee_id), date=str_current_date)155 cr, uid, int(employee_id), date=str_current_date, context=context)
157 # computing due total156 # computing due total
158 if active_contract_ids:157 if reference_calendar:
159 contract = contract_pool.browse(cr, uid, active_contract_ids[0])158 if reference_calendar.attendance_ids:
160 if contract.working_hours and contract.working_hours.attendance_ids:
161 current_total_due = 0.0159 current_total_due = 0.0
162 for calendar_attendance in contract.working_hours.attendance_ids:160 for calendar_attendance in reference.attendance_ids:
163 if ((161 if ((
164 not calendar_attendance.dayofweek162 not calendar_attendance.dayofweek
165 or int(calendar_attendance.dayofweek) == current_date.weekday()163 or int(calendar_attendance.dayofweek) == current_date.weekday()
@@ -200,8 +198,8 @@
200 ('date_to', '>', str_current_date_end),198 ('date_to', '>', str_current_date_end),
201 ('state', '=', 'validate'),199 ('state', '=', 'validate'),
202 ('employee_id', '=', int(employee_id)),200 ('employee_id', '=', int(employee_id)),
203 ])201 ], context=context)
204 for holiday in holidays_pool.browse(cr, uid, holidays_ids):202 for holiday in holidays_pool.browse(cr, uid, holidays_ids, context=context):
205 date_from = datetime.strptime(holiday.date_from, '%Y-%m-%d %H:%M:%S')203 date_from = datetime.strptime(holiday.date_from, '%Y-%m-%d %H:%M:%S')
206 date_to = datetime.strptime(holiday.date_to, '%Y-%m-%d %H:%M:%S')204 date_to = datetime.strptime(holiday.date_to, '%Y-%m-%d %H:%M:%S')
207 # if beginned before today205 # if beginned before today
@@ -230,10 +228,9 @@
230 ] = attendance_pool.time_difference(228 ] = attendance_pool.time_difference(
231 current_total_inside_calendar, due_minus_leaves)229 current_total_inside_calendar, due_minus_leaves)
232230
233 if active_contract_ids:231 if reference_calendar:
234 contract = contract_pool.browse(cr, uid, active_contract_ids[0])232 if reference_calendar.leave_rounding:
235 if contract.working_hours and contract.working_hours.leave_rounding:233 float_rounding = float(reference_calendar.leave_rounding)
236 float_rounding = float(contract.working_hours.leave_rounding)
237 days_by_employee[employee_id][str_current_date][234 days_by_employee[employee_id][str_current_date][
238 'negative'235 'negative'
239 ] = math.floor(236 ] = math.floor(
@@ -272,13 +269,12 @@
272 days_by_employee[employee_id][str_date]['due'])269 days_by_employee[employee_id][str_date]['due'])
273 270
274 # computing overtime types271 # computing overtime types
275 active_contract_ids = attendance_pool.get_active_contracts(272 reference_calendar = attendance_pool.get_reference_calendar(
276 cr, uid, int(employee_id), date=str_date)273 cr, uid, int(employee_id), date=str_date, context=context)
277 if active_contract_ids:274 if reference_calendar:
278 contract = contract_pool.browse(cr, uid, active_contract_ids[0]) 275 if reference_calendar.overtime_type_ids:
279 if contract.working_hours and contract.working_hours.overtime_type_ids:
280 sorted_types = sorted(276 sorted_types = sorted(
281 contract.working_hours.overtime_type_ids,277 reference_calendar.overtime_type_ids,
282 key=lambda k: k.sequence)278 key=lambda k: k.sequence)
283 current_overtime = days_by_employee[employee_id][279 current_overtime = days_by_employee[employee_id][
284 str_date]['overtime']280 str_date]['overtime']