Skip to content

Commit

Permalink
(PC-32204)[BO] fix: Use endDatetime to in reservation from CONFIRMED ->
Browse files Browse the repository at this point in the history
USED
  • Loading branch information
rprasquier-pass committed Oct 7, 2024
1 parent 0ee43c4 commit 63ddd25
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 45 deletions.
2 changes: 1 addition & 1 deletion api/src/pcapi/core/bookings/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,7 @@ def auto_mark_as_used_after_event() -> None:
.where(
CollectiveBooking.status == CollectiveBookingStatus.CONFIRMED,
CollectiveBooking.collectiveStockId == CollectiveStock.id,
CollectiveStock.beginningDatetime < threshold,
CollectiveStock.endDatetime < threshold,
)
.values(dateUsed=now, status=CollectiveBookingStatus.USED),
execution_options={"synchronize_session": False},
Expand Down
5 changes: 1 addition & 4 deletions api/src/pcapi/core/finance/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,7 @@ def add_event(
models.FinanceEventMotive.BOOKING_USED_AFTER_CANCELLATION,
):
assert booking.dateUsed
if isinstance(booking, bookings_models.Booking):
value_date = booking.dateUsed
else:
value_date = booking.collectiveStock.pricing_datetime
value_date = booking.dateUsed

pricing_point_id = booking.venue.current_pricing_point_id
if pricing_point_id:
Expand Down
4 changes: 2 additions & 2 deletions api/tests/core/bookings/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1938,7 +1938,7 @@ def test_update_collective_booking_when_not_used_and_event_date_is_3_days_before

def test_create_finance_event_for_collective_booking(self):
event_date = datetime.utcnow() - timedelta(days=3)
booking = educational_factories.CollectiveBookingFactory(collectiveStock__beginningDatetime=event_date)
booking = educational_factories.CollectiveBookingFactory(collectiveStock__endDatetime=event_date)

api.auto_mark_as_used_after_event()

Expand All @@ -1947,7 +1947,7 @@ def test_create_finance_event_for_collective_booking(self):

def test_does_not_update_collective_booking_when_event_date_is_only_1_day_before(self):
event_date = datetime.utcnow() - timedelta(days=1)
educational_factories.CollectiveBookingFactory(collectiveStock__beginningDatetime=event_date)
educational_factories.CollectiveBookingFactory(collectiveStock__endDatetime=event_date)

api.auto_mark_as_used_after_event()

Expand Down
41 changes: 3 additions & 38 deletions api/tests/core/finance/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ def test_pricing_individual(self):
assert pricing2.lines[1].category == models.PricingLineCategory.OFFERER_CONTRIBUTION
assert pricing2.lines[1].amount == 5 * 100

@override_features(USE_END_DATE_FOR_COLLECTIVE_PRICING=False)
def test_pricing_collective(self):
event1 = self._make_collective_event(price=19_999)
booking1 = event1.collectiveBooking
Expand All @@ -234,41 +233,7 @@ def test_pricing_collective(self):
assert pricing1.booking is None
assert pricing1.venue == booking1.venue
assert pricing1.pricingPoint == booking1.venue
assert pricing1.valueDate == booking1.collectiveStock.beginningDatetime
assert pricing1.amount == -(19_999 * 100)
assert pricing1.standardRule == "Remboursement total pour les offres éducationnelles"
assert pricing1.customRule is None
assert pricing1.revenue == 0
assert pricing1.lines[0].category == models.PricingLineCategory.OFFERER_REVENUE
assert pricing1.lines[0].amount == -(19_999 * 100)
assert pricing1.lines[1].category == models.PricingLineCategory.OFFERER_CONTRIBUTION
assert pricing1.lines[1].amount == 0

event2 = self._make_collective_event(price=100)
booking2 = event2.collectiveBooking
api.price_event(event2)
pricing2 = models.Pricing.query.filter_by(collectiveBooking=booking2).one()
assert pricing2.collectiveBooking == booking2
assert pricing2.amount == -(100 * 100)
assert pricing1.revenue == 0
assert pricing2.standardRule == "Remboursement total pour les offres éducationnelles"
assert pricing2.lines[0].category == models.PricingLineCategory.OFFERER_REVENUE
assert pricing2.lines[0].amount == -(100 * 100)
assert pricing2.lines[1].category == models.PricingLineCategory.OFFERER_CONTRIBUTION
assert pricing2.lines[1].amount == 0

@override_features(USE_END_DATE_FOR_COLLECTIVE_PRICING=True)
def test_pricing_collective_with_endDatetime(self):
event1 = self._make_collective_event(price=19_999)
booking1 = event1.collectiveBooking
api.price_event(event1)
pricing1 = models.Pricing.query.one()
assert pricing1.event == event1
assert pricing1.collectiveBooking == booking1
assert pricing1.booking is None
assert pricing1.venue == booking1.venue
assert pricing1.pricingPoint == booking1.venue
assert pricing1.valueDate == booking1.collectiveStock.endDatetime
assert pricing1.valueDate == booking1.dateUsed
assert pricing1.amount == -(19_999 * 100)
assert pricing1.standardRule == "Remboursement total pour les offres éducationnelles"
assert pricing1.customRule is None
Expand Down Expand Up @@ -1024,7 +989,7 @@ def test_used_using_collective_beginningDatetime(self):
assert event.collectiveBooking == booking
assert event.status == models.FinanceEventStatus.READY
assert event.motive == motive
assert event.valueDate == booking.collectiveStock.beginningDatetime
assert event.valueDate == booking.dateUsed
assert event.venue == booking.venue
assert event.pricingPoint == pricing_point
assert event.pricingOrderingDate == booking.collectiveStock.beginningDatetime
Expand All @@ -1050,7 +1015,7 @@ def test_used_using_collective_endDatetime(self):
assert event.collectiveBooking == booking
assert event.status == models.FinanceEventStatus.READY
assert event.motive == motive
assert event.valueDate == booking.collectiveStock.endDatetime
assert event.valueDate == booking.dateUsed
assert event.venue == booking.venue
assert event.pricingPoint == pricing_point
assert event.pricingOrderingDate == booking.collectiveStock.endDatetime
Expand Down

0 comments on commit 63ddd25

Please sign in to comment.