Skip to content

Commit

Permalink
(PC-33423)[API] feat: change headline offer creation in the sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
ogeber-pass committed Dec 24, 2024
1 parent b79fb82 commit 1d1c699
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
5 changes: 0 additions & 5 deletions api/src/pcapi/core/offers/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,6 @@ def _create(

return super()._create(model_class, *args, **kwargs)

@factory.post_generation
def is_headline_offer(self, create: bool, is_headline_offer: bool = False, **kwargs: typing.Any) -> None:
if is_headline_offer:
HeadlineOfferFactory(offer=self, venue=self.venue)


class ArtistProductLinkFactory(BaseFactory):
class Meta:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pcapi.core.offerers.models as offerers_models
import pcapi.core.offers.factories as offers_factories
import pcapi.core.offers.models as offers_models
from pcapi.models.offer_mixin import OfferStatus
from pcapi.repository import repository
from pcapi.sandboxes.scripts.mocks.event_mocks import MOCK_NAMES

Expand Down Expand Up @@ -59,11 +60,19 @@ def create_industrial_event_offers(
),
isActive=is_active,
isDuo=is_duo,
is_headline_offer=bool(headline_offer_limit_per_offerer and not event_venue.has_headline_offer),
)
if (
headline_offer_limit_per_offerer
and event_offers_by_name[name].status == OfferStatus.ACTIVE
and not event_venue.has_headline_offer
):
offers_factories.HeadlineOfferFactory(offer=event_offers_by_name[name], venue=event_venue)
headline_offer_limit_per_offerer = (
headline_offer_limit_per_offerer - 1
if headline_offer_limit_per_offerer > 0
else headline_offer_limit_per_offerer
)
offer_index += 1
# FIXME : 6.12.2024 ogeber : decrement headline_offer_limit_per_offerer (limit 0) if original limit is > 1
headline_offer_limit_per_offerer = 0

event_index += EVENTS_PER_OFFERER_WITH_PHYSICAL_VENUE

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pcapi.core.offerers.models as offerers_models
import pcapi.core.offers.factories as offers_factories
import pcapi.core.offers.models as offers_models
from pcapi.models.offer_mixin import OfferStatus
from pcapi.repository import repository
from pcapi.sandboxes.scripts.mocks.thing_mocks import MOCK_NAMES

Expand Down Expand Up @@ -65,12 +66,21 @@ def create_industrial_thing_offers(
url="http://example.com" if subcategory.is_online_only else None,
idAtProvider=str(id_at_provider),
extraData=offers_factories.build_extra_data_from_subcategory(subcategory.id, set_all_fields=False),
is_headline_offer=bool(headline_offer_limit_per_offerer and not thing_venue.has_headline_offer),
)
if (
headline_offer_limit_per_offerer
and thing_offers_by_name[name].status == OfferStatus.ACTIVE
and not thing_venue.has_headline_offer
):
offers_factories.HeadlineOfferFactory(offer=thing_offers_by_name[name], venue=thing_venue)
offer_index += 1
headline_offer_limit_per_offerer = (
headline_offer_limit_per_offerer - 1
if headline_offer_limit_per_offerer > 0
else headline_offer_limit_per_offerer
)
offer_index += 1
id_at_provider += 1
# FIXME : 6.12.2024 ogeber : decrement headline_offer_limit_per_offerer (limit 0) if original limit is > 1
headline_offer_limit_per_offerer = 0

thing_index += THINGS_PER_OFFERER

Expand Down

0 comments on commit 1d1c699

Please sign in to comment.