[FIX] hr_homeworking: show correct colors in homeworking icons
Since the early versions of the homeworking modules, we were showing incorrect colors for the homeworking icons if the partner_id was too large. This comes from the fact that we were not using the getColor helper from calendar to decide which color to render. Since we have a limited amount of colors, we should not use the partner id to define the color, but actually cycle through all the possible colors, which is done by the getColor method. Also, when getting the homeworking data, it was possible to get partner_id as false when the employee had no related user. This commit also changes this to fallback on the work_contact_id if no user is set. task-3561678 closes odoo/odoo#139167 Signed-off-by: Bertrand Dossogne (bedo) <bedo@odoo.com>
This commit is contained in:
@@ -77,10 +77,12 @@ class HrEmployeeBase(models.AbstractModel):
|
||||
def _get_worklocation(self, start_date, end_date):
|
||||
work_locations_by_employee = defaultdict(dict)
|
||||
for employee in self:
|
||||
work_locations_by_employee[employee.id]["user_id"] = employee.user_id.id
|
||||
work_locations_by_employee[employee.id]["employee_id"] = employee.id
|
||||
work_locations_by_employee[employee.id]["partner_id"] = employee.user_partner_id.id
|
||||
work_locations_by_employee[employee.id]["employee_name"] = employee.name
|
||||
work_locations_by_employee[employee.id].update({
|
||||
"user_id": employee.user_id.id,
|
||||
"employee_id": employee.id,
|
||||
"partner_id": employee.user_partner_id.id or employee.work_contact_id.id,
|
||||
"employee_name": employee.name
|
||||
})
|
||||
|
||||
for day in DAYS:
|
||||
work_locations_by_employee[employee.id][day] = {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import { AttendeeCalendarModel } from "@calendar/views/attendee_calendar/attendee_calendar_model";
|
||||
import { serializeDateTime } from "@web/core/l10n/dates";
|
||||
import { getColor } from "@web/views/calendar/colors";
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
|
||||
const { Interval } = luxon;
|
||||
@@ -113,10 +114,11 @@ patch(AttendeeCalendarModel.prototype, {
|
||||
get worklocations() {
|
||||
return this.data.worklocations;
|
||||
},
|
||||
|
||||
mapPartnersToColor(data) {
|
||||
return data.filterSections.partner_ids.filters
|
||||
.filter(filter => filter.type !== "all" && filter.value)
|
||||
.reduce((map, partner) => ({ ...map, [partner.value]: partner.colorIndex}), {})
|
||||
.reduce((map, partner) => ({ ...map, [partner.value]: getColor(partner.colorIndex)}), {})
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user