diff --git a/addons/hr_holidays/models/hr_leave.py b/addons/hr_holidays/models/hr_leave.py index 0ad2618177b..649a0bfbeeb 100644 --- a/addons/hr_holidays/models/hr_leave.py +++ b/addons/hr_holidays/models/hr_leave.py @@ -318,6 +318,9 @@ class HolidaysRequest(models.Model): self.date_to = False return + if self.request_date_from > self.request_date_to: + self.request_date_to = self.request_date_from + resource_calendar_id = self.employee_id.resource_calendar_id or self.env.company.resource_calendar_id domain = [('calendar_id', '=', resource_calendar_id.id), ('display_type', '=', False)] attendances = self.env['resource.calendar.attendance'].read_group(domain, ['ids:array_agg(id)', 'hour_from:min(hour_from)', 'hour_to:max(hour_to)', 'week_type', 'dayofweek', 'day_period'], ['week_type', 'dayofweek', 'day_period'], lazy=False) diff --git a/addons/hr_holidays/models/hr_leave_type.py b/addons/hr_holidays/models/hr_leave_type.py index 73e018023eb..8d8a08c64db 100644 --- a/addons/hr_holidays/models/hr_leave_type.py +++ b/addons/hr_holidays/models/hr_leave_type.py @@ -63,6 +63,9 @@ class HolidaysType(models.Model): virtual_remaining_leaves = fields.Float( compute='_compute_leaves', search='_search_virtual_remaining_leaves', string='Virtual Remaining Time Off', help='Maximum Time Off Allowed - Time Off Already Taken - Time Off Waiting Approval') + virtual_leaves_taken = fields.Float( + compute='_compute_leaves', string='Virtual Time Off Already Taken', + help='Sum of validated and non validated time off requests.') group_days_allocation = fields.Float( compute='_compute_group_days_allocation', string='Days Allocated') group_days_leave = fields.Float( @@ -187,7 +190,7 @@ class HolidaysType(models.Model): def get_days(self, employee_id): # need to use `dict` constructor to create a dict per id - result = dict((id, dict(max_leaves=0, leaves_taken=0, remaining_leaves=0, virtual_remaining_leaves=0)) for id in self.ids) + result = dict((id, dict(max_leaves=0, leaves_taken=0, remaining_leaves=0, virtual_remaining_leaves=0, virtual_leaves_taken=0)) for id in self.ids) requests = self.env['hr.leave'].search([ ('employee_id', '=', employee_id), @@ -206,6 +209,9 @@ class HolidaysType(models.Model): status_dict['virtual_remaining_leaves'] -= (request.number_of_hours_display if request.leave_type_request_unit == 'hour' else request.number_of_days) + status_dict['virtual_leaves_taken'] += (request.number_of_hours_display + if request.leave_type_request_unit == 'hour' + else request.number_of_days) if request.state == 'validate': status_dict['leaves_taken'] += (request.number_of_hours_display if request.leave_type_request_unit == 'hour' @@ -240,6 +246,7 @@ class HolidaysType(models.Model): 'virtual_remaining_leaves': ('%.2f' % lt.virtual_remaining_leaves).rstrip('0').rstrip('.'), 'max_leaves': ('%.2f' % lt.max_leaves).rstrip('0').rstrip('.'), 'leaves_taken': ('%.2f' % lt.leaves_taken).rstrip('0').rstrip('.'), + 'virtual_leaves_taken': ('%.2f' % lt.virtual_leaves_taken).rstrip('0').rstrip('.'), 'request_unit': lt.request_unit, }, lt.allocation_type, lt.validity_stop) for lt in leave_types] @@ -266,6 +273,7 @@ class HolidaysType(models.Model): holiday_status.leaves_taken = result.get('leaves_taken', 0) holiday_status.remaining_leaves = result.get('remaining_leaves', 0) holiday_status.virtual_remaining_leaves = result.get('virtual_remaining_leaves', 0) + holiday_status.virtual_leaves_taken = result.get('virtual_leaves_taken', 0) def _compute_group_days_allocation(self): domain = [ 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 36dd3f6387e..b012aff2e1c 100644 --- a/addons/hr_holidays/static/src/js/time_off_calendar.js +++ b/addons/hr_holidays/static/src/js/time_off_calendar.js @@ -2,6 +2,7 @@ odoo.define('hr_holidays.dashboard.view_custo', function(require) { 'use strict'; var core = require('web.core'); + var CalendarPopover = require('web.CalendarPopover'); var CalendarController = require("web.CalendarController"); var CalendarRenderer = require("web.CalendarRenderer"); var CalendarView = require("web.CalendarView"); @@ -10,6 +11,18 @@ odoo.define('hr_holidays.dashboard.view_custo', function(require) { var _t = core._t; var QWeb = core.qweb; + var TimeOffCalendarPopover = CalendarPopover.extend({ + template: 'hr_holidays.calendar.popover', + + init: function (parent, eventInfo) { + this._super.apply(this, arguments); + const state = this.event.extendedProps.record.state; + this.canDelete = state && ['validate', 'refuse'].indexOf(state) === -1; + this.canEdit = state !== undefined; + this.display_name = this.event.extendedProps.record.display_name; + this.displayFields = []; + }, + }); var TimeOffCalendarController = CalendarController.extend({ events: _.extend({}, CalendarController.prototype.events, { @@ -83,7 +96,32 @@ odoo.define('hr_holidays.dashboard.view_custo', function(require) { }); }, }); - var TimeOffCalendarRenderer = CalendarRenderer.extend({ + + var TimeOffPopoverRenderer = CalendarRenderer.extend({ + config: _.extend({}, CalendarRenderer.prototype.config, { + CalendarPopover: TimeOffCalendarPopover, + }), + + _getPopoverParams: function (eventData) { + let params = this._super.apply(this, arguments); + let calendarIcon; + let state = eventData.extendedProps.record.state; + + if (state === 'validate') { + calendarIcon = 'fa-calendar-check-o'; + } else if (state === 'refuse') { + calendarIcon = 'fa-calendar-times-o'; + } else if(state) { + calendarIcon = 'fa-calendar-o'; + } + + params['title'] = eventData.extendedProps.record.display_name.split(':').slice(0, -1).join(':'); + params['template'] = QWeb.render('hr_holidays.calendar.popover.placeholder', {color: this.getColor(eventData.color_index), calendarIcon: calendarIcon}); + return params; + }, + }); + + var TimeOffCalendarRenderer = TimeOffPopoverRenderer.extend({ _render: function () { var self = this; return this._super.apply(this, arguments).then(function () { @@ -108,5 +146,15 @@ odoo.define('hr_holidays.dashboard.view_custo', function(require) { }), }); + /** + * Calendar shown in the "Everyone" menu + */ + var TimeOffCalendarAllView = CalendarView.extend({ + config: _.extend({}, CalendarView.prototype.config, { + Renderer: TimeOffPopoverRenderer, + }), + }); + viewRegistry.add('time_off_calendar', TimeOffCalendarView); + viewRegistry.add('time_off_calendar_all', TimeOffCalendarAllView); }); 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 31c1bf4f2e8..b041222d7fc 100644 --- a/addons/hr_holidays/static/src/xml/time_off_calendar.xml +++ b/addons/hr_holidays/static/src/xml/time_off_calendar.xml @@ -13,17 +13,17 @@