From c0dc12f4645d83c54247e5292c26fff45d5060ed Mon Sep 17 00:00:00 2001 From: Leonardo Pavan Rocha Date: Mon, 6 Nov 2023 10:45:40 +0100 Subject: [PATCH] [FIX] hr_homeworking: change default WL and allow deleting default WLs This commit changes the default worklocation set for the employee from "office" to false. Also, this commit adds the possibility to delete a default worklocation from the calendar view. A typo is also fixed from "exception" to "exceptions" which was causing a bug returning the worklocations. task-3584193 closes odoo/odoo#141209 Signed-off-by: Sofie Gvaladze (sgv) --- addons/hr_homeworking/models/hr_employee.py | 20 ++++----- .../src/calendar/common/calendar_model.js | 10 ++--- .../common/popover/calendar_common_popover.js | 2 +- .../hr_homeworking_calendar_controller.js | 44 +++++++++++++------ 4 files changed, 45 insertions(+), 31 deletions(-) diff --git a/addons/hr_homeworking/models/hr_employee.py b/addons/hr_homeworking/models/hr_employee.py index 95f208e4f7c..2ec269ab28d 100644 --- a/addons/hr_homeworking/models/hr_employee.py +++ b/addons/hr_homeworking/models/hr_employee.py @@ -11,17 +11,13 @@ from .hr_homeworking import DAYS class HrEmployeeBase(models.AbstractModel): _inherit = "hr.employee.base" - @api.model - def _default_location_id(self): - return self.env.ref('hr.home_work_office', raise_if_not_found=False) - - monday_location_id = fields.Many2one('hr.work.location', string='Monday', default=lambda self: self._default_location_id()) - tuesday_location_id = fields.Many2one('hr.work.location', string='Tuesday', default=lambda self: self._default_location_id()) - wednesday_location_id = fields.Many2one('hr.work.location', string='Wednesday', default=lambda self: self._default_location_id()) - thursday_location_id = fields.Many2one('hr.work.location', string='Thursday', default=lambda self: self._default_location_id()) - friday_location_id = fields.Many2one('hr.work.location', string='Friday', default=lambda self: self._default_location_id()) - saturday_location_id = fields.Many2one('hr.work.location', string='Saturday', default=lambda self: self._default_location_id()) - sunday_location_id = fields.Many2one('hr.work.location', string='Sunday', default=lambda self: self._default_location_id()) + monday_location_id = fields.Many2one('hr.work.location', string='Monday') + tuesday_location_id = fields.Many2one('hr.work.location', string='Tuesday') + wednesday_location_id = fields.Many2one('hr.work.location', string='Wednesday') + thursday_location_id = fields.Many2one('hr.work.location', string='Thursday') + 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', @@ -108,7 +104,7 @@ class HrEmployeeBase(models.AbstractModel): 'work_location_id': exception['work_location_id'][0], } employee_id = exception["employee_id"][0] - if "exception" not in work_locations_by_employee[employee_id]: + if "exceptions" not in work_locations_by_employee[employee_id]: work_locations_by_employee[employee_id]["exceptions"] = {} work_locations_by_employee[employee_id]["exceptions"][date] = exception_value diff --git a/addons/hr_homeworking/static/src/calendar/common/calendar_model.js b/addons/hr_homeworking/static/src/calendar/common/calendar_model.js index 270e09c2ec8..bd97ff128b2 100644 --- a/addons/hr_homeworking/static/src/calendar/common/calendar_model.js +++ b/addons/hr_homeworking/static/src/calendar/common/calendar_model.js @@ -35,11 +35,11 @@ patch(AttendeeCalendarModel.prototype, { const startDay = day.s; const dayISO = startDay.toISODate(); const dayName = startDay.setLocale("en").weekdayLong.toLowerCase(); - if (!(dayISO in events)) { - events[dayISO] = {}; - } for (const employeeId in res) { if (this.multiCalendar) { + if (!(dayISO in events)) { + events[dayISO] = {}; + } if (res[employeeId].exceptions && dayISO in res[employeeId].exceptions) { // check if exception for that date const { location_type } = res[employeeId].exceptions[dayISO]; @@ -56,9 +56,9 @@ patch(AttendeeCalendarModel.prototype, { } const {location_type} = res[employeeId][locationKeyName]; if (location_type in events[dayISO]) { - events[dayISO][location_type].push(this.createHomeworkingEventAt(res[employeeId], startDay, res[employeeId][`${dayName}_location_id`])); + events[dayISO][location_type].push(this.createHomeworkingEventAt(res[employeeId], startDay, res[employeeId][locationKeyName])); } else { - events[dayISO][location_type] = [this.createHomeworkingEventAt(res[employeeId], startDay, res[employeeId][`${dayName}_location_id`])]; + events[dayISO][location_type] = [this.createHomeworkingEventAt(res[employeeId], startDay, res[employeeId][locationKeyName])]; } } } else { diff --git a/addons/hr_homeworking/static/src/calendar/common/popover/calendar_common_popover.js b/addons/hr_homeworking/static/src/calendar/common/popover/calendar_common_popover.js index 72d50922192..0849a23d50b 100644 --- a/addons/hr_homeworking/static/src/calendar/common/popover/calendar_common_popover.js +++ b/addons/hr_homeworking/static/src/calendar/common/popover/calendar_common_popover.js @@ -45,7 +45,7 @@ patch(AttendeeCalendarCommonPopover.prototype, { return !('resModel' in this.props.record) || super.isEventViewable; }, get isEventDeletable() { - return super.isEventDeletable && !this.props.record.ghostEvent; + return super.isEventDeletable; }, get displayAttendeeAnswerChoice() { return !('resModel' in this.props.record) && super.displayAttendeeAnswerChoice; diff --git a/addons/hr_homeworking/static/src/calendar/hr_homeworking_calendar_controller.js b/addons/hr_homeworking/static/src/calendar/hr_homeworking_calendar_controller.js index 22d5fb889bb..f44e4d259bf 100644 --- a/addons/hr_homeworking/static/src/calendar/hr_homeworking_calendar_controller.js +++ b/addons/hr_homeworking/static/src/calendar/hr_homeworking_calendar_controller.js @@ -45,19 +45,37 @@ patch(AttendeeCalendarController.prototype, { } }, deleteRecord(record) { - if (record.id && record.homeworking && !record.ghostEvent) { - this.displayDialog(ConfirmationDialog, { - title: _t("Confirmation"), - body: _t("Are you sure you want to delete this exception?"), - confirm: () => { - this.orm.call('hr.employee.location', "unlink", [ - record.id, - ]); - this.model.load(); - }, - cancel: () => { - }, - }); + if (record.id && record.homeworking) { + if (record.ghostEvent) { + this.displayDialog(ConfirmationDialog, { + title: _t("Confirmation"), + body: _t("Are you sure you want to delete this location?"), + confirm: () => { + const dayName = record.start.setLocale("en").weekdayLong.toLowerCase(); + const locationField = `${dayName}_location_id`; + this.orm.call('hr.employee', "write", [ + [record.rawRecord.employee_id], + {[locationField]: false} + ]); + this.model.load(); + }, + cancel: () => { + }, + }); + } else { + this.displayDialog(ConfirmationDialog, { + title: _t("Confirmation"), + body: _t("Are you sure you want to delete this exception?"), + confirm: () => { + this.orm.call('hr.employee.location', "unlink", [ + record.id, + ]); + this.model.load(); + }, + cancel: () => { + }, + }); + } } else { super.deleteRecord(...arguments) }