Skip to content

Commit

Permalink
(PC-34204)[API] feat: change is eligible for search to is released an…
Browse files Browse the repository at this point in the history
…d bookable
  • Loading branch information
bpeyrou-pass committed Feb 4, 2025
1 parent 332d2c8 commit 4d2a174
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion api/src/pcapi/core/offerers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1561,7 +1561,7 @@ def has_venue_at_least_one_bookable_offer(venue: models.Venue) -> bool:
at_least_one_eligible_offer_query = (
offers_models.Stock.query.join(offers_models.Offer)
.filter(offers_models.Offer.venueId == venue.id)
.filter(offers_models.Offer.is_eligible_for_search)
.filter(offers_models.Offer.is_released_and_bookable)
.exists()
)

Expand Down
13 changes: 11 additions & 2 deletions api/src/pcapi/core/offers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,6 @@ def __table_args__(self):

sa.Index("idx_offer_trgm_name", name, postgresql_using="gin")
sa.Index("offer_idAtProvider", idAtProvider)
sa.Index("ix_offer_ean", ean)
sa.Index("offer_ean_idx", extraData["ean"].astext)
sa.Index("offer_visa_idx", extraData["visa"].astext)
sa.Index("offer_authorId_idx", authorId, postgresql_using="btree")
Expand Down Expand Up @@ -834,10 +833,20 @@ def isBookable(self) -> bool:

@hybrid_property
def is_eligible_for_search(self) -> bool:
return self.isReleased and self.isBookable
if self.futureOffer:
return self.isReleased and self.futureOffer.isWaitingForPublication
return self.is_released_and_bookable

@is_eligible_for_search.expression # type: ignore[no-redef]
def is_eligible_for_search(cls) -> BooleanClauseList: # pylint: disable=no-self-argument
return sa.and_(cls._released, sa.or_(cls.is_released_and_bookable, FutureOffer.isWaitingForPublication))

@hybrid_property
def is_released_and_bookable(self) -> bool:
return self.isReleased and self.isBookable

@is_released_and_bookable.expression # type: ignore[no-redef]
def is_released_and_bookable(cls) -> BooleanClauseList: # pylint: disable=no-self-argument
return sa.and_(cls._released, Stock._bookable)

@hybrid_property
Expand Down
2 changes: 1 addition & 1 deletion api/src/pcapi/routes/institutional/playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def get_offers_by_tag(tag_name: str) -> serializers.OffersResponse:
.join(offers_models.Offer.stocks)
.filter(
criteria_models.Criterion.name == tag_name,
offers_models.Offer.is_eligible_for_search,
offers_models.Offer.is_released_and_bookable,
)
.options(
sqla_orm.joinedload(offers_models.Offer.stocks),
Expand Down

0 comments on commit 4d2a174

Please sign in to comment.