From ec25487cfbf388ebd1b10d3db60657e39bbaa809 Mon Sep 17 00:00:00 2001 From: Giacomello Nathan Date: Thu, 10 Sep 2020 16:29:51 +0200 Subject: [PATCH] [IMP] Time Off: Year Calendar ajustments A new calendar view has been added, the "year" view. Some modifications should be done on this view, more specialy in "Time Off" application. Problems were the fact that it was hard to see if a time off has been approved or not. Another was the fact that week-ends & public holidays were not grey. This commit change year calendar in Time Off module. More specially, this commit: - Change default calendar in personal dashboard to "year" - Gray week-ends & public holiday (based on the worker's calendar) - Hatch non-approved time off - Removed a calendar view from My Time Off Requests - Fix a "cancel" button that doesn't work - Add a new view that is displayed when there is no filter to show on the filter view for calendars Task id #2318645 Task id #2317525 --- addons/hr_holidays/models/hr_leave.py | 11 ++++++-- .../hr_holidays/models/hr_leave_allocation.py | 4 +-- .../report/hr_leave_report_calendar.py | 5 +++- .../report/hr_leave_report_calendar.xml | 1 + .../static/src/js/time_off_calendar.js | 26 ++++++++++++++++--- .../hr_holidays/static/src/scss/time_off.scss | 6 ++++- .../static/src/xml/time_off_calendar.xml | 14 ++++++++++ addons/hr_holidays/views/hr_leave_views.xml | 8 +++--- 8 files changed, 62 insertions(+), 13 deletions(-) diff --git a/addons/hr_holidays/models/hr_leave.py b/addons/hr_holidays/models/hr_leave.py index 1b82c77662d..bcd52facd13 100644 --- a/addons/hr_holidays/models/hr_leave.py +++ b/addons/hr_holidays/models/hr_leave.py @@ -256,6 +256,8 @@ class HolidaysRequest(models.Model): request_unit_half = fields.Boolean('Half Day', compute='_compute_request_unit_half', store=True, readonly=False) request_unit_hours = fields.Boolean('Custom Hours', compute='_compute_request_unit_hours', store=True, readonly=False) request_unit_custom = fields.Boolean('Days-long custom hours', compute='_compute_request_unit_custom', store=True, readonly=False) + # view + is_hatched = fields.Boolean('Hatched', compute='_compute_is_hatched') _sql_constraints = [ ('type_value', @@ -282,7 +284,7 @@ class HolidaysRequest(models.Model): is_officer = self.user_has_groups('hr_holidays.group_hr_holidays_user') for leave in self: - if is_officer or leave.user_id == self.env.user or leave.manager_id == self.env.user: + if is_officer or leave.user_id == self.env.user or leave.employee_id.leave_manager_id == self.env.user: leave.name = leave.sudo().private_name else: leave.name = '*****' @@ -291,7 +293,7 @@ class HolidaysRequest(models.Model): is_officer = self.user_has_groups('hr_holidays.group_hr_holidays_user') for leave in self: - if is_officer or leave.user_id == self.env.user or leave.manager_id == self.env.user: + if is_officer or leave.user_id == self.env.user or leave.employee_id.leave_manager_id == self.env.user: leave.sudo().private_name = leave.name def _search_description(self, operator, value): @@ -548,6 +550,11 @@ class HolidaysRequest(models.Model): else: holiday.can_approve = True + @api.depends('state') + def _compute_is_hatched(self): + for holiday in self: + holiday.is_hatched = holiday.state not in ['refuse', 'validate'] + @api.constrains('date_from', 'date_to', 'employee_id') def _check_date(self): for holiday in self.filtered('employee_id'): diff --git a/addons/hr_holidays/models/hr_leave_allocation.py b/addons/hr_holidays/models/hr_leave_allocation.py index f92c72b15af..c4896756a01 100644 --- a/addons/hr_holidays/models/hr_leave_allocation.py +++ b/addons/hr_holidays/models/hr_leave_allocation.py @@ -229,7 +229,7 @@ class HolidaysAllocation(models.Model): is_officer = self.env.user.has_group('hr_holidays.group_hr_holidays_user') for allocation in self: - if is_officer or allocation.employee_id.user_id == self.env.user or allocation.manager_id == self.env.user: + if is_officer or allocation.employee_id.user_id == self.env.user or allocation.employee_id.leave_manager_id == self.env.user: allocation.name = allocation.sudo().private_name else: allocation.name = '*****' @@ -237,7 +237,7 @@ class HolidaysAllocation(models.Model): def _inverse_description(self): is_officer = self.env.user.has_group('hr_holidays.group_hr_holidays_user') for allocation in self: - if is_officer or allocation.employee_id.user_id == self.env.user or allocation.manager_id == self.env.user: + if is_officer or allocation.employee_id.user_id == self.env.user or allocation.employee_id.leave_manager_id == self.env.user: allocation.sudo().private_name = allocation.name def _search_description(self, operator, value): diff --git a/addons/hr_holidays/report/hr_leave_report_calendar.py b/addons/hr_holidays/report/hr_leave_report_calendar.py index 0a5b45db9c6..1dd3cd1288a 100644 --- a/addons/hr_holidays/report/hr_leave_report_calendar.py +++ b/addons/hr_holidays/report/hr_leave_report_calendar.py @@ -28,6 +28,8 @@ class LeaveReportCalendar(models.Model): ('validate', 'Approved') ], readonly=True) + is_hatched = fields.Boolean('Hatched', readonly=True) + def init(self): tools.drop_view_if_exists(self._cr, 'hr_leave_report_calendar') self._cr.execute("""CREATE OR REPLACE VIEW hr_leave_report_calendar AS @@ -42,7 +44,8 @@ class LeaveReportCalendar(models.Model): CASE WHEN hl.holiday_type = 'employee' THEN rr.tz ELSE %s - END AS tz + END AS tz, + state != 'validate' as is_hatched FROM hr_leave hl LEFT JOIN hr_employee em ON em.id = hl.employee_id diff --git a/addons/hr_holidays/report/hr_leave_report_calendar.xml b/addons/hr_holidays/report/hr_leave_report_calendar.xml index c7f8a78e477..a62f10faa1e 100644 --- a/addons/hr_holidays/report/hr_leave_report_calendar.xml +++ b/addons/hr_holidays/report/hr_leave_report_calendar.xml @@ -19,6 +19,7 @@ + diff --git a/addons/hr_holidays/static/src/js/time_off_calendar.js b/addons/hr_holidays/static/src/js/time_off_calendar.js index ef9f262d861..3f863de98bf 100644 --- a/addons/hr_holidays/static/src/js/time_off_calendar.js +++ b/addons/hr_holidays/static/src/js/time_off_calendar.js @@ -138,6 +138,20 @@ odoo.define('hr_holidays.dashboard.view_custo', function(require) { var self = this; return this._super.apply(this, arguments).then(function () { self.$el.parent().find('.o_calendar_mini').hide(); + + // Check if there is a filter to display on the sidebar + // If there is no filter, hide the sidebar + const noFilters = !Object.values(self.state.filters).some(f => f.filters.length); + + // Remove the no data sidebar + self.$sidebar.find('#o_calendar_filter_no_data').remove(); + if (noFilters) { + // Show a special sidebar + self.$sidebar.html(QWeb.render('hr_holidays.calendar.sidebar.nofilter', { + title: 'Time Off Type', + description: '(no data)' + })); + } }); }, }); @@ -154,10 +168,14 @@ odoo.define('hr_holidays.dashboard.view_custo', function(require) { }).then(function (result) { self.$el.parent().find('.o_calendar_mini').hide(); self.$el.parent().find('.o_timeoff_container').remove(); - var elem = QWeb.render('hr_holidays.dashboard_calendar_header', { - timeoffs: result, - }); - self.$el.before(elem); + + // Do not display header if there is no element to display + if (result.length > 0) { + var elem = QWeb.render('hr_holidays.dashboard_calendar_header', { + timeoffs: result, + }); + self.$el.before(elem); + } }); }, }); diff --git a/addons/hr_holidays/static/src/scss/time_off.scss b/addons/hr_holidays/static/src/scss/time_off.scss index f37b89caf03..ffd80c80722 100644 --- a/addons/hr_holidays/static/src/scss/time_off.scss +++ b/addons/hr_holidays/static/src/scss/time_off.scss @@ -1,10 +1,14 @@ .o_timeoff_calendar .o_content { .o_timeoff_container { height: 6rem; + + + .o_calendar_container { + height: calc(100% - 6rem); + } } .o_calendar_container { - height: calc(100% - 6rem); + height: 100%; } @include media-breakpoint-down(sm) { diff --git a/addons/hr_holidays/static/src/xml/time_off_calendar.xml b/addons/hr_holidays/static/src/xml/time_off_calendar.xml index b041222d7fc..97397fc8d5b 100644 --- a/addons/hr_holidays/static/src/xml/time_off_calendar.xml +++ b/addons/hr_holidays/static/src/xml/time_off_calendar.xml @@ -75,4 +75,18 @@ + + +
+
+
+
+

+ + +

+
+
+
+
diff --git a/addons/hr_holidays/views/hr_leave_views.xml b/addons/hr_holidays/views/hr_leave_views.xml index be46d191e47..1ee485953d5 100644 --- a/addons/hr_holidays/views/hr_leave_views.xml +++ b/addons/hr_holidays/views/hr_leave_views.xml @@ -353,10 +353,11 @@ hr.leave.view.dashboard hr.leave - + + @@ -432,10 +433,11 @@ hr.leave.view.calendar hr.leave - + + @@ -605,7 +607,7 @@ My Time Off Requests ir.actions.act_window hr.leave - tree,form,calendar,kanban,activity + tree,form,kanban,activity {} [('user_id', '=', uid)]