diff --git a/api/src/pcapi/core/offerers/repository.py b/api/src/pcapi/core/offerers/repository.py index fe7d29a44b2..ecabc1ecf93 100644 --- a/api/src/pcapi/core/offerers/repository.py +++ b/api/src/pcapi/core/offerers/repository.py @@ -886,18 +886,16 @@ def get_offerer_address_of_offerer(offerer_id: int, offerer_address_id: int) -> def get_offerer_headline_offer(offerer_id: int) -> offers_models.Offer | None: try: - # FIXME: ogeber: when offers will be able to have several headline offers, and unicity of the headline - # offer will be on its active status, change this query and add a filter on active headline offer only offer = ( offers_models.Offer.query.join(models.Venue, offers_models.Offer.venueId == models.Venue.id) .join(models.Offerer, models.Venue.managingOffererId == models.Offerer.id) .join(offers_models.HeadlineOffer, offers_models.HeadlineOffer.offerId == offers_models.Offer.id) .options( - sqla_orm.contains_eager(offers_models.Offer.headlineOffer), + sqla_orm.contains_eager(offers_models.Offer.headlineOffers), sqla_orm.joinedload(offers_models.Offer.mediations), sqla_orm.joinedload(offers_models.Offer.product).joinedload(offers_models.Product.productMediations), ) - .filter(models.Offerer.id == offerer_id) + .filter(models.Offerer.id == offerer_id, offers_models.HeadlineOffer.isActive == True) .one_or_none() ) diff --git a/api/tests/core/offerers/test_repository.py b/api/tests/core/offerers/test_repository.py index 4ae99092a4f..1e187107b4a 100644 --- a/api/tests/core/offerers/test_repository.py +++ b/api/tests/core/offerers/test_repository.py @@ -276,6 +276,7 @@ def test_get_offerer_addresses(self): class GetOffererHeadlineOfferTest: def test_return_headline_offer(self): offer = offers_factories.OfferFactory() + offers_factories.StockFactory(offer=offer) offers_factories.HeadlineOfferFactory(offer=offer, venue=offer.venue) headline_offer = repository.get_offerer_headline_offer(offer.venue.managingOffererId) @@ -287,7 +288,9 @@ def test_shoud_not_return_several_headline_offer(self): venue = offerers_factories.VenueFactory(managingOfferer=offerer) other_venue = offerers_factories.VenueFactory(managingOfferer=offerer) offer = offers_factories.OfferFactory(venue=venue) + offers_factories.StockFactory(offer=offer) other_offer = offers_factories.OfferFactory(venue=other_venue) + offers_factories.StockFactory(offer=other_offer) offers_factories.HeadlineOfferFactory(offer=offer, venue=venue) offers_factories.HeadlineOfferFactory(offer=other_offer, venue=other_venue) diff --git a/api/tests/routes/native/v1/offerers_test.py b/api/tests/routes/native/v1/offerers_test.py index 1cdee3cf6b0..0e10eb67ae0 100644 --- a/api/tests/routes/native/v1/offerers_test.py +++ b/api/tests/routes/native/v1/offerers_test.py @@ -211,6 +211,7 @@ def test_get_offerer_headline_offer_success(self, client): offerer = user_offerer.offerer venue = offerers_factories.VenueFactory(managingOfferer=offerer) offer = offers_factories.OfferFactory(venue=venue) + offers_factories.StockFactory(offer=offer) offers_factories.HeadlineOfferFactory(offer=offer, venue=venue) client = client.with_session_auth(email=pro.email) diff --git a/api/tests/routes/pro/get_offerer_headline_offer_test.py b/api/tests/routes/pro/get_offerer_headline_offer_test.py index b43cc9cdd9b..92930ef3252 100644 --- a/api/tests/routes/pro/get_offerer_headline_offer_test.py +++ b/api/tests/routes/pro/get_offerer_headline_offer_test.py @@ -24,6 +24,7 @@ def test_get_offerer_headline_offer_success(self, client): offerer = user_offerer.offerer venue = offerers_factories.VenueFactory(managingOfferer=offerer) offer = offers_factories.OfferFactory(venue=venue) + offers_factories.StockFactory(offer=offer) offers_factories.HeadlineOfferFactory(offer=offer, venue=venue) client = client.with_session_auth(email=pro.email) offerer_id = offerer.id @@ -52,6 +53,7 @@ def test_get_offerer_headline_offer_with_product_mediations(self, client): offers_factories.ProductMediationFactory(product=product, imageType=TiteliveImageType.VERSO) offer = offers_factories.OfferFactory(venue=venue, product=product) + offers_factories.StockFactory(offer=offer) offers_factories.HeadlineOfferFactory(offer=offer, venue=venue) client = client.with_session_auth(email=pro.email) offerer_id = offerer.id @@ -91,9 +93,11 @@ def test_with_multiple_headline_offer_on_one_offerer_should_fail(self, client): offerer = user_offerer.offerer venue = offerers_factories.VenueFactory(managingOfferer=offerer) offer = offers_factories.OfferFactory(venue=venue) + offers_factories.StockFactory(offer=offer) offers_factories.HeadlineOfferFactory(offer=offer, venue=venue) other_venue = offerers_factories.VenueFactory(managingOfferer=offerer) other_offer = offers_factories.OfferFactory(venue=other_venue) + offers_factories.StockFactory(offer=other_offer) offers_factories.HeadlineOfferFactory(offer=other_offer, venue=other_venue) client = client.with_session_auth(email=pro.email) offerer_id = offerer.id