diff options
| author | Jinal Patel <jip@odoo.com> | 2020-06-12 12:26:12 +0000 |
|---|---|---|
| committer | Barad Mahendra <mba@openerp.com> | 2020-07-20 14:45:44 +0000 |
| commit | 950c7d415d4d2d13fc00af35b433c02e13e2948a (patch) | |
| tree | 8372a114b0a79ccb08f722fd542cad031d02c0c8 /addons | |
| parent | a9a64ffc0c5074f95e7efb1cf645dfdac5689245 (diff) | |
[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>
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/hr_holidays/models/hr_leave_allocation.py | 15 | ||||
| -rw-r--r-- | addons/hr_holidays/views/hr_leave_allocation_views.xml | 1 |
2 files changed, 10 insertions, 6 deletions
diff --git a/addons/hr_holidays/models/hr_leave_allocation.py b/addons/hr_holidays/models/hr_leave_allocation.py index 5c39867ba50..a71917c9044 100644 --- a/addons/hr_holidays/models/hr_leave_allocation.py +++ b/addons/hr_holidays/models/hr_leave_allocation.py @@ -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: diff --git a/addons/hr_holidays/views/hr_leave_allocation_views.xml b/addons/hr_holidays/views/hr_leave_allocation_views.xml index cf34ca2a195..d170e134310 100644 --- a/addons/hr_holidays/views/hr_leave_allocation_views.xml +++ b/addons/hr_holidays/views/hr_leave_allocation_views.xml @@ -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')]}"/> |
