def test_should_return_hour_followed_by_two_digits_minutes(self): # Given twelve_o_clock = datetime.time(12, 0, 0, 0) # When time_formatted_for_email = get_time_formatted_for_email(twelve_o_clock) # Then assert time_formatted_for_email == "12h00"
def make_beneficiary_booking_cancellation_email_data(booking: Booking) -> Dict: stock = booking.stock beneficiary = booking.user offer = stock.offer beneficiary_email = beneficiary.email environment = format_environment_for_email() event_date = "" event_hour = "" first_name = beneficiary.firstName is_event = int(offer.isEvent) offer_id = humanize(offer.id) offer_name = offer.name price = str(stock.price * booking.quantity) is_free_offer = 1 if stock.price == 0 else 0 if is_event: beginning_date_time_in_tz = utc_datetime_to_department_timezone( stock.beginningDatetime, offer.venue.departementCode) event_date = get_date_formatted_for_email(beginning_date_time_in_tz) event_hour = get_time_formatted_for_email(beginning_date_time_in_tz) return { "FromEmail": settings.SUPPORT_EMAIL_ADDRESS, "Mj-TemplateID": 1091464, "Mj-TemplateLanguage": True, "To": beneficiary_email, "Vars": { "env": environment, "event_date": event_date, "event_hour": event_hour, "is_free_offer": is_free_offer, "is_event": is_event, "offer_id": offer_id, "offer_name": offer_name, "offer_price": price, "user_first_name": first_name, }, }
def make_beneficiary_booking_cancellation_email_data( individual_booking: IndividualBooking) -> dict: stock = individual_booking.booking.stock beneficiary = individual_booking.user offer = stock.offer event_date = "" event_hour = "" first_name = beneficiary.firstName is_event = int(offer.isEvent) offer_id = humanize(offer.id) offer_name = offer.name price = str(individual_booking.booking.total_amount) is_free_offer = 1 if stock.price == 0 else 0 can_book_again = int( beneficiary.deposit.expirationDate > datetime.datetime.now()) if is_event: beginning_date_time_in_tz = utc_datetime_to_department_timezone( stock.beginningDatetime, offer.venue.departementCode) event_date = get_date_formatted_for_email(beginning_date_time_in_tz) event_hour = get_time_formatted_for_email(beginning_date_time_in_tz) return { "Mj-TemplateID": 1091464, "Mj-TemplateLanguage": True, "Vars": { "event_date": event_date, "event_hour": event_hour, "is_free_offer": is_free_offer, "is_event": is_event, "offer_id": offer_id, "offer_name": offer_name, "offer_price": price, "user_first_name": first_name, "can_book_again": can_book_again, }, }
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_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" 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 { "MJ-TemplateID": 1163067, "MJ-TemplateLanguage": True, "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, "can_expire": can_expire, }, }
def retrieve_data_for_beneficiary_booking_confirmation_email( individual_booking: IndividualBooking) -> dict: stock = individual_booking.booking.stock offer = stock.offer venue = offer.venue beneficiary = individual_booking.user is_digital_offer = offer.isDigital is_physical_offer = not offer.isEvent and not is_digital_offer is_event = offer.isEvent if is_digital_offer and individual_booking.booking.activationCode: can_expire = 0 else: can_expire = int(offer.subcategory.can_expire) expiration_delay: str = "" if can_expire: if offer.subcategoryId == subcategories.LIVRE_PAPIER.id: expiration_delay = BOOKS_BOOKINGS_AUTO_EXPIRY_DELAY.days else: expiration_delay = BOOKINGS_AUTO_EXPIRY_DELAY.days department_code = venue.departementCode if not is_digital_offer else beneficiary.departementCode booking_date_in_tz = utc_datetime_to_department_timezone( individual_booking.booking.dateCreated, department_code) 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 = "" stock_price = f"{individual_booking.booking.total_amount} €" if stock.price > 0 else "Gratuit" venue_name = venue.publicName if venue.publicName else 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 individual_booking.booking.quantity == 1 else 0 is_duo_event_stringified_boolean = 1 if is_event and individual_booking.booking.quantity == 2 else 0 offer_id = humanize(offer.id) mediation_id = humanize( offer.activeMediation.id) if offer.activeMediation else "vide" 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) is_digital_booking_with_activation_code_and_no_expiration_date = ( 1 if is_digital_offer and individual_booking.booking.activationCode and not individual_booking.booking.activationCode.expirationDate else 0) code_expiration_date = ( get_date_formatted_for_email( individual_booking.booking.activationCode.expirationDate) if is_digital_offer and individual_booking.booking.activationCode and individual_booking.booking.activationCode.expirationDate else "") booking_token = (individual_booking.booking.activationCode.code if individual_booking.booking.activationCode else individual_booking.booking.token) has_offer_url = 1 if is_digital_offer else 0 return { "MJ-TemplateID": 3094927, "MJ-TemplateLanguage": True, "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, "is_digital_booking_with_activation_code_and_no_expiration_date": is_digital_booking_with_activation_code_and_no_expiration_date, "code_expiration_date": code_expiration_date, "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, "can_expire": can_expire, "expiration_delay": expiration_delay, "has_offer_url": has_offer_url, "digital_offer_url": individual_booking.booking.completedUrl or "", "offer_withdrawal_details": offer.withdrawalDetails or "", }, }