Odoo Mindscape. Understand Odoo faster. Explore modules, fields, dependencies and version differences in one place instead of digging through the source code.
Module: Time Off
Entity: hr.leave
Compute Method: _compute_date_from_to
| Inputs | Method | Outputs |
|---|---|---|
|
- for holiday in self: - if not holiday.request_date_from: + if self.env.context.get('leave_skip_date_from_to_computation'): + for leave in self: + leave.date_from = leave._origin.date_from or leave.date_from + leave.date_to = leave._origin.date_to or leave.date_to + return + for leave in self.filtered('source_leave_id'): + leave.date_from = leave._origin.date_from + leave.date_to = leave._origin.date_to + trimmed_sources = self.filtered( + lambda l: not l.source_leave_id and ( + l.is_time_rule_trimmed or self.env.context.get('leave_time_rule_trim') + ) + ) + for leave in trimmed_sources: + if not self.env.context.get('leave_time_rule_trim'): + # outside an engine write: restore the committed engine dates from DB + leave.date_from = leave._origin.date_from or leave.date_from + leave.date_to = leave._origin.date_to or leave.date_to + for holiday in self.filtered(lambda l: not l.source_leave_id and l not in trimmed_sources): + is_calendar_leave = holiday.work_entry_type_id.count_days_as == 'calendar' + if not holiday.request_date_from or not holiday.request_date_to: holiday.date_from = False - elif not holiday.request_unit_half and not holiday.request_unit_hours and not holiday.request_date_to: holiday.date_to = False - else: - if (holiday.request_unit_half or holiday.request_unit_hours) and holiday.request_date_to != holiday.request_date_from: - holiday.request_date_to = holiday.request_date_from - + continue - day_period = { - 'am': 'morning', - 'pm': 'afternoon' - }.get(holiday.request_date_from_period, None) if holiday.request_unit_half else None + if not holiday.request_date_from: + holiday.date_from = False + continue + if not holiday.request_date_to: + holiday.date_to = False + continue - compensated_request_date_from = holiday.request_date_from - compensated_request_date_to = holiday.request_date_to + if holiday.work_entry_type_request_unit == 'hour': + hour_from = holiday.request_hour_from + hour_to = holiday.request_hour_to + # both falsy means the hours were never initialized yet, a real + # request never has the same from and to hour + if not hour_from and not hour_to: + hour_from, hour_to = holiday._get_hour_from_to(holiday.request_date_from, holiday.request_date_to) - if holiday.request_unit_hours: - hour_from = holiday.request_hour_from - hour_to = holiday.request_hour_to - else: + elif holiday.work_entry_type_request_unit == 'half_day': + period_map = {'am': 'morning', 'pm': 'afternoon'} + from_period = period_map.get(holiday.request_date_from_period) + to_period = period_map.get(holiday.request_date_to_period) + if holiday.request_date_from == holiday.request_date_to: + day_period = from_period if from_period == to_period else None hour_from, hour_to = holiday._get_hour_from_to(holiday.request_date_from, holiday.request_date_to, - day_period=day_period) + day_period, count_non_working_days=is_calendar_leave) + else: + hour_from, _ = holiday._get_hour_from_to(holiday.request_date_from, holiday.request_date_from, from_period, count_non_working_days=is_calendar_leave) + _, hour_to = holiday._get_hour_from_to(holiday.request_date_to, holiday.request_date_to, to_period, count_non_working_days=is_calendar_leave) - holiday.date_from = self._to_utc(compensated_request_date_from, hour_from, holiday.employee_id or holiday) - holiday.date_to = self._to_utc(compensated_request_date_to, hour_to, holiday.employee_id or holiday) + else: + hour_from, hour_to = holiday._get_hour_from_to(holiday.request_date_from, holiday.request_date_to, count_non_working_days=is_calendar_leave) + + holiday.date_from = self._to_utc(holiday.request_date_from, hour_from, holiday.employee_id or holiday) + holiday.date_to = self._to_utc(holiday.request_date_to, hour_to, holiday.employee_id or holiday) |
|
