diff --git a/uw_mazevo/api.py b/uw_mazevo/api.py index 6da9f5e..3572dc2 100644 --- a/uw_mazevo/api.py +++ b/uw_mazevo/api.py @@ -1,5 +1,5 @@ from uw_mazevo import DAO, get_resource, post_resource -from uw_mazevo.models import Booking, Building, Room, Status +from uw_mazevo.models import Booking, BookingDetail, Building, Room, Status class PublicConfiguration(object): @@ -72,3 +72,20 @@ def get_events(self, **kwargs): for data in post_resource(url, body): events.append(Booking.from_json(data)) return events + + def get_events_with_booking_details(self, booking_ids): + """ + Returns all event information and resource details + + """ + url = self.URL.format("GetEventsWithBookingDetails") + body = {"bookingIds": booking_ids} + + events = [] + for data in post_resource(url, body): + event = Booking.from_json(data) + event.booking_details = [] + for detail in data["bookingDetails"]: + event.booking_details.append(BookingDetail.from_json(detail)) + events.append(event) + return events diff --git a/uw_mazevo/models.py b/uw_mazevo/models.py index 1e22564..51dc498 100644 --- a/uw_mazevo/models.py +++ b/uw_mazevo/models.py @@ -127,11 +127,29 @@ def from_json(data): return booking -class ServiceOrderDetail(models.Model): - booking_date = models.DateField() - service_order_start_time = models.TimeField(null=True) - service_order_end_time = models.TimeField(null=True) - resource_description = models.CharField(max_length=50) - resource_external_reference = models.CharField(max_length=255, blank=True) - service_order_id = models.PositiveIntegerField() +class BookingDetail(models.Model): booking = models.ForeignKey(Booking) + id = models.PositiveIntegerField(primary_key=True) + resource_id = models.PositiveIntegerField() + resource = models.CharField() + service_provider = models.CharField() + quantity = models.PositiveIntegerField() + notes = models.TextField() + special_instructions = models.TextField() + service_start_time = models.TimeField(null=True) + service_end_time = models.TimeField(null=True) + + @staticmethod + def from_json(data): + detail = BookingDetail() + detail.booking_id = data["bookingId"] + detail.id = data["bookingDetailId"] + detail.resource_id = data["resourceId"] + detail.resource_description = data["resource"] + detail.service_provider = data["serviceProvier"] + detail.quantity = data["quantity"] + detail.notes = data["notes"] + detail.special_instructions = data["specialInstructions"] + detail.service_start_time = data["serviceStartTime"] + detail.service_end_time = data["serviceEndTime"] + return detail