diff --git a/api/src/pcapi/core/mails/transactional/bookings/booking_cancellation_confirmation_by_pro.py b/api/src/pcapi/core/mails/transactional/bookings/booking_cancellation_confirmation_by_pro.py index 0496bb3782f..ed8cd3825c4 100644 --- a/api/src/pcapi/core/mails/transactional/bookings/booking_cancellation_confirmation_by_pro.py +++ b/api/src/pcapi/core/mails/transactional/bookings/booking_cancellation_confirmation_by_pro.py @@ -1,8 +1,11 @@ +from functools import partial + from pcapi.core import mails from pcapi.core.bookings.models import Booking from pcapi.core.educational.models import CollectiveBooking from pcapi.core.mails import models from pcapi.core.mails.transactional.sendinblue_template_ids import TransactionalEmail +from pcapi.repository import on_commit from pcapi.utils.date import get_date_formatted_for_email from pcapi.utils.date import get_time_formatted_for_email from pcapi.utils.mailing import get_event_datetime @@ -65,7 +68,13 @@ def send_booking_cancellation_confirmation_by_pro_email(bookings: list[Booking]) if not offerer_booking_email: return data = get_booking_cancellation_confirmation_by_pro_email_data(bookings) - mails.send(recipients=[offerer_booking_email], data=data) + on_commit( + partial( + mails.send, + recipients=[offerer_booking_email], + data=data, + ) + ) def send_collective_booking_cancellation_confirmation_by_pro_email(booking: CollectiveBooking) -> None: diff --git a/api/src/pcapi/core/offers/api.py b/api/src/pcapi/core/offers/api.py index 1774891572c..1a285252251 100644 --- a/api/src/pcapi/core/offers/api.py +++ b/api/src/pcapi/core/offers/api.py @@ -1040,10 +1040,19 @@ def _delete_stock(stock: models.Stock, author_id: int | None = None, user_connec transactional_mails.send_booking_cancellation_by_pro_to_beneficiary_email(booking) transactional_mails.send_booking_cancellation_confirmation_by_pro_email(cancelled_bookings) if not FeatureToggle.WIP_DISABLE_CANCEL_BOOKING_NOTIFICATION.is_active(): - push_notification_job.send_cancel_booking_notification.delay([booking.id for booking in cancelled_bookings]) - search.async_index_offer_ids( - [stock.offerId], - reason=search.IndexationReason.STOCK_DELETION, + on_commit( + partial( + push_notification_job.send_cancel_booking_notification.delay, + [booking.id for booking in cancelled_bookings], + ) + ) + + on_commit( + partial( + search.async_index_offer_ids, + [stock.offerId], + reason=search.IndexationReason.STOCK_DELETION, + ) ) diff --git a/api/src/pcapi/routes/pro/offers.py b/api/src/pcapi/routes/pro/offers.py index b70e296fd29..47ab33523a8 100644 --- a/api/src/pcapi/routes/pro/offers.py +++ b/api/src/pcapi/routes/pro/offers.py @@ -150,6 +150,7 @@ def get_stocks(offer_id: int, query: offers_serialize.StocksQueryModel) -> offer on_success_status=204, api=blueprint.pro_private_schema, ) +@atomic() def delete_stocks(offer_id: int, body: offers_serialize.DeleteStockListBody) -> None: try: offer = offers_repository.get_offer_by_id(offer_id)