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: Superseded
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: 458 lines (+140/-98) (has conflicts)
2 files modified
hr_attendance_analysis/hr_attendance.py (+69/-46)
hr_attendance_analysis/wizard/print_calendar_report.py (+71/-52)
Text conflict in hr_attendance_analysis/hr_attendance.py
Text conflict in hr_attendance_analysis/wizard/print_calendar_report.py
To merge this branch: bzr merge lp:~laetitia-gangloff/hr-timesheet/hr_attendance_analysis_externalise_contract_calendar
Reviewer Review Type Date Requested Status
Pedro Manuel Baeza Needs Resubmitting
Guewen Baconnier @ Camptocamp Needs Resubmitting
Lorenzo Battistini (community) Needs Fixing
Review via email: mp+182565@code.launchpad.net

This proposal has been superseded by a proposal from 2013-11-19.

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 :

LGTM

review: Approve (code review, no test)
Revision history for this message
Lorenzo Battistini (elbati) wrote :
review: Needs Fixing
54. By Laetitia Gangloff (Acsone)

hr_attendance_analysis: externalise contract calendar

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

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 :

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
55. By Laetitia Gangloff (Acsone)

revert last commit

Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

There are still conflicts. Can you check ?

review: Needs Resubmitting
Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

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 :

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 :

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

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

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

Unmerged revisions

55. By Laetitia Gangloff (Acsone)

revert last commit

54. By Laetitia Gangloff (Acsone)

hr_attendance_analysis: externalise contract calendar

53. By Laetitia Gangloff (Acsone)

hr_attendance_analysis: externalise contract calendar

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-09-10 14:55:43 +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,24 @@
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:
152<<<<<<< TREE
150 employee = self.pool.get('hr.employee').browse(cr,uid,employee_id)153 employee = self.pool.get('hr.employee').browse(cr,uid,employee_id)
151 raise orm.except_orm(_('Error'), _(154 raise orm.except_orm(_('Error'), _(
155=======
156 employee = self.pool.get('hr.employee').browse(cr,uid,employee_id, context=context)
157 raise orm.except_orm(_('Error'), _(
158>>>>>>> MERGE-SOURCE
152 'Too many active contracts for employee %s'159 'Too many active contracts for employee %s'
153 ) % employee.name)160<<<<<<< TREE
161 ) % employee.name)
162=======
163 ) % employee.name)
164 if active_contract_ids:
165 contract = contract_pool.browse(cr, uid, active_contract_ids[0], context=context)
166 return contract.working_hours
167>>>>>>> MERGE-SOURCE
154 return active_contract_ids168 return active_contract_ids
155169
156 def _ceil_rounding(self, rounding, datetime):170 def _ceil_rounding(self, rounding, datetime):
@@ -165,10 +179,9 @@
165179
166 def _get_attendance_duration(self, cr, uid, ids, field_name, arg, context=None):180 def _get_attendance_duration(self, cr, uid, ids, field_name, arg, context=None):
167 res = {}181 res = {}
168 contract_pool = self.pool.get('hr.contract')
169 resource_pool = self.pool.get('resource.resource')182 resource_pool = self.pool.get('resource.resource')
170 attendance_pool = self.pool.get('resource.calendar.attendance')183 attendance_pool = self.pool.get('resource.calendar.attendance')
171 precision = self.pool.get('res.users').browse(cr, uid, uid).company_id.working_time_precision184 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 context185 # 2012.10.16 LF FIX : Get timezone from context
173 active_tz = pytz.timezone(context.get("tz","UTC") if context else "UTC")186 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')187 str_now = datetime.strftime(datetime.now(), '%Y-%m-%d %H:%M:%S')
@@ -176,7 +189,7 @@
176 duration = 0.0189 duration = 0.0
177 outside_calendar_duration = 0.0190 outside_calendar_duration = 0.0
178 inside_calendar_duration = 0.0191 inside_calendar_duration = 0.0
179 attendance = self.browse(cr, uid, attendance_id)192 attendance = self.browse(cr, uid, attendance_id, context=context)
180 res[attendance.id] = {}193 res[attendance.id] = {}
181 # 2012.10.16 LF FIX : Attendance in context timezone194 # 2012.10.16 LF FIX : Attendance in context timezone
182 attendance_start = datetime.strptime(195 attendance_start = datetime.strptime(
@@ -188,9 +201,9 @@
188 if attendance.action == 'sign_in':201 if attendance.action == 'sign_in':
189 next_attendance_ids = self.search(cr, uid, [202 next_attendance_ids = self.search(cr, uid, [
190 ('employee_id', '=', attendance.employee_id.id),203 ('employee_id', '=', attendance.employee_id.id),
191 ('name', '>', attendance.name)], order='name')204 ('name', '>', attendance.name)], order='name', context=context)
192 if next_attendance_ids:205 if next_attendance_ids:
193 next_attendance = self.browse(cr, uid, next_attendance_ids[0])206 next_attendance = self.browse(cr, uid, next_attendance_ids[0], context=context)
194 if next_attendance.action == 'sign_in':207 if next_attendance.action == 'sign_in':
195 # 2012.10.16 LF FIX : Attendance in context timezone208 # 2012.10.16 LF FIX : Attendance in context timezone
196 raise orm.except_orm(_('Error'), _(209 raise orm.except_orm(_('Error'), _(
@@ -206,13 +219,14 @@
206 duration = round(duration / precision) * precision219 duration = round(duration / precision) * precision
207 res[attendance.id]['duration'] = duration220 res[attendance.id]['duration'] = duration
208 res[attendance.id]['end_datetime'] = next_attendance_date221 res[attendance.id]['end_datetime'] = next_attendance_date
209 # If contract is not specified: working days = 24/7222 # If calendar is not specified: working days = 24/7
210 res[attendance.id]['inside_calendar_duration'] = duration223 res[attendance.id]['inside_calendar_duration'] = duration
211 res[attendance.id]['outside_calendar_duration'] = 0.0224 res[attendance.id]['outside_calendar_duration'] = 0.0
212225
213 active_contract_ids = self.get_active_contracts(226 reference_calendar = self.get_reference_calendar(
214 cr, uid, attendance.employee_id.id, date=str_now[:10])227 cr, uid, attendance.employee_id.id, date=str_now[:10], context=context)
215228
229<<<<<<< TREE
216 if active_contract_ids and next_attendance_ids:230 if active_contract_ids and next_attendance_ids:
217 contract = contract_pool.browse(cr, uid, active_contract_ids[0])231 contract = contract_pool.browse(cr, uid, active_contract_ids[0])
218 if contract.working_hours:232 if contract.working_hours:
@@ -224,6 +238,23 @@
224 rounded_stop_hour = self._floor_rounding(238 rounded_stop_hour = self._floor_rounding(
225 float_attendance_rounding, attendance_stop)239 float_attendance_rounding, attendance_stop)
226 240
241=======
242 if reference_calendar and next_attendance_ids:
243 # TODO applicare prima arrotondamento o tolleranza?
244 if reference_calendar.attendance_rounding:
245 float_attendance_rounding = float(reference_calendar.attendance_rounding)
246 rounded_start_hour = self._ceil_rounding(
247 float_attendance_rounding, attendance_start)
248 rounded_stop_hour = self._floor_rounding(
249 float_attendance_rounding, attendance_stop)
250
251 if abs(1- rounded_start_hour) < 0.01: # if shift == 1 hour
252 attendance_start = datetime(attendance_start.year, attendance_start.month,
253 attendance_start.day, attendance_start.hour + 1)
254 else:
255 attendance_start = datetime(attendance_start.year, attendance_start.month,
256 attendance_start.day, attendance_start.hour, int(round(rounded_start_hour * 60.0)))
257>>>>>>> MERGE-SOURCE
227 if abs(1- rounded_start_hour) < 0.01: # if shift == 1 hour258 if abs(1- rounded_start_hour) < 0.01: # if shift == 1 hour
228 attendance_start = datetime(attendance_start.year, attendance_start.month,259 attendance_start = datetime(attendance_start.year, attendance_start.month,
229 attendance_start.day, attendance_start.hour + 1)260 attendance_start.day, attendance_start.hour + 1)
@@ -243,7 +274,7 @@
243 274
244 res[attendance.id]['inside_calendar_duration'] = 0.0275 res[attendance.id]['inside_calendar_duration'] = 0.0
245 res[attendance.id]['outside_calendar_duration'] = 0.0276 res[attendance.id]['outside_calendar_duration'] = 0.0
246 calendar_id = contract.working_hours.id277 calendar_id = reference_calendar.id
247 intervals_within = 0278 intervals_within = 0
248279
249 # split attendance in intervals = precision280 # split attendance in intervals = precision
@@ -273,7 +304,7 @@
273 ('calendar_id','=',calendar_id),304 ('calendar_id','=',calendar_id),
274 ('hour_to','>=',centered_attendance_hour),305 ('hour_to','>=',centered_attendance_hour),
275 ('hour_from','<=',centered_attendance_hour),306 ('hour_from','<=',centered_attendance_hour),
276 ])307 ], context=context)
277 if len(matched_schedule_ids) > 1:308 if len(matched_schedule_ids) > 1:
278 raise orm.except_orm(_('Error'),309 raise orm.except_orm(_('Error'),
279 _('Wrongly configured working schedule with id %s') % str(calendar_id))310 _('Wrongly configured working schedule with id %s') % str(calendar_id))
@@ -281,7 +312,7 @@
281 intervals_within += 1312 intervals_within += 1
282 # sign in tolerance313 # sign in tolerance
283 if intervals_within == 1:314 if intervals_within == 1:
284 calendar_attendance = attendance_pool.browse(cr, uid, matched_schedule_ids[0])315 calendar_attendance = attendance_pool.browse(cr, uid, matched_schedule_ids[0], context=context)
285 attendance_start_hour = (316 attendance_start_hour = (
286 attendance_start.hour + attendance_start.minute / 60.0317 attendance_start.hour + attendance_start.minute / 60.0
287 + attendance_start.second / 60.0 / 60.0318 + attendance_start.second / 60.0 / 60.0
@@ -302,7 +333,7 @@
302 attendance_stop.hour + attendance_stop.minute / 60.0333 attendance_stop.hour + attendance_stop.minute / 60.0
303 + attendance_stop.second / 60.0 / 60.0334 + attendance_stop.second / 60.0 / 60.0
304 )335 )
305 calendar_attendance = attendance_pool.browse(cr, uid, matched_schedule_ids[0])336 calendar_attendance = attendance_pool.browse(cr, uid, matched_schedule_ids[0], context=context)
306 if attendance_stop_hour <= (337 if attendance_stop_hour <= (
307 calendar_attendance.hour_to and338 calendar_attendance.hour_to and
308 (attendance_stop_hour - (calendar_attendance.hour_to -339 (attendance_stop_hour - (calendar_attendance.hour_to -
@@ -321,13 +352,13 @@
321 res[attendance.id]['inside_calendar_duration'],352 res[attendance.id]['inside_calendar_duration'],
322 res[attendance.id]['duration'])353 res[attendance.id]['duration'])
323354
324 if contract.working_hours.overtime_rounding:355 if reference_calendar.overtime_rounding:
325 if res[attendance.id]['outside_calendar_duration']:356 if res[attendance.id]['outside_calendar_duration']:
326 overtime = res[attendance.id]['outside_calendar_duration']357 overtime = res[attendance.id]['outside_calendar_duration']
327 if contract.working_hours.overtime_rounding_tolerance:358 if reference_calendar.overtime_rounding_tolerance:
328 overtime = self.time_sum(overtime,359 overtime = self.time_sum(overtime,
329 contract.working_hours.overtime_rounding_tolerance)360 reference_calendar.overtime_rounding_tolerance)
330 float_overtime_rounding = float(contract.working_hours.overtime_rounding)361 float_overtime_rounding = float(reference_calendar.overtime_rounding)
331 res[attendance.id]['outside_calendar_duration'] = math.floor(362 res[attendance.id]['outside_calendar_duration'] = math.floor(
332 overtime * float_overtime_rounding) / float_overtime_rounding363 overtime * float_overtime_rounding) / float_overtime_rounding
333364
@@ -337,7 +368,7 @@
337 attendance_ids = []368 attendance_ids = []
338 attendance_pool = self.pool.get('hr.attendance')369 attendance_pool = self.pool.get('hr.attendance')
339 for contract in self.pool.get('hr.contract').browse(cr, uid, ids, context=context):370 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)])371 att_ids = attendance_pool.search(cr, uid, [('employee_id', '=', contract.employee_id.id)], context=context)
341 for att_id in att_ids:372 for att_id in att_ids:
342 if att_id not in attendance_ids:373 if att_id not in attendance_ids:
343 attendance_ids.append(att_id)374 attendance_ids.append(att_id)
@@ -348,7 +379,7 @@
348 attendance_pool = self.pool.get('hr.attendance')379 attendance_pool = self.pool.get('hr.attendance')
349 contract_pool = self.pool.get('hr.contract')380 contract_pool = self.pool.get('hr.contract')
350 for calendar in self.pool.get('resource.calendar').browse(cr, uid, ids, context=context):381 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)])382 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)383 att_ids = attendance_pool._get_by_contracts(cr, uid, contract_ids, context=None)
353 for att_id in att_ids:384 for att_id in att_ids:
354 if att_id not in attendance_ids:385 if att_id not in attendance_ids:
@@ -373,47 +404,39 @@
373 elif attendance.action == 'sign_out':404 elif attendance.action == 'sign_out':
374 previous_attendance_ids = self.search(cr, uid, [405 previous_attendance_ids = self.search(cr, uid, [
375 ('employee_id', '=', attendance.employee_id.id),406 ('employee_id', '=', attendance.employee_id.id),
407<<<<<<< TREE
376 ('name', '<', attendance.name),408 ('name', '<', attendance.name),
377 ('action', '=', 'sign_in'),409 ('action', '=', 'sign_in'),
378 ], order='name')410 ], order='name')
411=======
412 ('name', '<', attendance.name),
413 ('action', '=', 'sign_in'),
414 ], order='name', context=context)
415>>>>>>> MERGE-SOURCE
379 if previous_attendance_ids and previous_attendance_ids[len(previous_attendance_ids) - 1] not in attendance_ids:416 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]) 417 attendance_ids.append(previous_attendance_ids[len(previous_attendance_ids) - 1])
381 return attendance_ids418 return attendance_ids
382419
383 _inherit = "hr.attendance"420 _inherit = "hr.attendance"
384421
422 _store_rules = {
423 'hr.attendance': (_get_attendances, ['name', 'action', 'employee_id'], 20),
424 'hr.contract': (_get_by_contracts, ['employee_id', 'date_start', 'date_end', 'trial_date_start', 'trial_date_end', 'working_hours'], 20),
425 'resource.calendar': (_get_by_calendars, ['attendance_ids'], 20),
426 'resource.calendar.attendance': (_get_by_calendar_attendances, ['dayofweek', 'date_from', 'hour_from', 'hour_to', 'calendar_id'], 20),
427 }
428
385 _columns = {429 _columns = {
386 'duration': fields.function(_get_attendance_duration, method=True, multi='duration', string="Attendance duration",430 'duration': fields.function(_get_attendance_duration, method=True, multi='duration', string="Attendance duration",
387 store={431 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",432 'end_datetime': fields.function(_get_attendance_duration, method=True, multi='duration', type="datetime", string="End date time",
395 store={433 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',434 'outside_calendar_duration': fields.function(_get_attendance_duration, method=True, multi='duration',
402 string="Overtime",435 string="Overtime",
403 store={436 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',437 'inside_calendar_duration': fields.function(_get_attendance_duration, method=True, multi='duration',
410 string="Duration within working schedule",438 string="Duration within working schedule",
411 store={439 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 }440 }
418441
419442
420443
=== 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-09-10 14:55:43 +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,9 +151,10 @@
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
157<<<<<<< TREE
158 if active_contract_ids:158 if active_contract_ids:
159 contract = contract_pool.browse(cr, uid, active_contract_ids[0])159 contract = contract_pool.browse(cr, uid, active_contract_ids[0])
160 if contract.working_hours and contract.working_hours.attendance_ids:160 if contract.working_hours and contract.working_hours.attendance_ids:
@@ -178,6 +178,29 @@
178 current_total_due = attendance_pool.time_sum(current_total_due, 178 current_total_due = attendance_pool.time_sum(current_total_due,
179 calendar_attendance_duration)179 calendar_attendance_duration)
180 180
181=======
182 if reference_calendar and reference_calendar.attendance_ids:
183 current_total_due = 0.0
184 for calendar_attendance in reference_calendar.attendance_ids:
185 if ((
186 not calendar_attendance.dayofweek
187 or int(calendar_attendance.dayofweek) == current_date.weekday()
188 )
189 and (
190 not calendar_attendance.date_from or
191 datetime.strptime(calendar_attendance.date_from,'%Y-%m-%d')
192 <= current_date
193 )):
194 calendar_attendance_duration = attendance_pool.time_difference(
195 calendar_attendance.hour_from, calendar_attendance.hour_to)
196 if calendar_attendance_duration < 0:
197 raise orm.except_orm(_('Error'),
198 _("%s: 'Work to' is < 'Work from'")
199 % calendar_attendance.name)
200 current_total_due = attendance_pool.time_sum(current_total_due,
201 calendar_attendance_duration)
202
203>>>>>>> MERGE-SOURCE
181 days_by_employee[employee_id][str_current_date]['due'] = current_total_due204 days_by_employee[employee_id][str_current_date]['due'] = current_total_due
182205
183 # computing leaves206 # computing leaves
@@ -200,8 +223,8 @@
200 ('date_to', '>', str_current_date_end),223 ('date_to', '>', str_current_date_end),
201 ('state', '=', 'validate'),224 ('state', '=', 'validate'),
202 ('employee_id', '=', int(employee_id)),225 ('employee_id', '=', int(employee_id)),
203 ])226 ], context=context)
204 for holiday in holidays_pool.browse(cr, uid, holidays_ids):227 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')228 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')229 date_to = datetime.strptime(holiday.date_to, '%Y-%m-%d %H:%M:%S')
207 # if beginned before today230 # if beginned before today
@@ -230,17 +253,15 @@
230 ] = attendance_pool.time_difference(253 ] = attendance_pool.time_difference(
231 current_total_inside_calendar, due_minus_leaves)254 current_total_inside_calendar, due_minus_leaves)
232255
233 if active_contract_ids:256 if reference_calendar and reference_calendar.leave_rounding:
234 contract = contract_pool.browse(cr, uid, active_contract_ids[0])257 float_rounding = float(reference_calendar.leave_rounding)
235 if contract.working_hours and contract.working_hours.leave_rounding:258 days_by_employee[employee_id][str_current_date][
236 float_rounding = float(contract.working_hours.leave_rounding)259 'negative'
237 days_by_employee[employee_id][str_current_date][260 ] = math.floor(
238 'negative'261 days_by_employee[employee_id][str_current_date]['negative'] *
239 ] = math.floor(262 float_rounding
240 days_by_employee[employee_id][str_current_date]['negative'] *263 ) / float_rounding
241 float_rounding264
242 ) / float_rounding
243
244 day_count += 1265 day_count += 1
245266
246 totals_by_employee = {}267 totals_by_employee = {}
@@ -272,36 +293,34 @@
272 days_by_employee[employee_id][str_date]['due'])293 days_by_employee[employee_id][str_date]['due'])
273 294
274 # computing overtime types295 # computing overtime types
275 active_contract_ids = attendance_pool.get_active_contracts(296 reference_calendar = attendance_pool.get_reference_calendar(
276 cr, uid, int(employee_id), date=str_date)297 cr, uid, int(employee_id), date=str_date, context=context)
277 if active_contract_ids:298 if reference_calendar and reference_calendar.overtime_type_ids:
278 contract = contract_pool.browse(cr, uid, active_contract_ids[0]) 299 sorted_types = sorted(
279 if contract.working_hours and contract.working_hours.overtime_type_ids:300 reference_calendar.overtime_type_ids,
280 sorted_types = sorted(301 key=lambda k: k.sequence)
281 contract.working_hours.overtime_type_ids,302 current_overtime = days_by_employee[employee_id][
282 key=lambda k: k.sequence)303 str_date]['overtime']
283 current_overtime = days_by_employee[employee_id][304 for overtime_type in sorted_types:
284 str_date]['overtime']305 if not totals_by_employee[employee_id]['total_types'].get(
285 for overtime_type in sorted_types:306 overtime_type.name, False):
286 if not totals_by_employee[employee_id]['total_types'].get(307 totals_by_employee[employee_id]['total_types'][
287 overtime_type.name, False):308 overtime_type.name] = 0.0
288 totals_by_employee[employee_id]['total_types'][309 if current_overtime:
289 overtime_type.name] = 0.0310 if current_overtime <= overtime_type.limit or not overtime_type.limit:
290 if current_overtime:311 totals_by_employee[employee_id]['total_types'][
291 if current_overtime <= overtime_type.limit or not overtime_type.limit:312 overtime_type.name] = attendance_pool.time_sum(
292 totals_by_employee[employee_id]['total_types'][313 totals_by_employee[employee_id]
293 overtime_type.name] = attendance_pool.time_sum(314 ['total_types'][overtime_type.name],
294 totals_by_employee[employee_id]315 current_overtime)
295 ['total_types'][overtime_type.name],316 current_overtime = 0.0
296 current_overtime)317 else:
297 current_overtime = 0.0318 totals_by_employee[employee_id]['total_types'][
298 else:319 overtime_type.name] = attendance_pool.time_sum(
299 totals_by_employee[employee_id]['total_types'][320 totals_by_employee[employee_id]['total_types']
300 overtime_type.name] = attendance_pool.time_sum(321 [overtime_type.name], overtime_type.limit)
301 totals_by_employee[employee_id]['total_types']322 current_overtime = attendance_pool.time_difference(overtime_type.limit,
302 [overtime_type.name], overtime_type.limit)323 current_overtime)
303 current_overtime = attendance_pool.time_difference(overtime_type.limit,
304 current_overtime)
305324
306 days_by_employee[employee_id][str_date][325 days_by_employee[employee_id][str_date][
307 'attendances'326 'attendances'
308327
=== modified file 'timesheet_task/project_task.py'