From 2ba4e04953f5cfb8a4a06c8c626086396ed27c79 Mon Sep 17 00:00:00 2001 From: Florian Damhaut Date: Mon, 21 Feb 2022 13:34:07 +0000 Subject: [PATCH] [FIX] hr_holidays: Only show time off of current company's employee Step to reproduce (Traceback): - Be in multi-company - Create a time off type with duration in hour and no company_id - Create an instance of this type on company A with a user linked to company A (need access to both) - Switch to company B Current Behaviour: - Traceback - Cannot fetch user's calendar if content of company A is not checked for convertion from Days to Hour Behaviour after PR: - We only fetch if the user related to the leave is in allowed_companies -> only fetch if the user data is available - This is also true if duration is in Days/Half-Days (GMF Approved) opw-2749258 closes odoo/odoo#88104 X-original-commit: cb5942e5461ec0fc1fa54cd249de23e4f28f8692 Signed-off-by: Kevin Baptiste --- .../time_off_calendar_employee_views.js | 2 ++ .../js/time_off_calendar/time_off_calendar_model.js | 11 +++++++++++ .../js/time_off_calendar/time_off_calendar_views.js | 2 ++ 3 files changed, 15 insertions(+) create mode 100644 addons/hr_holidays/static/src/js/time_off_calendar/time_off_calendar_model.js diff --git a/addons/hr_holidays/static/src/js/time_off_calendar/time_off_calendar_employee_views.js b/addons/hr_holidays/static/src/js/time_off_calendar/time_off_calendar_employee_views.js index 6eb95dcc328..6695c08c79e 100644 --- a/addons/hr_holidays/static/src/js/time_off_calendar/time_off_calendar_employee_views.js +++ b/addons/hr_holidays/static/src/js/time_off_calendar/time_off_calendar_employee_views.js @@ -1,12 +1,14 @@ /** @odoo-module **/ import { TimeOffCalendarEmployeeController } from "./time_off_calendar_employee_controller"; +import { TimeOffCalendarModel } from "./time_off_calendar_model"; import { TimeOffCalendarView } from "./time_off_calendar_views"; import viewRegistry from 'web.view_registry'; export const TimeOffCalendarEmployeeView = TimeOffCalendarView.extend({ config: Object.assign({}, TimeOffCalendarView.prototype.config, { Controller: TimeOffCalendarEmployeeController, + Model: TimeOffCalendarModel, }), }); diff --git a/addons/hr_holidays/static/src/js/time_off_calendar/time_off_calendar_model.js b/addons/hr_holidays/static/src/js/time_off_calendar/time_off_calendar_model.js new file mode 100644 index 00000000000..2d4d5ab338a --- /dev/null +++ b/addons/hr_holidays/static/src/js/time_off_calendar/time_off_calendar_model.js @@ -0,0 +1,11 @@ +/** @odoo-module */ + +import CalendarModel from "web.CalendarModel"; + + +export const TimeOffCalendarModel = CalendarModel.extend({ + _getFilterDomain: function() { + const company_domain = [['user_id.company_id', 'in', this.data.context.allowed_company_ids]]; + return this._super().concat(company_domain); + }, +}); diff --git a/addons/hr_holidays/static/src/js/time_off_calendar/time_off_calendar_views.js b/addons/hr_holidays/static/src/js/time_off_calendar/time_off_calendar_views.js index 19db972c1f3..2777e808e77 100644 --- a/addons/hr_holidays/static/src/js/time_off_calendar/time_off_calendar_views.js +++ b/addons/hr_holidays/static/src/js/time_off_calendar/time_off_calendar_views.js @@ -3,6 +3,7 @@ import CalendarView from "web.CalendarView"; import config from 'web.config'; import { TimeOffCalendarController } from "./time_off_calendar_controller"; +import { TimeOffCalendarModel } from "./time_off_calendar_model"; import { TimeOffCalendarRenderer } from "./time_off_calendar_renderer"; import { TimeOffPopoverRenderer } from "./time_off_popover_renderer"; import viewRegistry from 'web.view_registry'; @@ -10,6 +11,7 @@ import viewRegistry from 'web.view_registry'; export const TimeOffCalendarView = CalendarView.extend({ config: Object.assign({}, CalendarView.prototype.config, { Controller: TimeOffCalendarController, + Model: TimeOffCalendarModel, Renderer: TimeOffCalendarRenderer, }),