Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(PC-32238)[BO] feat: permit to filter solo/duo bookings in bo #14914

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions api/src/pcapi/routes/backoffice/bookings/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ class GetIndividualBookingListForm(BaseBookingListForm):
default=DEPOSIT_DEFAULT_VALUE,
validators=(wtforms.validators.Optional(),),
)
is_duo = fields.PCSelectMultipleField(
"Réservation Duo",
choices=((1, "solo"), (2, "duo")),
coerce=int,
)

def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None:
super().__init__(*args, **kwargs)
Expand All @@ -195,13 +200,15 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None:
self._fields.move_to_end("status")
self._fields.move_to_end("cancellation_reason")
self._fields.move_to_end("cashflow_batches")
self._fields.move_to_end("is_duo")

def is_empty(self) -> bool:
return (
super().is_empty()
and not self.category.data
and not self.cancellation_reason.data
and (not self.deposit.data or self.deposit.data == DEPOSIT_DEFAULT_VALUE)
and len(self.is_duo.data) != 1
)

@property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ def _get_individual_bookings(
elif form.deposit.data == "expired":
base_query = base_query.filter(finance_models.Deposit.expirationDate <= sa.func.now())

if len(form.is_duo.data) == 1:
base_query = base_query.filter(bookings_models.Booking.quantity == form.is_duo.data[0])

or_filters = []
if form.q.data:
search_query = form.q.data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ <h5 class="modal-title">Annuler la réservation {{ booking.token }}</h5>
<td>{{ links.build_public_user_name_to_details_link(booking.user) }}</td>
<td>{{ links.build_offer_name_to_pc_pro_link(offer) }}</td>
<td>{{ links.build_offer_name_to_details_link(offer, text_attr="id") }}</td>
<td>{{ (offer.isDuo and booking.quantity == 2) | format_bool }}</td>
<td>{{ (booking.quantity == 2) | format_bool }}</td>
<td>{{ booking.stock.quantity }}</td>
<td>{{ booking.total_amount | format_amount(target=booking.user) }}</td>
<td>{{ booking | format_booking_status(with_badge=True) | safe }}</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def create_offerer_provider_with_offers(name: str, user_email: str) -> None:
subcategoryId=subcategories.CONCERT.id,
lastProvider=provider,
withdrawalType=offers_models.WithdrawalTypeEnum.IN_APP,
isDuo=bool(i % 3),
)
price_category = offers_factories.PriceCategoryFactory(offer=offer)

Expand All @@ -98,9 +99,10 @@ def create_offerer_provider_with_offers(name: str, user_email: str) -> None:
)

for _ in range(15):
stock = random.choice(stocks)
booking = bookings_factories.BookingFactory(
quantity=random.randint(1, 2),
stock=random.choice(stocks),
quantity=random.randint(1, 2 if stock.offer.isDuo else 1),
stock=stock,
dateCreated=now
+ datetime.timedelta(
days=random.randint(0, 10), hours=random.randint(0, 23), minutes=random.randint(0, 59)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def _create_offers(provider: Provider) -> Venue:
venue=venue,
subcategoryId=subcategories.SEANCE_CINE.id,
lastProvider=provider,
isDuo=True,
)
stock_duo = CinemaStockProviderFactory(offer=offer_duo)
booking_duo = BookingFactory(quantity=2, stock=stock_duo, user=user_bene)
Expand Down
9 changes: 9 additions & 0 deletions api/tests/routes/backoffice/individual_bookings_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,15 @@ def test_list_caledonian_booking_shows_xfp_amounts(self, authenticated_client):
assert "Total payé par l'utilisateur : 150,00 € (17900 CFP)" in reimbursement_data
assert "Montant remboursé : 150,00 € (17900 CFP)" in reimbursement_data

@pytest.mark.parametrize("quantity", [1, 2])
def test_display_duo_bookings(self, authenticated_client, bookings, quantity):
with assert_no_duplicated_queries():
response = authenticated_client.get(url_for(self.endpoint, is_duo=[quantity]))
assert response.status_code == 200

rows = html_parser.extract_table_rows(response.data)
assert {int(r["ID résa"]) for r in rows} == {b.id for b in bookings if b.quantity == quantity}

rpaoloni-pass marked this conversation as resolved.
Show resolved Hide resolved

class MarkBookingAsUsedTest(PostEndpointHelper):
endpoint = "backoffice_web.individual_bookings.mark_booking_as_used"
Expand Down
Loading