From 5cc42022fc159e71ccd2dde122ddde80dd66e23e Mon Sep 17 00:00:00 2001 From: nia-odoo Date: Mon, 9 Mar 2020 09:38:16 +0000 Subject: [PATCH] [IMP] hr_holidays: Allow to select start date for accruals for allocation Currently it was not possible select start date for accruals leave allocation. it was default taken as today's date. So purpose of this task is to make start date field of accrual time off visible so user do not have to wait until day to add a day off In this commit, we make start date field of accrual time off visible with default value as today and also check for the start date in cron method. closes odoo/odoo#46811 Taskid: 2199326 Closes: #46811 Signed-off-by: Yannick Tivisse (yti) --- addons/hr_holidays/models/hr_leave_allocation.py | 7 +++---- .../hr_holidays/views/hr_leave_allocation_views.xml | 11 ++++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/addons/hr_holidays/models/hr_leave_allocation.py b/addons/hr_holidays/models/hr_leave_allocation.py index 60aa7985ad8..0f69967cbeb 100644 --- a/addons/hr_holidays/models/hr_leave_allocation.py +++ b/addons/hr_holidays/models/hr_leave_allocation.py @@ -56,7 +56,7 @@ class HolidaysAllocation(models.Model): "\nThe status is 'Refused', when an allocation request is refused by manager." + "\nThe status is 'Approved', when an allocation request is approved by manager.") date_from = fields.Datetime( - 'Start Date', readonly=True, index=True, copy=False, + 'Start Date', readonly=True, index=True, copy=False, default=fields.Date.context_today, states={'draft': [('readonly', False)], 'confirm': [('readonly', False)]}, tracking=True) date_to = fields.Datetime( 'End Date', readonly=True, copy=False, @@ -188,7 +188,7 @@ class HolidaysAllocation(models.Model): # in order to not allocate him/her too much leaves start_date = holiday.employee_id._get_date_start_work() # If employee is created after the period, we cancel the computation - if period_end <= start_date: + if period_end <= start_date or period_end < holiday.date_from: holiday.write(values) continue @@ -399,8 +399,6 @@ class HolidaysAllocation(models.Model): @api.model def create(self, values): """ Override to avoid automatic logging of creation """ - if values.get('allocation_type', 'regular') == 'accrual': - values['date_from'] = fields.Datetime.now() employee_id = values.get('employee_id', False) if not values.get('department_id'): values.update({'department_id': self.env['hr.employee'].browse(employee_id).department_id.id}) @@ -446,6 +444,7 @@ class HolidaysAllocation(models.Model): 'parent_id': self.id, 'employee_id': employee.id, 'allocation_type': self.allocation_type, + 'date_from': self.date_from, 'date_to': self.date_to, 'interval_unit': self.interval_unit, 'interval_number': self.interval_number, diff --git a/addons/hr_holidays/views/hr_leave_allocation_views.xml b/addons/hr_holidays/views/hr_leave_allocation_views.xml index 68212af9c7f..e2d66fb694b 100644 --- a/addons/hr_holidays/views/hr_leave_allocation_views.xml +++ b/addons/hr_holidays/views/hr_leave_allocation_views.xml @@ -159,12 +159,13 @@ 0 -