[FIX] hr_homeworking: show location correctly

current behavior:
If you have a weekly location defined on the employee,
and a exeptional, location for that day defined on the Calendar,
the presnece icon shows weekly and not the exceptional.

Expected behavior:
Presence icon should be based on the exceptional location,
and if there are none, take the weekly one.

task-3482527

closes odoo/odoo#135191

X-original-commit: cbb4d588e3a1dd1f89f19ac3a413bd531f8a5729
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
This commit is contained in:
sofiagvaladze
2023-09-13 04:37:01 +00:00
parent 8e2d0e9f8d
commit 7e20111e48
+21 -3
View File
@@ -19,6 +19,10 @@ class HrEmployeeBase(models.AbstractModel):
friday_location_id = fields.Many2one('hr.work.location', string='Friday')
saturday_location_id = fields.Many2one('hr.work.location', string='Saturday')
sunday_location_id = fields.Many2one('hr.work.location', string='Sunday')
exceptional_location_id = fields.Many2one(
'hr.work.location', string='Current',
compute='_compute_exceptional_location_id',
help='This is the exceptional, non-weekly, location set for today.')
hr_icon_display = fields.Selection(selection_add=[('presence_home', 'At Home'),
('presence_office', 'At Office'),
('presence_other', 'At Other')])
@@ -41,18 +45,32 @@ class HrEmployeeBase(models.AbstractModel):
res['views']['list']['arch'] = res['views']['list']['arch'].replace('name_work_location_display', dayfield)
return res
@api.depends('exceptional_location_id')
def _compute_name_work_location_display(self):
dayfield = self._get_current_day_location_field()
unspecified = _('Unspecified')
for employee in self:
employee.name_work_location_display = employee[dayfield].name if employee[dayfield] else unspecified
current_location_id = employee.exceptional_location_id or employee[dayfield]
employee.name_work_location_display = current_location_id.name if current_location_id else unspecified
@api.depends(*DAYS)
def _compute_exceptional_location_id(self):
today = fields.Date.today()
current_employee_locations = self.env['hr.employee.location'].search([
('employee_id', 'in', self.ids),
('start_date', '=', today),
('weekly', '=', False)
])
employee_work_locations = {l.employee_id.id: l.work_location_id for l in current_employee_locations}
for employee in self:
employee.exceptional_location_id = employee_work_locations.get(employee.id, False)
@api.depends(*DAYS, 'exceptional_location_id')
def _compute_presence_icon(self):
super()._compute_presence_icon()
dayfield = self._get_current_day_location_field()
for employee in self:
today_employee_location_id = employee[dayfield]
today_employee_location_id = employee.exceptional_location_id or employee[dayfield]
if not today_employee_location_id or employee.hr_icon_display.startswith('presence_holiday'):
continue
employee.hr_icon_display = f'presence_{today_employee_location_id.location_type}'