From 09e515eecc5610c8af0c3989b5b023ad435ca437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Lef=C3=A8vre?= Date: Thu, 2 May 2019 15:35:35 +0200 Subject: [PATCH] [IMP] hr_holidays: Improve usability This commit improves screens usability in the Time Off app. The following points have been changed: 1. For leaves and allocations, add buttons on the kanban card to directly approve or refuse if it's not already validated. 2. On the leave kanban card, only display the dates, not the full datetime. 3. Add a description to the activity created when a leave/allocation needs to be approved by someone. 4. Allocation are now sorted in the list view, more recent firsts. 5. In the allocation form view, add a stat button to know how many leaves has been allocated and how many has been taken for the allocation leave type. The button redirects to the employee's leaves of the leave type. Only shown for holiday type 'emloyee'. 6. In the leave form view, there are currently two duration fields for managers. The readonly duration is an informative field for regular employees and the editable duration is meant for managers, it's used if the number of days needs to be manually set for some reason. Make sure the manager only sees the editable duration fields. 7. From "My Dashboard", the creation form view should not be the manager form view (default view) which has additional unecessary fields when requesting a leave for yourself (`employee_id`, `holiday_type`, ect). It's now showing the form view for regular employees. Task 1961713 --- addons/hr_holidays/models/hr_leave.py | 8 +- .../hr_holidays/models/hr_leave_allocation.py | 14 +++ .../static/src/js/time_off_calendar.js | 9 +- .../views/hr_leave_allocation_views.xml | 44 ++++++++- .../hr_holidays/views/hr_leave_template.xml | 6 ++ addons/hr_holidays/views/hr_leave_views.xml | 99 ++++++++++++++++--- 6 files changed, 149 insertions(+), 31 deletions(-) diff --git a/addons/hr_holidays/models/hr_leave.py b/addons/hr_holidays/models/hr_leave.py index 7e24529c4af..54680fcc4f4 100644 --- a/addons/hr_holidays/models/hr_leave.py +++ b/addons/hr_holidays/models/hr_leave.py @@ -138,8 +138,7 @@ class HolidaysRequest(models.Model): default=fields.Datetime.now, states={'draft': [('readonly', False)], 'confirm': [('readonly', False)]}, tracking=True) number_of_days = fields.Float( - 'Duration (Days)', copy=False, readonly=True, tracking=True, - states={'draft': [('readonly', False)], 'confirm': [('readonly', False)]}, + 'Duration (Days)', copy=False, tracking=True, help='Number of days of the time off request. Used in the calculation. To manually correct the duration, use this field.') number_of_days_display = fields.Float( 'Duration in days', compute='_compute_number_of_days_display', copy=False, readonly=True, @@ -469,7 +468,7 @@ class HolidaysRequest(models.Model): target = leave.employee_id.name res.append( (leave.id, - _("%s on %s :%.2f day(s)") % + _("%s on %s: %.2f day(s)") % (target, leave.holiday_status_id.name, leave.number_of_days)) ) return res @@ -817,16 +816,19 @@ class HolidaysRequest(models.Model): def activity_update(self): to_clean, to_do = self.env['hr.leave'], self.env['hr.leave'] for holiday in self: + note = _('New %s Request created by %s from %s to %s') % (holiday.holiday_status_id.name, holiday.create_uid.name, fields.Datetime.to_string(holiday.date_from), fields.Datetime.to_string(holiday.date_to)) if holiday.state == 'draft': to_clean |= holiday elif holiday.state == 'confirm': holiday.activity_schedule( 'hr_holidays.mail_act_leave_approval', + note=note, user_id=holiday.sudo()._get_responsible_for_approval().id) elif holiday.state == 'validate1': holiday.activity_feedback(['hr_holidays.mail_act_leave_approval']) holiday.activity_schedule( 'hr_holidays.mail_act_leave_second_approval', + note=note, user_id=holiday.sudo()._get_responsible_for_approval().id) elif holiday.state == 'validate': to_do |= holiday diff --git a/addons/hr_holidays/models/hr_leave_allocation.py b/addons/hr_holidays/models/hr_leave_allocation.py index bee454c074e..287a94224f7 100644 --- a/addons/hr_holidays/models/hr_leave_allocation.py +++ b/addons/hr_holidays/models/hr_leave_allocation.py @@ -21,6 +21,7 @@ class HolidaysAllocation(models.Model): """ Allocation Requests Access specifications: similar to leave requests """ _name = "hr.leave.allocation" _description = "Time Off Allocation" + _order = "create_date desc" _inherit = ['mail.thread', 'mail.activity.mixin'] _mail_post_access = 'read' @@ -126,6 +127,8 @@ class HolidaysAllocation(models.Model): ('years', 'Year(s)') ], string="Unit of time between two intervals", default='weeks', readonly=True, states={'draft': [('readonly', False)], 'confirm': [('readonly', False)]}) nextcall = fields.Date("Date of the next accrual allocation", default=False, readonly=True) + max_leaves = fields.Float(compute='_compute_leaves') + leaves_taken = fields.Float(compute='_compute_leaves') _sql_constraints = [ ('type_value', @@ -197,6 +200,14 @@ class HolidaysAllocation(models.Model): holiday.write(values) + @api.multi + @api.depends('employee_id', 'holiday_status_id') + def _compute_leaves(self): + for allocation in self: + leave_type = allocation.holiday_status_id.with_context(employee_id=allocation.employee_id.id) + allocation.max_leaves = leave_type.max_leaves + allocation.leaves_taken = leave_type.leaves_taken + @api.multi @api.depends('number_of_days') def _compute_number_of_days_display(self): @@ -565,16 +576,19 @@ class HolidaysAllocation(models.Model): def activity_update(self): to_clean, to_do = self.env['hr.leave.allocation'], self.env['hr.leave.allocation'] for allocation in self: + note = _('New Allocation Request created by %s: %s Days of %s') % (allocation.create_uid.name, allocation.number_of_days, allocation.holiday_status_id.name) if allocation.state == 'draft': to_clean |= allocation elif allocation.state == 'confirm': allocation.activity_schedule( 'hr_holidays.mail_act_leave_allocation_approval', + note=note, user_id=allocation.sudo()._get_responsible_for_approval().id) elif allocation.state == 'validate1': allocation.activity_feedback(['hr_holidays.mail_act_leave_allocation_approval']) allocation.activity_schedule( 'hr_holidays.mail_act_leave_allocation_second_approval', + note=note, user_id=allocation.sudo()._get_responsible_for_approval().id) elif allocation.state == 'validate': to_do |= allocation 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 1f9f5fc6cdf..b9bc4785f57 100644 --- a/addons/hr_holidays/static/src/js/time_off_calendar.js +++ b/addons/hr_holidays/static/src/js/time_off_calendar.js @@ -150,13 +150,8 @@ odoo.define('hr_holidays.dashboard.view_custo', function(require) { */ _onNewTimeOff: function () { var self = this; - this.do_action({ - type: 'ir.actions.act_window', - res_model: 'hr.leave', - view_type: 'form', - views: [[false,'form']], - target: 'new', - }, { + + this.do_action('hr_holidays.hr_leave_action_my_request', { on_close: function () { self.reload(); } diff --git a/addons/hr_holidays/views/hr_leave_allocation_views.xml b/addons/hr_holidays/views/hr_leave_allocation_views.xml index 88f32e18dca..6cbcf8eb62a 100644 --- a/addons/hr_holidays/views/hr_leave_allocation_views.xml +++ b/addons/hr_holidays/views/hr_leave_allocation_views.xml @@ -55,11 +55,32 @@
+
+
+ +

@@ -230,6 +251,8 @@ + + +
+
+
+ + + +
+
+
+
+ + + +
+
diff --git a/addons/hr_holidays/views/hr_leave_template.xml b/addons/hr_holidays/views/hr_leave_template.xml index 17000934502..736bc0512d0 100644 --- a/addons/hr_holidays/views/hr_leave_template.xml +++ b/addons/hr_holidays/views/hr_leave_template.xml @@ -3,9 +3,15 @@ + diff --git a/addons/hr_holidays/views/hr_leave_views.xml b/addons/hr_holidays/views/hr_leave_views.xml index 6e3e4daf94e..93381f54285 100644 --- a/addons/hr_holidays/views/hr_leave_views.xml +++ b/addons/hr_holidays/views/hr_leave_views.xml @@ -46,6 +46,7 @@ domain="[('activity_ids.date_deadline', '<', context_today().strftime('%Y-%m-%d'))]" help="Show all records which has next action date is before today"/> + +
-
from
-
-
-
to
-
+
+
+ from + + to + +
+
+
+
+
+ + + +
+
+
+
+ + + +
@@ -188,6 +204,11 @@ +
+

+ +

+
@@ -258,13 +279,16 @@
- -