Skip to content

Commit

Permalink
(PC-32883)[API] chore: add atomic to DELETE stocks
Browse files Browse the repository at this point in the history
  • Loading branch information
ogeber-pass committed Jan 8, 2025
1 parent a3aff23 commit f504a13
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand Down
17 changes: 13 additions & 4 deletions api/src/pcapi/core/offers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
)


Expand Down
1 change: 1 addition & 0 deletions api/src/pcapi/routes/pro/offers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f504a13

Please sign in to comment.