def is_booked_offer_event(self) -> bool: return ProductType.is_event(self.type)
def test_if_type_is_livre_audio_return_False(self): # When is_event = ProductType.is_book(str(ThingType.LIVRE_AUDIO)) # Then assert is_event is False
def test_if_name_is_empty_return_False(self): # When is_thing = ProductType.is_thing("") # Then assert is_thing is False
def test_if_type_is_empty_return_False(self): # When is_event = ProductType.is_book("") # Then assert is_event is False
def test_if_type_is_livre_edition_return_True(self): # When is_event = ProductType.is_book(str(ThingType.LIVRE_EDITION)) # Then assert is_event is True
def test_if_name_is_EventType_MUSEES_PATRIMOINE_return_True(self): # When is_event = ProductType.is_event(str(EventType.MUSEES_PATRIMOINE)) # Then assert is_event is True
def test_if_name_is_ThingType_JEUX_VIDEO_return_False(self): # When is_event = ProductType.is_event(str(ThingType.JEUX_VIDEO)) # Then assert is_event is False
def test_if_name_is_ThingType_AUDIOVISUEL_return_True(self): # When is_thing = ProductType.is_thing(str(ThingType.AUDIOVISUEL)) # Then assert is_thing is True
def test_if_name_is_EventType_PRATIQUE_ARTISTIQUE_return_False(self): # When is_thing = ProductType.is_thing(str(EventType.PRATIQUE_ARTISTIQUE)) # Then assert is_thing is False
def retrieve_data_for_beneficiary_booking_confirmation_email( booking: Booking) -> Dict: stock = booking.stock offer = stock.offer venue = offer.venue beneficiary = booking.user is_digital_offer = offer.isDigital is_physical_offer = ProductType.is_thing( name=offer.type) and not is_digital_offer is_event = ProductType.is_event(name=offer.type) can_expire = int(offer.offerType.get("canExpire", False)) department_code = venue.departementCode if not is_digital_offer else beneficiary.departementCode booking_date_in_tz = utc_datetime_to_department_timezone( booking.dateCreated, department_code) beneficiary_email = beneficiary.email if feature_send_mail_to_users_enabled( ) else settings.DEV_EMAIL_ADDRESS beneficiary_first_name = beneficiary.firstName formatted_booking_date = get_date_formatted_for_email(booking_date_in_tz) formatted_booking_time = get_time_formatted_for_email(booking_date_in_tz) offer_name = offer.name offerer_name = venue.managingOfferer.name formatted_event_beginning_time = "" formatted_event_beginning_date = "" # FIXME: booking.price == stock.price, so we should just write str(booking.total_amount), right? stock_price = str(stock.price * booking.quantity) if stock.price > 0 else "Gratuit" booking_token = booking.token venue_name = venue.name venue_address = venue.address or "" venue_postal_code = venue.postalCode or "" venue_city = venue.city or "" is_event_or_physical_offer_stringified_boolean = 1 if is_event or is_physical_offer else 0 is_physical_offer_stringified_boolean = 1 if is_physical_offer else 0 is_event_stringified_boolean = 1 if is_event else 0 is_single_event_stringified_boolean = 1 if is_event and booking.quantity == 1 else 0 is_duo_event_stringified_boolean = 1 if is_event and booking.quantity == 2 else 0 offer_id = humanize(offer.id) mediation_id = humanize( offer.activeMediation.id) if offer.activeMediation else "vide" environment = format_environment_for_email() if is_event: event_beginning_date_in_tz = utc_datetime_to_department_timezone( stock.beginningDatetime, department_code) formatted_event_beginning_time = get_time_formatted_for_email( event_beginning_date_in_tz) formatted_event_beginning_date = get_date_formatted_for_email( event_beginning_date_in_tz) return { "FromEmail": settings.SUPPORT_EMAIL_ADDRESS, "MJ-TemplateID": 1163067, "MJ-TemplateLanguage": True, "To": beneficiary_email, "Vars": { "user_first_name": beneficiary_first_name, "booking_date": formatted_booking_date, "booking_hour": formatted_booking_time, "offer_name": offer_name, "offerer_name": offerer_name, "event_date": formatted_event_beginning_date, "event_hour": formatted_event_beginning_time, "offer_price": stock_price, "offer_token": booking_token, "venue_name": venue_name, "venue_address": venue_address, "venue_postal_code": venue_postal_code, "venue_city": venue_city, "all_but_not_virtual_thing": is_event_or_physical_offer_stringified_boolean, "all_things_not_virtual_thing": is_physical_offer_stringified_boolean, "is_event": is_event_stringified_boolean, "is_single_event": is_single_event_stringified_boolean, "is_duo_event": is_duo_event_stringified_boolean, "offer_id": offer_id, "mediation_id": mediation_id, "env": environment, "can_expire": can_expire, }, }
def retrieve_data_for_offerer_booking_recap_email( booking: Booking, recipients: List[str]) -> Dict: offer = booking.stock.offer venue_name = offer.venue.name offer_name = offer.name price = "Gratuit" if booking.stock.price == 0 else str(booking.stock.price) quantity = booking.quantity user_email = booking.user.email user_firstname = booking.user.firstName user_lastname = booking.user.lastName user_phoneNumber = booking.user.phoneNumber or "" departement_code = offer.venue.departementCode or "numérique" offer_type = offer.type is_event = int(offer.isEvent) bookings = booking_repository.find_ongoing_bookings_by_stock( booking.stock.id) can_expire = int(offer.offerType.get("canExpire", False)) offer_link = build_pc_pro_offer_link(offer) environment = format_environment_for_email() mailjet_json = { "FromEmail": settings.SUPPORT_EMAIL_ADDRESS, "MJ-TemplateID": 2113444, "MJ-TemplateLanguage": True, "To": create_email_recipients(recipients), "Vars": { "nom_offre": offer_name, "nom_lieu": venue_name, "is_event": is_event, "nombre_resa": len(bookings), "ISBN": "", "offer_type": "book", "date": "", "heure": "", "quantity": quantity, "contremarque": booking.token, "prix": price, # FIXME (asaunier, 2020-12-15): These information seems unused by the template "users": extract_users_information_from_bookings(bookings), "user_firstName": user_firstname, "user_lastName": user_lastname, "user_phoneNumber": user_phoneNumber, "user_email": user_email, "lien_offre_pcpro": offer_link, "departement": departement_code, "env": environment, "can_expire": can_expire, }, } offer_is_a_book = ProductType.is_book(offer_type) if offer_is_a_book: mailjet_json["Vars"]["ISBN"] = (offer.extraData["isbn"] if offer.extraData is not None and "isbn" in offer.extraData else "") else: mailjet_json["Vars"]["offer_type"] = offer_type offer_is_an_event = is_event == 1 if offer_is_an_event: mailjet_json["Vars"]["date"] = format_booking_date_for_email(booking) mailjet_json["Vars"]["heure"] = format_booking_hours_for_email(booking) return mailjet_json
def check_offer_type_is_valid(offer_type_name): if not ProductType.is_thing(offer_type_name) and not ProductType.is_event( offer_type_name): api_error = ApiErrors() api_error.add_error("type", "Le type de cette offre est inconnu") raise api_error
def isThing(self) -> bool: return ProductType.is_thing(self.type)
def isEvent(self) -> bool: return ProductType.is_event(self.type)