From 1c391c3dfbdf733304fc882b9045d25e20e6dd1f Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Wed, 7 Nov 2018 16:15:21 +0000 Subject: [PATCH] [FIX] hr_holidays: Correctly compute number_of_days on form loading On a hr.leave creation on the form view, the fields request_date_from and request_date_to are set on today. The fields date_from and date_to are set on now. We have 2 onchange methods: - _onchange_request_parameters: Set date_from and date_to according to the leave configuration. - _onchange_leave_dates: Set number_of_days according to date_from and date_to As _onchange_leave_dates is called before _onchange_request_parameters, the field number_of_day is always set to 0, even if the leave is taken for all the day (the default value). It means that if you don't modify the dates, the value stored in the database is incorrect. We have to call manually the method _onchange_leave_dates at the end of the method _onchange_request_parameters execution to ensure the validity of the value. --- addons/hr_holidays/models/hr_leave.py | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/hr_holidays/models/hr_leave.py b/addons/hr_holidays/models/hr_leave.py index 16b10a6c83b..b2f8197917f 100644 --- a/addons/hr_holidays/models/hr_leave.py +++ b/addons/hr_holidays/models/hr_leave.py @@ -293,6 +293,7 @@ class HolidaysRequest(models.Model): tz = self.env.user.tz if self.env.user.tz and not self.request_unit_custom else 'UTC' # custom -> already in UTC self.date_from = timezone(tz).localize(datetime.combine(self.request_date_from, hour_from)).astimezone(UTC).replace(tzinfo=None) self.date_to = timezone(tz).localize(datetime.combine(self.request_date_to, hour_to)).astimezone(UTC).replace(tzinfo=None) + self._onchange_leave_dates() @api.onchange('request_unit_half') def _onchange_request_unit_half(self):