[FIX] hr_homeworking: fix adding/removing weekly location

This commit fixes 3 bugs

------
Prior:
Deleting a weekly record from the calendar didn't remove it from the
employee's profile
Steps:
• Have a weekly location for the employee for Wednesday
• Go to the calendar and remove Wednesday location and choose that it's
  removed for everyweek
• Check employee card
Current behavior: The weekly location for Wednesday still appears on the
employee profile.
Expected: The weekly location for Wednesday is empty

------
Prior:
Deleting a weekly record from the employee's profile removed all records
from the calendar.
Expected behavior: When a weekly location is removed from the employee's
profile only future records should be removed, the past records should
stay untouched.

------
Prior:
When hr_homeworking is installed, if there is a work location set for
the day it is shown on the employee's kanban card, but when it's not
specified it shows nothing, which can be confusing.
Expected: Show 'Unspecified' when location is not set.

task - 3439421

closes odoo/odoo#133671

X-original-commit: 9212e2ff95be61528cc9d249e6f2baec770b8907
Signed-off-by: Xavier Bol (xbo) <xbo@odoo.com>
This commit is contained in:
sofiagvaladze
2023-08-31 06:16:05 +00:00
parent 4c1d7fec82
commit 24abddacda
2 changed files with 5 additions and 4 deletions
+4 -3
View File
@@ -4,7 +4,7 @@ from collections import defaultdict
from datetime import timedelta
from dateutil.rrule import rrule, WEEKLY
from odoo import api, fields, models
from odoo import _, api, fields, models
from .hr_homeworking import DAYS
@@ -43,8 +43,9 @@ class HrEmployeeBase(models.AbstractModel):
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
employee.name_work_location_display = employee[dayfield].name if employee[dayfield] else unspecified
@api.depends(*DAYS)
def _compute_presence_icon(self):
@@ -180,5 +181,5 @@ class HrEmployeeBase(models.AbstractModel):
)
for employee, locations in read_group:
if employee.id in employee_locations_to_remove:
locations.filtered(lambda l: l.weekday in employee_locations_to_remove[employee.id]).unlink()
locations.filtered(lambda l: l.weekday in employee_locations_to_remove[employee.id]).delete_default_worklocation()
return super().write(values)
@@ -120,7 +120,6 @@ class HrEmployeeLocation(models.Model):
def add_exceptional_worklocation(self, vals):
exceptional, date, work, employee_id = self._check_exceptional_work_location(vals)
exceptional.ensure_one()
if exceptional:
exceptional.unlink()
self.env['hr.employee.location'].create({
@@ -179,6 +178,7 @@ class HrEmployeeLocation(models.Model):
def delete_default_worklocation(self):
self.ensure_one()
self.employee_id.with_context(no_loop=True).write({DAYS[self.weekday]: False})
self._save_previous_default_worklocation()
def _get_new_worklocation_vals(self, vals):