[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.
This commit is contained in:
Yannick Tivisse
2018-11-07 16:30:29 +00:00
parent 32051efdc9
commit 1c391c3dfb
+1
View File
@@ -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):