From 93cd3d295f62fd926f86649b1614d5b28dfbf25e Mon Sep 17 00:00:00 2001 From: William Braeckman Date: Tue, 5 Oct 2021 08:19:36 +0000 Subject: [PATCH] [IMP] hr_attendance: improve overtime display on attendance closing Improves on the display when closing an attendance to display today's overtime aswell as the total overtime the employee has. Also small cleanup, remove unused variable. TaskId-2655689 closes odoo/odoo#77841 Signed-off-by: Kevin Baptiste --- addons/hr_attendance/models/hr_attendance.py | 1 - addons/hr_attendance/models/hr_employee.py | 3 +++ .../static/src/js/greeting_message.js | 4 +++- .../hr_attendance/static/src/xml/attendance.xml | 15 +++++---------- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/addons/hr_attendance/models/hr_attendance.py b/addons/hr_attendance/models/hr_attendance.py index c91ad6530e6..7750d70818c 100644 --- a/addons/hr_attendance/models/hr_attendance.py +++ b/addons/hr_attendance/models/hr_attendance.py @@ -140,7 +140,6 @@ class HrAttendance(models.Model): for emp, attendance_dates in employee_attendance_dates.items(): # get_attendances_dates returns the date translated from the local timezone without tzinfo, # and contains all the date which we need to check for overtime - emp_tz = pytz.timezone(emp._get_tz()) attendance_domain = [] for attendance_date in attendance_dates: attendance_domain = OR([attendance_domain, [ diff --git a/addons/hr_attendance/models/hr_employee.py b/addons/hr_attendance/models/hr_employee.py index 258bf1f5082..6c730d3c178 100644 --- a/addons/hr_attendance/models/hr_employee.py +++ b/addons/hr_attendance/models/hr_employee.py @@ -165,6 +165,9 @@ class HrEmployee(models.Model): modified_attendance = employee._attendance_action_change() action_message['attendance'] = modified_attendance.read()[0] action_message['total_overtime'] = employee.total_overtime + # Overtime have an unique constraint on the day, no need for limit=1 + action_message['overtime_today'] = self.env['hr.attendance.overtime'].sudo().search([ + ('employee_id', '=', employee.id), ('date', '=', fields.Date.context_today(self)), ('adjustment', '=', False)]).duration or 0 return {'action': action_message} def _attendance_action_change(self): diff --git a/addons/hr_attendance/static/src/js/greeting_message.js b/addons/hr_attendance/static/src/js/greeting_message.js index 3c816087b36..eb8f0e5f9dc 100644 --- a/addons/hr_attendance/static/src/js/greeting_message.js +++ b/addons/hr_attendance/static/src/js/greeting_message.js @@ -55,7 +55,9 @@ var GreetingMessage = AbstractAction.extend({ // extra hours amount displayed in the greeting message template. this.total_overtime_float = action.total_overtime; // Used for comparison in template - this.total_overtime = field_utils.format.float_time(this.total_overtime_float) + this.total_overtime = field_utils.format.float_time(this.total_overtime_float); + this.today_overtime_float = action.overtime_today; + this.today_overtime = field_utils.format.float_time(this.today_overtime_float); if (action.hours_today) { var duration = moment.duration(action.hours_today, "hours"); diff --git a/addons/hr_attendance/static/src/xml/attendance.xml b/addons/hr_attendance/static/src/xml/attendance.xml index 787c9ebbb92..00b6356bd13 100644 --- a/addons/hr_attendance/static/src/xml/attendance.xml +++ b/addons/hr_attendance/static/src/xml/attendance.xml @@ -118,17 +118,12 @@ Checked out at
+
+ Extra hours today: + +
-
- Total extra hours: - -
-
- -
- Total extra hours: - -
+ Total extra hours: