[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) <sgv@odoo.com>
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user