Exemplo n.º 1
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
Exemplo n.º 2
0
    def fill_stock_attributes(self, allocine_stock: Stock):
        showtime_uuid = _get_showtimes_uuid_by_idAtProvider(
            allocine_stock.idAtProviders)
        showtime = _find_showtime_by_showtime_uuid(
            self.filtered_movie_showtimes, showtime_uuid)

        parsed_showtimes = retrieve_showtime_information(showtime)
        diffusion_version = parsed_showtimes["diffusionVersion"]

        allocine_stock.offerId = (self.last_vo_offer_id
                                  if diffusion_version == ORIGINAL_VERSION else
                                  self.last_vf_offer_id)

        local_tz = get_department_timezone(self.venue.departementCode)
        date_in_utc = _format_date_from_local_timezone_to_utc(
            parsed_showtimes["startsAt"], local_tz)
        allocine_stock.beginningDatetime = date_in_utc

        is_new_stock_to_insert = allocine_stock.id is None
        if is_new_stock_to_insert:
            allocine_stock.fieldsUpdated = []

        if "bookingLimitDatetime" not in allocine_stock.fieldsUpdated:
            allocine_stock.bookingLimitDatetime = date_in_utc

        if "quantity" not in allocine_stock.fieldsUpdated:
            allocine_stock.quantity = self.quantity

        if "price" not in allocine_stock.fieldsUpdated:
            allocine_stock.price = self.apply_allocine_price_rule(
                allocine_stock)
Exemplo 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
Exemplo n.º 4
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
Exemplo n.º 5
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