def retrieve_offerer_bookings_recap_email_data_after_offerer_cancellation( bookings: List[Booking]) -> Dict: booking = bookings[0] stock = booking.stock offer = stock.offer event_date = format_booking_date_for_email(booking) event_hour = format_booking_hours_for_email(booking) offer_link = build_pc_pro_offer_link(offer) offer_price = str(stock.price) if stock.price > 0 else "Gratuit" quantity = sum([booking.quantity for booking in bookings]) venue_name = offer.venue.publicName if offer.venue.publicName else offer.venue.name return { "MJ-TemplateID": 1116333, "MJ-TemplateLanguage": True, "Vars": { "offer_name": offer.name, "venue_name": venue_name, "price": offer_price, "is_event": int(offer.isEvent), "event_date": event_date, "event_hour": event_hour, "quantity": quantity, "reservations_number": len(bookings), "lien_offre_pcpro": offer_link, "users": _extract_users_information_from_bookings_list(bookings), }, }
def retrieve_offerer_bookings_recap_email_data_after_offerer_cancellation( bookings: List[Booking], recipients: str) -> Dict: booking = bookings[0] stock = booking.stock offer = stock.offer event_date = format_booking_date_for_email(booking) event_hour = format_booking_hours_for_email(booking) offer_link = build_pc_pro_offer_link(offer) offer_price = str(stock.price) if stock.price > 0 else "Gratuit" environment = format_environment_for_email() quantity = sum([booking.quantity for booking in bookings]) venue_name = offer.venue.publicName if offer.venue.publicName else offer.venue.name return { "FromEmail": settings.SUPPORT_EMAIL_ADDRESS, "MJ-TemplateID": 1116333, "MJ-TemplateLanguage": True, "To": recipients if feature_send_mail_to_users_enabled() else settings.DEV_EMAIL_ADDRESS, "Vars": { "offer_name": offer.name, "venue_name": venue_name, "price": offer_price, "is_event": int(offer.isEvent), "event_date": event_date, "event_hour": event_hour, "quantity": quantity, "reservations_number": len(bookings), "env": environment, "lien_offre_pcpro": offer_link, "users": _extract_users_information_from_bookings_list(bookings), }, }
def _build_booking_confirmation_mail_data( booking: bookings_models.Booking) -> dict: stock: Stock = booking.stock offer: Offer = stock.offer educational_booking: EducationalBooking = booking.educationalBooking offer_link = build_pc_pro_offer_link(offer) return { "MJ-TemplateID": 3174413, "MJ-TemplateLanguage": True, "Vars": { "lien_offre_pcpro": offer_link, "nom_offre": offer.name, "nom_lieu": offer.venue.name, "date": format_booking_date_for_email(booking), "heure": format_booking_hours_for_email(booking), "quantity": booking.quantity, "prix": str(booking.amount) if booking.amount > 0 else "Gratuit", "user_firstName": educational_booking.educationalRedactor.firstName, "user_lastName": educational_booking.educationalRedactor.lastName, "user_email": educational_booking.educationalRedactor.email, "is_event": int(offer.isEvent), }, }
def retrieve_data_for_offerer_booking_recap_email(booking: Booking) -> 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) can_expire = int(offer.offerType.get("canExpire", False)) offer_link = build_pc_pro_offer_link(offer) mailjet_json = { "MJ-TemplateID": 2418750, "MJ-TemplateLanguage": True, "Headers": { "Reply-To": user_email, }, "Vars": { "nom_offre": offer_name, "nom_lieu": venue_name, "is_event": is_event, "ISBN": "", "offer_type": "book", "date": "", "heure": "", "quantity": quantity, "contremarque": booking.token, "prix": price, "user_firstName": user_firstname, "user_lastName": user_lastname, "user_phoneNumber": user_phoneNumber, "user_email": user_email, "lien_offre_pcpro": offer_link, "departement": departement_code, "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 test_should_return_empty_string_when_offer_is_not_an_event(self): # Given user = create_user() offerer = create_offerer() venue = create_venue(offerer) offer = create_offer_with_thing_product(venue) stock = create_stock_from_offer(offer, beginning_datetime=None) booking = create_booking(user=user, stock=stock) # When formatted_date = format_booking_date_for_email(booking) # Then assert formatted_date == ""
def test_should_return_formatted_event_beginningDatetime_when_offer_is_an_event(self): # Given user = create_user() offerer = create_offerer() venue = create_venue(offerer) offer = create_offer_with_event_product(venue) stock = create_stock_from_offer(offer, beginning_datetime=datetime(2019, 10, 9, 10, 20, 00)) booking = create_booking(user=user, stock=stock) # When formatted_date = format_booking_date_for_email(booking) # Then assert formatted_date == "09-Oct-2019"
def retrieve_offerer_booking_recap_email_data_after_user_cancellation( booking: Booking, recipients: str) -> Dict: user = booking.user stock = booking.stock bookings = list( filter(lambda ongoing_booking: not ongoing_booking.isCancelled, stock.bookings)) offer = stock.offer venue = offer.venue departement_code = venue.departementCode or "numérique" price = str(stock.price) if stock.price > 0 else "Gratuit" offer_pc_pro_link = build_pc_pro_offer_link(offer) environment = format_environment_for_email() booked_date = format_booking_date_for_email(booking) booked_hour = format_booking_hours_for_email(booking) is_active = _is_offer_active_for_recap(stock) return { "FromEmail": settings.SUPPORT_EMAIL_ADDRESS, "MJ-TemplateID": 780015, "MJ-TemplateLanguage": True, "To": recipients if feature_send_mail_to_users_enabled() else settings.DEV_EMAIL_ADDRESS, "Vars": { "departement": departement_code, "nom_offre": offer.name, "lien_offre_pcpro": offer_pc_pro_link, "nom_lieu": venue.name, "prix": price, "is_event": int(offer.isEvent), "date": booked_date, "heure": booked_hour, "quantite": booking.quantity, "user_name": user.publicName, "user_email": user.email, "is_active": int(is_active), "nombre_resa": len(bookings), "env": environment, "users": extract_users_information_from_bookings(bookings), }, }
def retrieve_offerer_booking_recap_email_data_after_user_cancellation( booking: Booking) -> dict: stock = booking.stock bookings = (Booking.query.filter_by( isCancelled=False, stock=stock).options( joinedload(Booking.individualBooking).joinedload( IndividualBooking.user)).all()) offer = stock.offer venue = offer.venue departement_code = venue.departementCode or "numérique" price = str(stock.price) if stock.price > 0 else "Gratuit" offer_pc_pro_link = build_pc_pro_offer_link(offer) booked_date = format_booking_date_for_email(booking) booked_hour = format_booking_hours_for_email(booking) is_active = _is_offer_active_for_recap(stock) user_public_name = f"{booking.firstName} {booking.lastName}" user_email = booking.email return { "MJ-TemplateID": 780015, "MJ-TemplateLanguage": True, "Vars": { "departement": departement_code, "nom_offre": offer.name, "lien_offre_pcpro": offer_pc_pro_link, "nom_lieu": venue.name, "prix": price, "is_event": int(offer.isEvent), "date": booked_date, "heure": booked_hour, "quantite": booking.quantity, "user_name": user_public_name, "user_email": user_email, "is_active": int(is_active), "nombre_resa": len(bookings), "users": extract_users_information_from_bookings(bookings), }, }
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 retrieve_data_for_offerer_booking_recap_email( individual_booking: IndividualBooking) -> dict: booking = individual_booking.booking offer = booking.stock.offer venue = offer.venue venue_name = venue.publicName if venue.publicName else venue.name offer_name = offer.name price = "Gratuit" if booking.stock.price == 0 else f"{booking.stock.price} €" quantity = booking.quantity user_email = individual_booking.user.email user_firstname = individual_booking.user.firstName user_lastname = individual_booking.user.lastName user_phoneNumber = individual_booking.user.phoneNumber or "" departement_code = venue.departementCode or "numérique" is_event = int(offer.isEvent) if (booking.stock.canHaveActivationCodes and booking.activationCode and FeatureToggle.AUTO_ACTIVATE_DIGITAL_BOOKINGS.is_active()): can_expire = 0 is_booking_autovalidated = 1 else: can_expire = int(offer.subcategory.can_expire) is_booking_autovalidated = 0 expiration_delay = BOOKINGS_AUTO_EXPIRY_DELAY.days if offer.subcategoryId == subcategories.LIVRE_PAPIER.id: expiration_delay = BOOKS_BOOKINGS_AUTO_EXPIRY_DELAY.days offer_link = build_pc_pro_offer_link(offer) if booking.stock.price == 0 or booking.activationCode or is_booking_autovalidated: must_use_token_for_payment = 0 else: must_use_token_for_payment = 1 mailjet_json = { "MJ-TemplateID": 3095147, "MJ-TemplateLanguage": True, "Headers": { "Reply-To": user_email, }, "Vars": { "nom_offre": offer_name, "nom_lieu": venue_name, "is_event": is_event, "ISBN": "", # FIXME: change MJ template variable name "offer_type": offer.subcategoryId, "date": "", "heure": "", "quantity": quantity, "contremarque": booking.token, "prix": price, "user_firstName": user_firstname, "user_lastName": user_lastname, "user_phoneNumber": user_phoneNumber, "user_email": user_email, "lien_offre_pcpro": offer_link, "departement": departement_code, "can_expire": can_expire, "expiration_delay": expiration_delay, "is_booking_autovalidated": is_booking_autovalidated, "must_use_token_for_payment": must_use_token_for_payment, }, } if "isbn" in offer.subcategory.conditional_fields: mailjet_json["Vars"]["ISBN"] = (offer.extraData["isbn"] if offer.extraData is not None and "isbn" in offer.extraData else "") mailjet_json["Vars"]["offer_type"] = "book" 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