Esempio n. 1
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)
Esempio n. 2
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. 3
0
 def fill_stock_attributes(self, stock: Stock) -> None:
     bookings_quantity = count_not_cancelled_bookings_quantity_by_stock_id(stock.id)
     stock.quantity = self.provider_stocks["available"] + bookings_quantity
     stock.bookingLimitDatetime = None
     stock.offerId = self.offer_id
     stock.price = (
         self.provider_stocks["price"]
         if self.price_divider_to_euro is None
         else _fill_stock_price(int(self.provider_stocks["price"]), self.price_divider_to_euro)
     )
     stock.dateModified = datetime.now()
Esempio n. 4
0
 def fill_stock_attributes(self, stock: Stock) -> None:
     bookings_quantity = count_not_cancelled_bookings_quantity_by_stock_id(
         stock.id)
     stock.quantity = self.provider_stocks["available"] + bookings_quantity
     stock.bookingLimitDatetime = None
     stock.offerId = self.offer_id
     if self.provider_stocks["price"] and self.price_divider_to_euro:
         stock.price = int(
             self.provider_stocks["price"]) / self.price_divider_to_euro
     else:
         # Beware: price may be None. repository.save() will catch and skip the stock
         stock.price = self.provider_stocks["price"]
     stock.dateModified = datetime.now()