Ejemplo n.º 1
0
    def _process(self, args):
        new_booking_data = {
            'booking_reason': args['booking_reason'],
            'booked_for_user': args.get('booked_for_user', self.booking.booked_for_user),
            'start_dt': args['start_dt'],
            'end_dt': args['end_dt'],
            'repeat_frequency': args['repeat_frequency'],
            'repeat_interval': args['repeat_interval'],
        }

        additional_booking_attrs = {}
        if not should_split_booking(self.booking, new_booking_data):
            has_date_changed = not has_same_dates(self.booking, new_booking_data)
            room = self.booking.room
            self.booking.modify(new_booking_data, session.user)
            if (has_date_changed and not room.can_book(session.user, allow_admin=False) and
                    room.can_prebook(session.user, allow_admin=False) and self.booking.is_accepted):
                self.booking.reset_approval(session.user)
        else:
            new_booking = split_booking(self.booking, new_booking_data)
            additional_booking_attrs['new_booking_id'] = new_booking.id

        db.session.flush()
        today = date.today()
        calendar = get_room_calendar(args['start_dt'] or today, args['end_dt'] or today, [args['room_id']])
        return jsonify(booking=dict(serialize_booking_details(self.booking), **additional_booking_attrs),
                       room_calendar=serialize_availability(calendar).values())
Ejemplo n.º 2
0
    def _process(self, args):
        new_booking_data = {
            'booking_reason': args['booking_reason'],
            'booked_for_user': args.get('booked_for_user', self.booking.booked_for_user),
            'start_dt': args['start_dt'],
            'end_dt': args['end_dt'],
            'repeat_frequency': args['repeat_frequency'],
            'repeat_interval': args['repeat_interval'],
        }

        additional_booking_attrs = {}
        if not should_split_booking(self.booking, new_booking_data):
            has_slot_changed = not has_same_slots(self.booking, new_booking_data)
            room = self.booking.room
            self.booking.modify(new_booking_data, session.user)
            if (has_slot_changed and not room.can_book(session.user, allow_admin=False) and
                    room.can_prebook(session.user, allow_admin=False) and self.booking.is_accepted):
                self.booking.reset_approval(session.user)
        else:
            new_booking = split_booking(self.booking, new_booking_data)
            additional_booking_attrs['new_booking_id'] = new_booking.id

        db.session.flush()
        today = date.today()
        calendar = get_room_calendar(args['start_dt'] or today, args['end_dt'] or today, [args['room_id']])
        return jsonify(booking=dict(serialize_booking_details(self.booking), **additional_booking_attrs),
                       room_calendar=serialize_availability(calendar).values())
Ejemplo n.º 3
0
def test_bookings_are_split_on_time_changes(create_reservation):
    from indico.modules.rb.operations.bookings import should_split_booking

    start_dt = datetime.today().replace(hour=8, minute=30) - timedelta(days=3)
    end_dt = datetime.today().replace(hour=17, minute=30) + timedelta(days=3)
    reservation = create_reservation(start_dt=start_dt,
                                     end_dt=end_dt,
                                     repeat_frequency=RepeatFrequency.DAY)
    new_booking_data = {
        'start_dt': start_dt,
        'end_dt': end_dt,
        'repeat_frequency': reservation.repeat_frequency,
        'repeat_interval': reservation.repeat_interval
    }

    assert not should_split_booking(reservation, new_booking_data)
    assert not should_split_booking(
        reservation, dict(new_booking_data, end_dt=end_dt + timedelta(days=5)))
    assert should_split_booking(
        reservation, dict(new_booking_data, start_dt=start_dt.replace(hour=9)))
    assert should_split_booking(
        reservation, dict(new_booking_data, end_dt=end_dt.replace(hour=20)))
    assert should_split_booking(
        reservation,
        dict(new_booking_data, repeat_frequency=RepeatFrequency.NEVER))
    assert should_split_booking(reservation,
                                dict(new_booking_data, repeat_interval=2))
Ejemplo n.º 4
0
def test_bookings_are_split_on_time_changes(create_reservation):
    from indico.modules.rb.operations.bookings import should_split_booking

    start_dt = datetime.today().replace(hour=8, minute=30) - timedelta(days=3)
    end_dt = datetime.today().replace(hour=17, minute=30) + timedelta(days=3)
    reservation = create_reservation(start_dt=start_dt, end_dt=end_dt, repeat_frequency=RepeatFrequency.DAY)
    new_booking_data = {'start_dt': start_dt, 'end_dt': end_dt, 'repeat_frequency': reservation.repeat_frequency,
                        'repeat_interval': reservation.repeat_interval}

    assert not should_split_booking(reservation, new_booking_data)
    assert not should_split_booking(reservation, dict(new_booking_data, end_dt=end_dt + timedelta(days=5)))
    assert should_split_booking(reservation, dict(new_booking_data, start_dt=start_dt.replace(hour=9)))
    assert should_split_booking(reservation, dict(new_booking_data, end_dt=end_dt.replace(hour=20)))
    assert should_split_booking(reservation, dict(new_booking_data, repeat_frequency=RepeatFrequency.NEVER))
    assert should_split_booking(reservation, dict(new_booking_data, repeat_interval=2))