[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 <kba@odoo.com>
This commit is contained in:
William Braeckman
2021-10-26 14:10:56 +00:00
parent 4a29ba94ad
commit 93cd3d295f
4 changed files with 11 additions and 12 deletions
@@ -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, [
@@ -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):
@@ -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");
@@ -118,17 +118,12 @@
Checked out at <b><t t-esc="widget.attendance.check_out_time"/></b>
<br/><b><t t-esc="widget.hours_today"/></b>
</div>
<div t-att-class="'alert ' + (widget.today_overtime_float &gt;= 0 ? 'alert-success' : 'alert-danger') + ' h3 mt0'" role="status">
Extra hours today:
<span t-esc="widget.today_overtime"/>
</div>
<t t-if="widget.total_overtime_float &gt; 0">
<div class="alert alert-success h3 mt0" role="status">
Total extra hours:
<span t-esc="widget.total_overtime"/>
</div>
</t>
<t t-if="widget.total_overtime_float &lt; 0">
<div class="alert alert-danger h3 mt0" role="status">
Total extra hours:
<span t-esc="widget.total_overtime"/>
</div>
Total extra hours: <span t-esc="widget.total_overtime"/>
</t>
<h3 class="o_hr_attendance_random_message mb24"/>
<div class="o_hr_attendance_warning_message mt24 alert alert-warning" style="display:none" role="alert"/>