from booking.models import Booking
from containers.models import Container

def get_container_for_booking(booking):
    filters = {
        'expedited': False,
    }
    # booking = Booking.objects.get(number=booking_number)
    if not booking:
        return None
    if booking.container_number:
        filters['container_number'] = booking.container_number
    else:
        filters['container_type'] = booking.container_type
        filters['line'] = booking.line

    return Container.objects.filter(**filters).order_by('received_on').first()