[FIX] hr_holidays: Fix the automatic change of duration in allocation

In the commit, https://github.com/odoo/odoo/commit/3bd345597fa932abdaf780f72bacf331690f549b#diff-4b74c5cd47565e7fbe2a526d12a577c4L300
which convert the onchange to compute, there was onchage on
number_of_hours_display and on number_of_days_display which
going to write the value to number_of_days. but it was missed
in above commit so value was no upated in number_of_days.

So due to that when we try to allocate the duration in terms of days
or hours in time off allocarion and save it, it will be automatically
takes the default value.

So in this commit, Fix the issue and update the number of days based on
number_of_days_display and number_of_hours_display also set the default
value for number of days/hours when change allocation type or holiday
status type.

closes odoo/odoo#54715

Taskid: 2275933
Closes: #53014
X-original-commit: 5fe6ae94bb61cc27f8f3326408d749680e4f79e1
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
This commit is contained in:
Jinal Patel
2020-07-20 14:45:44 +00:00
committed by Barad Mahendra
parent a9a64ffc0c
commit 950c7d415d
2 changed files with 10 additions and 6 deletions
@@ -69,7 +69,7 @@ class HolidaysAllocation(models.Model):
notes = fields.Text('Reasons', readonly=True, states={'draft': [('readonly', False)], 'confirm': [('readonly', False)]})
# duration
number_of_days = fields.Float(
'Number of Days', compute='_compute_from_holiday_status_id', store=True, readonly=False, tracking=True,
'Number of Days', compute='_compute_from_holiday_status_id', store=True, readonly=False, tracking=True, default=1,
help='Duration in days. Reference field to use when necessary.')
number_of_days_display = fields.Float(
'Duration (days)', compute='_compute_number_of_days_display',
@@ -260,8 +260,10 @@ class HolidaysAllocation(models.Model):
for allocation in self:
if allocation.parent_id and allocation.parent_id.type_request_unit == "hour":
allocation.number_of_hours_display = allocation.number_of_days * HOURS_PER_DAY
else:
elif allocation.number_of_days:
allocation.number_of_hours_display = allocation.number_of_days * (allocation.employee_id.sudo().resource_id.calendar_id.hours_per_day or HOURS_PER_DAY)
else:
allocation.number_of_hours_display = 0.0
@api.depends('number_of_hours_display', 'number_of_days_display')
def _compute_duration_display(self):
@@ -339,12 +341,14 @@ class HolidaysAllocation(models.Model):
elif not holiday.holiday_status_id and not holiday._origin.holiday_status_id:
holiday.holiday_status_id = default_holiday_status_id
@api.depends('holiday_status_id', 'allocation_type')
@api.depends('holiday_status_id', 'allocation_type', 'number_of_hours_display', 'number_of_days_display')
def _compute_from_holiday_status_id(self):
for allocation in self:
allocation.number_of_days = allocation.number_of_days_display
if allocation.type_request_unit == 'hour':
allocation.number_of_days = allocation.number_of_hours_display / (allocation.employee_id.sudo().resource_calendar_id.hours_per_day or HOURS_PER_DAY)
# set default values
if not allocation.number_of_days and not allocation._origin.number_of_days:
allocation.number_of_days = 1
if not allocation.interval_number and not allocation._origin.interval_number:
allocation.interval_number = 1
if not allocation.number_per_interval and not allocation._origin.number_per_interval:
@@ -360,7 +364,6 @@ class HolidaysAllocation(models.Model):
allocation.date_to = new_date_to
if allocation.allocation_type == 'accrual':
allocation.number_of_days = 0
if allocation.holiday_status_id.request_unit == 'hour':
allocation.unit_per_interval = 'hours'
else:
@@ -90,6 +90,7 @@
<field name="allocation_type" invisible="1" widget="radio"/>
<field name="number_of_days_display" invisible="1"/>
<field name="number_of_days" invisible="1"/>
<div class="o_td_label">
<label for="number_of_days" string="Duration" attrs="{'invisible': [('allocation_type', '=', 'accrual')]}"/>