'Schedule hours of work, using a calendar and an optional resource to
compute working and leave days. This method can be used backwards, i.e.
scheduling days before a deadline.
:param int hours: number of hours to schedule. Use a negative number to
compute a backwards scheduling.
:param datetime day_dt: reference date to compute working days. If days is
> 0 date is the starting date. If days is < 0
date is the ending date.
:param boolean compute_leaves: if set, compute the leaves based on calendar
and resource. Otherwise no leaves are taken
into account.
:param int resource_id: the id of the resource to take into account when
computing the leaves. If not set, only general
leaves are computed. If set, generic and
specific leaves are computed.
:param tuple default_interval: if no id, try to return a default working
day using default_interval[0] as beginning
hour, and default_interval[1] as ending hour.
Example: default_interval = (8, 16).
Otherwise, a void list of working intervals
is returned when id is None.
:return tuple (datetime, intervals): datetime is the beginning/ending date
of the schedulign; intervals are the
working intervals of the scheduling.
Note: Why not using rrule.rrule ? Because rrule does not seem to allow
getting back in time.'

@api.multi
def _schedule_hours(self, hours, day_dt=None, compute_leaves=False, resource_id=None, default_interval=None):

    if (day_dt is None):
        day_dt = datetime.datetime.now()
    elif ((day_dt is not None) and (hours > 0)):
        self = self.with_context(force_start_dt=day_dt)
    backwards = (hours < 0)
    hours = abs(hours)
    intervals = []
    remaining_hours = (hours * 1.0)
    iterations = 0
    current_datetime = day_dt
    call_args = dict(compute_leaves=compute_leaves, resource_id=resource_id, default_interval=default_interval)
    while ((float_compare(remaining_hours, 0.0, precision_digits=2) in (1, 0)) and (iterations < 1000)):
        if backwards:
            call_args['end_dt'] = current_datetime
        else:
            call_args['start_dt'] = current_datetime
        working_intervals = self.get_working_intervals_of_day(**call_args)
        if ((not self) and (not working_intervals)):
            remaining_hours -= 8.0
        elif working_intervals:
            if backwards:
                working_intervals.reverse()
            new_working_intervals = self.interval_schedule_hours(working_intervals, remaining_hours, (not backwards))
            if backwards:
                new_working_intervals.reverse()
            res = timedelta()
            for interval in working_intervals:
                res += (interval[1] - interval[0])
            remaining_hours -= (seconds(res) / 3600.0)
            if backwards:
                intervals = (new_working_intervals + intervals)
            else:
                intervals = (intervals + new_working_intervals)
        if backwards:
            current_datetime = datetime.datetime.combine(self.get_previous_day(current_datetime), datetime.time(23, 59, 59))
        else:
            current_datetime = datetime.datetime.combine(self.get_next_day(current_datetime), datetime.time())
        iterations += 1
    return intervals
