Esempio n. 1
0
def create_reservation_1(save=True):
    reservation = Reservation(
        reserved_from=(datetime.now() + timedelta(days=16, hours=1)),
        reserved_until=(datetime.now() + timedelta(days=16, hours=12)),
        user=users[1],
        car=cars[0]
    )
    reservation.save(force_save_user=True)
    return reservation
Esempio n. 2
0
def create_reservation_5(save=True):
    reservation = Reservation(
        reserved_from=(datetime.now() + timedelta(days=14, hours=13, minutes=15)),
        reserved_until=(datetime.now() + timedelta(days=14, hours=22, minutes=30)),
        user=users[1],
        car=cars[4],
        cancelled=True
    )
    reservation.save(force_save_user=True)
    return reservation
Esempio n. 3
0
def create_reservation_2(save=True):
    reservation = Reservation(
        reserved_from=(datetime.now() + timedelta(days=-3, hours=13)),
        reserved_until=(datetime.now() + timedelta(days=-3, hours=22)),
        user=users[1],
        car=cars[1],
        cancelled=True
    )
    reservation.save(force_save_user=True)
    return reservation
Esempio n. 4
0
 def test_3_conflicting_time(self):
     self.reservation_1.save()
     reservation = Reservation(
         reserved_from=(self.reservation_1.reserved_from + timedelta(seconds=1)),
         reserved_until=(self.reservation_1.reserved_until + timedelta(hours=1)),
         user=self.user_1,
         car=self.car_1
     )
     val_res, val_errs = reservation.is_valid()
     self.assertFalse(val_res)
     self.assertTrue(len(val_errs) == 1)
Esempio n. 5
0
 def test_3_conflicting_time(self):
     self.reservation_1.save()
     reservation = Reservation(
         reserved_from=(self.reservation_1.reserved_from +
                        timedelta(seconds=1)),
         reserved_until=(self.reservation_1.reserved_until +
                         timedelta(hours=1)),
         user=self.user_1,
         car=self.car_1)
     val_res, val_errs = reservation.is_valid()
     self.assertFalse(val_res)
     self.assertTrue(len(val_errs) == 1)
Esempio n. 6
0
 def setUp(self):
     super(ReservationEnabledTestCase, self).setUp()
     self.reservation = Reservation(
         reserved_from=(datetime.now() + timedelta(hours=1)),
         reserved_until=(datetime.now() + timedelta(hours=12)),
         user=self.user,
         car=self.car)
Esempio n. 7
0
def create_reservation_4(save=True):
    reservation = Reservation(
        reserved_from=(datetime.now() + timedelta(days=-10, hours=3, minutes=40)),
        reserved_until=(datetime.now() + timedelta(days=-10, hours=8, minutes=40)),
        user=users[1],
        car=cars[3],
        price=120,
    )
    reservation.save(force_save_user=True)

    journey = JourneyManager()
    journey.create_complete_journey(
        car = reservation.car,
        user_card=reservation.user,
        datetime_since=reservation.reserved_from,
        datetime_till=reservation.reserved_until,
    )

    reservation_bill = ReservationBill.objects.create_for_reservation(reservation)
    reservation_bill.datetime = datetime.now() + timedelta(days=-10, hours=3, minutes=40)
    reservation_bill.save()

    reservation.finished = True
    reservation.save(force_save_user=True)

    return reservation
Esempio n. 8
0
    def list_of_available_cars(cls, datetime_start, datetime_end, parking, home_subsidiary=None):
        """
        Vrati vsechny automobily, ktere jsou v zadanem obdobi dostupne a patri ke zvolene pobocce
        """
        cars = Car.objects.filter(parking=parking)
        if (home_subsidiary is not None):
            cars = cars.filter(home_subsidiary=home_subsidiary)

        result = []
        for c in cars:
            reservations = Reservation.find_conflicts(c, datetime_start, datetime_end)
            if len(reservations) == 0:
                result.append(c)

        return result