From 24abddacdac35cb5ef1c5082aa3b8fa2bf9cad61 Mon Sep 17 00:00:00 2001 From: sofiagvaladze Date: Wed, 30 Aug 2023 11:17:35 +0200 Subject: [PATCH] [FIX] hr_homeworking: fix adding/removing weekly location MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- addons/hr_homeworking/models/hr_employee.py | 7 ++++--- addons/hr_homeworking/models/hr_homeworking.py | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/addons/hr_homeworking/models/hr_employee.py b/addons/hr_homeworking/models/hr_employee.py index 20f444d5d39..74ec77f073d 100644 --- a/addons/hr_homeworking/models/hr_employee.py +++ b/addons/hr_homeworking/models/hr_employee.py @@ -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) diff --git a/addons/hr_homeworking/models/hr_homeworking.py b/addons/hr_homeworking/models/hr_homeworking.py index 270ccf38a81..f957b1007b5 100644 --- a/addons/hr_homeworking/models/hr_homeworking.py +++ b/addons/hr_homeworking/models/hr_homeworking.py @@ -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):