Esempio n. 1
0
def create_stock_with_thing_offer(
    offerer: Offerer,
    venue: Venue,
    offer: Offer = None,
    price: Optional[Decimal] = 10,
    quantity: int = 50,
    name: str = "Test Book",
    booking_email: str = "*****@*****.**",
    soft_deleted: bool = False,
    url: str = None,
    booking_limit_datetime: datetime = None,
    thing_type: ThingType = ThingType.AUDIOVISUEL,
) -> Stock:
    stock = Stock()
    stock.offerer = offerer
    stock.price = price

    if offer:
        stock.offer = offer
    else:
        stock.offer = create_offer_with_thing_product(venue,
                                                      thing_name=name,
                                                      thing_type=thing_type)

    stock.offer.bookingEmail = booking_email
    stock.bookingLimitDatetime = booking_limit_datetime
    stock.offer.url = url
    stock.offer.venue = venue
    stock.quantity = quantity
    stock.isSoftDeleted = soft_deleted

    return stock
Esempio n. 2
0
def create_stock(
    beginning_datetime: Optional[datetime] = None,
    booking_limit_datetime: Optional[datetime] = None,
    date_created: datetime = datetime.utcnow(),
    date_modified: datetime = datetime.utcnow(),
    date_modified_at_last_provider: Optional[datetime] = None,
    idx: Optional[int] = None,
    id_at_providers: Optional[str] = None,
    is_soft_deleted: bool = False,
    last_provider_id: Optional[int] = None,
    offer: Optional[Offer] = None,
    price: float = 10,
    quantity: Optional[int] = None,
) -> Stock:
    stock = Stock()
    stock.quantity = quantity
    stock.beginningDatetime = beginning_datetime
    stock.bookingLimitDatetime = booking_limit_datetime
    stock.dateCreated = date_created
    stock.dateModified = date_modified
    stock.dateModifiedAtLastProvider = date_modified_at_last_provider
    if idx:
        stock.id = idx
    stock.idAtProviders = id_at_providers
    stock.isSoftDeleted = is_soft_deleted
    stock.lastProviderId = last_provider_id
    stock.offer = offer
    stock.price = price

    return stock
Esempio n. 3
0
def create_stock_from_event_occurrence(
    event_occurrence: Dict,
    price: int = 10,
    quantity: int = 10,
    soft_deleted: bool = False,
    recap_sent: bool = False,
    booking_limit_date: datetime = None,
) -> Stock:
    stock = Stock()
    stock.beginningDatetime = event_occurrence["beginningDatetime"]
    stock.offerId = event_occurrence["offerId"]
    stock.offer = event_occurrence["offer"]
    stock.price = price
    stock.quantity = quantity
    stock.isSoftDeleted = soft_deleted

    if recap_sent:
        stock.bookingRecapSent = datetime.utcnow()

    if booking_limit_date is None:
        stock.bookingLimitDatetime = event_occurrence["beginningDatetime"]
    else:
        stock.bookingLimitDatetime = booking_limit_date

    return stock
Esempio n. 4
0
def create_booking(
    user: User,
    amount: Optional[Union[Decimal, float]] = None,
    date_created: datetime = datetime.utcnow(),
    date_used: datetime = None,
    idx: int = None,
    is_cancelled: bool = False,
    is_used: bool = False,
    quantity: int = 1,
    stock: Stock = None,
    token: str = None,
    venue: VenueSQLEntity = None,
) -> Booking:
    booking = Booking()
    offerer = create_offerer(siren="987654321",
                             address="Test address",
                             city="Test city",
                             postal_code="93000",
                             name="Test name")
    if venue is None:
        venue = create_venue(
            offerer=offerer,
            name="Test offerer",
            booking_email="*****@*****.**",
            address="123 rue test",
            postal_code="93000",
            city="Test city",
            departement_code="93",
        )
    if stock is None:
        price = amount if amount is not None else 10
        product_with_thing_type = create_offer_with_thing_product(venue)
        stock = create_stock_with_thing_offer(offerer=offerer,
                                              venue=venue,
                                              offer=product_with_thing_type,
                                              price=price)

    if not stock.offer:
        stock.offer = create_offer_with_thing_product(venue)

    booking.user = user
    booking.amount = amount if amount is not None else stock.price
    booking.dateCreated = date_created
    booking.dateUsed = date_used
    booking.id = idx
    booking.isCancelled = is_cancelled
    booking.isUsed = is_used
    booking.quantity = quantity
    booking.stock = stock
    booking.token = token if token is not None else random_token()
    booking.userId = user.id
    booking.confirmationDate = bookings_api.compute_confirmation_date(
        stock.beginningDatetime, date_created)

    return booking
Esempio n. 5
0
def create_stock_from_offer(
        offer: Offer,
        price: float = 9.90,
        quantity: Optional[int] = 10,
        soft_deleted: bool = False,
        booking_limit_datetime: datetime = None,
        beginning_datetime: datetime = None,
        idx: int = None,
        date_modified: datetime = datetime.utcnow(),
) -> Stock:
    stock = Stock()
    stock.id = idx
    stock.offer = offer
    stock.price = price
    stock.quantity = quantity
    stock.isSoftDeleted = soft_deleted
    stock.bookingLimitDatetime = booking_limit_datetime
    stock.beginningDatetime = beginning_datetime
    stock.dateModified = date_modified

    return stock
Esempio n. 6
0
def create_stock_with_event_offer(
        offerer: Offerer,
        venue: Venue,
        price: int = 10,
        booking_email: str = "*****@*****.**",
        quantity: int = 10,
        is_soft_deleted: bool = False,
        event_type: EventType = EventType.JEUX,
        name: str = "Mains, sorts et papiers",
        offer_id: int = None,
        beginning_datetime: datetime = datetime.utcnow() + timedelta(hours=72),
        thumb_count: int = 0,
        booking_limit_datetime: datetime = datetime.utcnow() +
    timedelta(hours=71),
        date_created: datetime = datetime.utcnow(),
        date_modified_at_last_provider: datetime = datetime.utcnow(),
        date_modifed: datetime = datetime.utcnow(),
) -> Stock:
    stock = Stock()
    stock.offerer = offerer
    stock.price = price
    stock.quantity = quantity
    stock.beginningDatetime = beginning_datetime
    stock.bookingLimitDatetime = booking_limit_datetime
    stock.dateCreated = date_created
    stock.dateModifiedAtLastProvider = date_modified_at_last_provider
    stock.dateModified = date_modifed
    stock.offer = create_offer_with_event_product(
        venue,
        event_name=name,
        event_type=event_type,
        booking_email=booking_email,
        is_national=False,
        thumb_count=thumb_count,
    )
    stock.offer.id = offer_id
    stock.isSoftDeleted = is_soft_deleted

    return stock
Esempio n. 7
0
def create_booking_for_thing(
    amount: int = 50,
    date_created: datetime = datetime.utcnow(),
    is_cancelled: bool = False,
    quantity: int = 1,
    product_type: ThingType = ThingType.JEUX,
    url: str = None,
    user: User = None,
) -> Booking:
    product = Product(from_dict={"url": url, "type": str(product_type)})
    offer = Offer(from_dict={"url": url, "type": str(product_type)})
    stock = Stock()
    booking = Booking(from_dict={"amount": amount})
    offer.product = product
    stock.offer = offer
    booking.stock = stock
    booking.quantity = quantity
    booking.user = user
    booking.isCancelled = is_cancelled
    booking.dateCreated = date_created

    return booking
Esempio n. 8
0
def create_booking_for_event(  # pylint: disable=redefined-builtin
    amount: int = 50,
    date_created: datetime = datetime.utcnow(),
    is_cancelled: bool = False,
    quantity: int = 1,
    type: EventType = EventType.CINEMA,
    user: User = None,
) -> Booking:
    product = Product(from_dict={"type": str(type)})
    offer = Offer()
    stock = Stock()
    booking = Booking(from_dict={"amount": amount})
    offer.product = product
    stock.offer = offer
    booking.stock = stock
    booking.quantity = quantity
    booking.user = user
    booking.isCancelled = is_cancelled
    booking.token = random_token()
    booking.dateCreated = date_created

    return booking