[REF] hr: Split hr_icon_display into two separate fields.
The icon that is displayed in the employee kanban view is determined by the field hr_icon_display, computed in the method _compute_hr_icon_display. This method is overridden in multiple modules such as hr_holidays, hr_attendance and hr_homeworking. Currently this field has a state to show no icon (presence_undetermined). In this change this state is extracted into the a separate field show_hr_icon_display with the default state of hr_icon_display being presence_to_define. In this way a module such as hr_attendance, which only overrides _compute_hr_icon_display to show the default icon for everyone as a default, now only needs to change this separate field and does not need any knowledge of what other states exist. This reduces coupling between modules.
This commit is contained in:
@@ -57,6 +57,7 @@ class HrEmployeeBase(models.AbstractModel):
|
||||
('presence_absent', 'Absent'),
|
||||
('presence_to_define', 'To define'),
|
||||
('presence_undetermined', 'Undetermined')], compute='_compute_presence_icon')
|
||||
show_hr_icon_display = fields.Boolean(compute='_compute_presence_icon')
|
||||
employee_type = fields.Selection([
|
||||
('employee', 'Employee'),
|
||||
('student', 'Student'),
|
||||
@@ -174,6 +175,7 @@ class HrEmployeeBase(models.AbstractModel):
|
||||
"""
|
||||
working_now_list = self.filtered(lambda e: e.hr_presence_state == 'present')._get_employee_working_now()
|
||||
for employee in self:
|
||||
show_icon = True
|
||||
if employee.hr_presence_state == 'present':
|
||||
if employee.id in working_now_list:
|
||||
icon = 'presence_present'
|
||||
@@ -185,13 +187,13 @@ class HrEmployeeBase(models.AbstractModel):
|
||||
else:
|
||||
# without attendance, default employee state is 'to_define' without confirmed presence/absence
|
||||
# we need to check why they are not there
|
||||
if employee.user_id:
|
||||
# Display an orange icon on internal users.
|
||||
icon = 'presence_to_define'
|
||||
else:
|
||||
# Display an orange icon on internal users.
|
||||
icon = 'presence_to_define'
|
||||
if not employee.user_id:
|
||||
# We don't want non-user employee to have icon.
|
||||
icon = 'presence_undetermined'
|
||||
show_icon = False
|
||||
employee.hr_icon_display = icon
|
||||
employee.show_hr_icon_display = show_icon
|
||||
|
||||
@api.depends('address_id')
|
||||
def _compute_work_location_id(self):
|
||||
|
||||
@@ -124,6 +124,7 @@
|
||||
<field name="user_partner_id"/>
|
||||
<field name="last_activity"/>
|
||||
<field name="hr_icon_display"/>
|
||||
<field name="show_hr_icon_display"/>
|
||||
<field name="image_128" />
|
||||
<templates>
|
||||
<t t-name="kanban-box">
|
||||
@@ -135,36 +136,38 @@
|
||||
<div class="o_kanban_record_top">
|
||||
<div class="o_kanban_record_headings">
|
||||
<strong class="o_kanban_record_title">
|
||||
<div class="float-end"
|
||||
t-if="record.hr_icon_display.raw_value == 'presence_present'">
|
||||
<!-- Employee is present/connected and it is normal according to his work schedule -->
|
||||
<span class="fa fa-circle text-success" role="img" aria-label="Present"
|
||||
title="Present" name="presence_present">
|
||||
</span>
|
||||
</div>
|
||||
<div class="float-end"
|
||||
t-if="record.hr_icon_display.raw_value == 'presence_absent'">
|
||||
<!-- Employee is absent and it is normal according to his work schedule -->
|
||||
<span class="fa fa-circle-o text-muted" role="img" aria-label="Absent"
|
||||
title="Absent" name="presence_absent">
|
||||
</span>
|
||||
</div>
|
||||
<div class="float-end"
|
||||
t-if="record.hr_icon_display.raw_value == 'presence_absent_active'">
|
||||
<!-- Employee is connected but according to his work schedule, he should not work for now -->
|
||||
<span class="fa fa-circle-o text-success" role="img"
|
||||
aria-label="Present but not active"
|
||||
title="Present but not active" name="presence_absent_active">
|
||||
</span>
|
||||
</div>
|
||||
<!-- Employee is not here but according to his work schedule, he should be connected -->
|
||||
<div class="float-end"
|
||||
t-if="record.hr_icon_display.raw_value == 'presence_to_define'">
|
||||
<span class="fa fa-circle text-warning" role="img"
|
||||
aria-label="To define" title="To define"
|
||||
name="presence_to_define">
|
||||
</span>
|
||||
</div>
|
||||
<t t-if="record.show_hr_icon_display.raw_value">
|
||||
<div class="float-end"
|
||||
t-if="record.hr_icon_display.raw_value == 'presence_present'">
|
||||
<!-- Employee is present/connected and it is normal according to his work schedule -->
|
||||
<span class="fa fa-circle text-success" role="img" aria-label="Present"
|
||||
title="Present" name="presence_present">
|
||||
</span>
|
||||
</div>
|
||||
<div class="float-end"
|
||||
t-if="record.hr_icon_display.raw_value == 'presence_absent'">
|
||||
<!-- Employee is absent and it is normal according to his work schedule -->
|
||||
<span class="fa fa-circle-o text-muted" role="img" aria-label="Absent"
|
||||
title="Absent" name="presence_absent">
|
||||
</span>
|
||||
</div>
|
||||
<div class="float-end"
|
||||
t-if="record.hr_icon_display.raw_value == 'presence_absent_active'">
|
||||
<!-- Employee is connected but according to his work schedule, he should not work for now -->
|
||||
<span class="fa fa-circle-o text-success" role="img"
|
||||
aria-label="Present but not active"
|
||||
title="Present but not active" name="presence_absent_active">
|
||||
</span>
|
||||
</div>
|
||||
<!-- Employee is not here but according to his work schedule, he should be connected -->
|
||||
<div class="float-end"
|
||||
t-if="record.hr_icon_display.raw_value == 'presence_to_define'">
|
||||
<span class="fa fa-circle text-warning" role="img"
|
||||
aria-label="To define" title="To define"
|
||||
name="presence_to_define">
|
||||
</span>
|
||||
</div>
|
||||
</t>
|
||||
<field name="name"/>
|
||||
</strong>
|
||||
<span t-if="record.job_title.raw_value" class="o_kanban_record_subtitle"><field name="job_title"/></span>
|
||||
|
||||
@@ -265,6 +265,7 @@
|
||||
<field name="user_id"/>
|
||||
<field name="user_partner_id"/>
|
||||
<field name="hr_icon_display"/>
|
||||
<field name="show_hr_icon_display"/>
|
||||
<field name="image_128" />
|
||||
<templates>
|
||||
<t t-name="kanban-box">
|
||||
@@ -276,42 +277,44 @@
|
||||
<div class="o_kanban_record_top">
|
||||
<div class="o_kanban_record_headings">
|
||||
<strong class="o_kanban_record_title">
|
||||
<div class="float-end"
|
||||
t-if="record.hr_icon_display.raw_value == 'presence_present'"
|
||||
name="presence_present">
|
||||
<!-- Employee is present/connected and it is normal according to his work schedule -->
|
||||
<span class="fa fa-circle text-success" role="img" aria-label="Present"
|
||||
title="Present" name="presence_present">
|
||||
</span>
|
||||
</div>
|
||||
<div class="float-end"
|
||||
t-if="record.hr_icon_display.raw_value == 'presence_absent'"
|
||||
name="presence_absent">
|
||||
<!-- Employee is not present and it is normal according to his work schedule -->
|
||||
<span class="fa fa-circle-o text-muted" role="img" aria-label="Absent"
|
||||
title="Absent" name="presence_absent">
|
||||
</span>
|
||||
</div>
|
||||
<div class="float-end"
|
||||
t-if="record.hr_icon_display.raw_value == 'presence_absent_active'"
|
||||
name="presence_absent_active">
|
||||
<!-- Employee is connected but according to his work schedule,
|
||||
he should not work for now -->
|
||||
<span class="fa fa-circle-o text-success" role="img"
|
||||
aria-label="Present but not active"
|
||||
title="Present but not active"
|
||||
name="presence_absent_active">
|
||||
</span>
|
||||
</div>
|
||||
<div class="float-end"
|
||||
t-if="record.hr_icon_display.raw_value == 'presence_to_define'"
|
||||
name="presence_to_define">
|
||||
<!-- Employee is not here but according to his work schedule, he should be connected -->
|
||||
<span class="fa fa-circle text-warning" role="img"
|
||||
aria-label="To define" title="To define"
|
||||
name="presence_to_define">
|
||||
</span>
|
||||
</div>
|
||||
<t t-if="record.show_hr_icon_display.raw_value">
|
||||
<div class="float-end"
|
||||
t-if="record.hr_icon_display.raw_value == 'presence_present'"
|
||||
name="presence_present">
|
||||
<!-- Employee is present/connected and it is normal according to his work schedule -->
|
||||
<span class="fa fa-circle text-success" role="img" aria-label="Present"
|
||||
title="Present" name="presence_present">
|
||||
</span>
|
||||
</div>
|
||||
<div class="float-end"
|
||||
t-if="record.hr_icon_display.raw_value == 'presence_absent'"
|
||||
name="presence_absent">
|
||||
<!-- Employee is not present and it is normal according to his work schedule -->
|
||||
<span class="fa fa-circle-o text-muted" role="img" aria-label="Absent"
|
||||
title="Absent" name="presence_absent">
|
||||
</span>
|
||||
</div>
|
||||
<div class="float-end"
|
||||
t-if="record.hr_icon_display.raw_value == 'presence_absent_active'"
|
||||
name="presence_absent_active">
|
||||
<!-- Employee is connected but according to his work schedule,
|
||||
he should not work for now -->
|
||||
<span class="fa fa-circle-o text-success" role="img"
|
||||
aria-label="Present but not active"
|
||||
title="Present but not active"
|
||||
name="presence_absent_active">
|
||||
</span>
|
||||
</div>
|
||||
<div class="float-end"
|
||||
t-if="record.hr_icon_display.raw_value == 'presence_to_define'"
|
||||
name="presence_to_define">
|
||||
<!-- Employee is not here but according to his work schedule, he should be connected -->
|
||||
<span class="fa fa-circle text-warning" role="img"
|
||||
aria-label="To define" title="To define"
|
||||
name="presence_to_define">
|
||||
</span>
|
||||
</div>
|
||||
</t>
|
||||
<field name="name" placeholder="Employee's Name"/>
|
||||
</strong>
|
||||
<span t-if="record.job_title.raw_value" class="o_kanban_record_subtitle"><field name="job_title"/></span>
|
||||
|
||||
@@ -205,6 +205,5 @@ class HrEmployee(models.Model):
|
||||
def _compute_presence_icon(self):
|
||||
res = super()._compute_presence_icon()
|
||||
# All employee must chek in or check out. Everybody must have an icon
|
||||
employee_to_define = self.filtered(lambda e: e.hr_icon_display == 'presence_undetermined')
|
||||
employee_to_define.hr_icon_display = 'presence_to_define'
|
||||
self.filtered(lambda employee: not employee.show_hr_icon_display).show_hr_icon_display = True
|
||||
return res
|
||||
|
||||
@@ -121,11 +121,11 @@ class HrEmployeeBase(models.AbstractModel):
|
||||
def _compute_presence_icon(self):
|
||||
super()._compute_presence_icon()
|
||||
employees_absent = self.filtered(lambda employee:
|
||||
employee.hr_icon_display not in ['presence_present', 'presence_absent_active']
|
||||
employee.hr_presence_state != 'present'
|
||||
and employee.is_absent)
|
||||
employees_absent.update({'hr_icon_display': 'presence_holiday_absent'})
|
||||
employees_present = self.filtered(lambda employee:
|
||||
employee.hr_icon_display in ['presence_present', 'presence_absent_active']
|
||||
employee.hr_presence_state == 'present'
|
||||
and employee.is_absent)
|
||||
employees_present.update({'hr_icon_display': 'presence_holiday_present'})
|
||||
|
||||
|
||||
@@ -91,7 +91,8 @@
|
||||
<xpath expr="//templates" position="before">
|
||||
<field name="is_absent"/>
|
||||
</xpath>
|
||||
<xpath expr="//strong[hasclass('o_kanban_record_title')]" position="inside">
|
||||
<xpath expr="//strong[hasclass('o_kanban_record_title')]" position="inside"
|
||||
t-if="record.show_hr_icon_display.raw_value">
|
||||
<!-- Employee is absent, in holiday but he is connected -->
|
||||
<div class="float-end"
|
||||
t-if="record.hr_icon_display.raw_value == 'presence_holiday_present'">
|
||||
@@ -121,7 +122,8 @@
|
||||
<field name="leave_date_to"/>
|
||||
<field name="is_absent"/>
|
||||
</xpath>
|
||||
<xpath expr="//div[@name='presence_absent_active']" position="after">
|
||||
<xpath expr="//div[@name='presence_absent_active']" position="after"
|
||||
t-if="record.show_hr_icon_display.raw_value">
|
||||
<!-- Employee is absent, in holiday but he is connected -->
|
||||
<!-- green plane -->
|
||||
<div class="float-end"
|
||||
|
||||
Reference in New Issue
Block a user