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

View 17.0 View 19.0
Inputs Method Outputs
  • request_date_from
  • request_unit_half
  • request_unit_hours
  • request_date_to
  • request_date_from_period
  • request_hour_from
  • request_hour_to
  • employee_id
  • request_date_to_period
for holiday in self:
            if not holiday.request_date_from:
                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
- 
- 
-                 day_period = {
-                     'am': 'morning',
-                     'pm': 'afternoon'
-                 }.get(holiday.request_date_from_period, None) if holiday.request_unit_half else None
+                 continue

-                 attendance_from, attendance_to = holiday._get_attendances(holiday.request_date_from, holiday.request_date_to, day_period=day_period)
+             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.request_unit_hours:
+                 hour_from = holiday.request_hour_from
+                 hour_to = holiday.request_hour_to
+                 if not hour_from or not hour_to:
+                     computed_from, computed_to = holiday._get_hour_from_to(holiday.request_date_from, holiday.request_date_to)
+                     hour_from = hour_from or computed_from
+                     hour_to = hour_to or computed_to

-                 if holiday.request_unit_hours:
-                     hour_from = holiday.request_hour_from
-                     hour_to = holiday.request_hour_to
+             elif holiday.request_unit_half:
+                 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)
                else:
-                     hour_from = attendance_from.hour_from
-                     hour_to = attendance_to.hour_to
+                     hour_from, _ = holiday._get_hour_from_to(holiday.request_date_from, holiday.request_date_from, from_period)
+                     _, hour_to = holiday._get_hour_from_to(holiday.request_date_to, holiday.request_date_to, to_period)

-                 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)
+ 
+             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)
  • date_from
  • date_to
  • request_date_to

Back to entity