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 Jan 6, 2025
1 parent 423ca9f commit 3cf7c3d
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 14 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 @@ -23,6 +23,9 @@
from pcapi.sandboxes.scripts.creators.industrial.create_industrial_event_occurrences import *
from pcapi.sandboxes.scripts.creators.industrial.create_industrial_event_offers import *
from pcapi.sandboxes.scripts.creators.industrial.create_industrial_event_stocks import *
from pcapi.sandboxes.scripts.creators.industrial.create_industrial_headline_offers import (
create_industrial_headline_offers,
)
from pcapi.sandboxes.scripts.creators.industrial.create_industrial_incidents import create_industrial_incidents
from pcapi.sandboxes.scripts.creators.industrial.create_industrial_individual_offerers import (
create_industrial_individual_offerers,
Expand Down Expand Up @@ -102,6 +105,8 @@ def save_industrial_sandbox() -> None:

create_industrial_mediations(offers_by_name)

create_industrial_headline_offers(offers_by_name)

criteria_by_name = create_industrial_criteria()

associate_criterion_to_one_offer_with_mediation(offers_by_name, criteria_by_name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def create_industrial_event_offers(
continue

event_venue = event_venues[0]
headline_offer_limit_per_offerer = 1

for venue_event_index in range(0, EVENTS_PER_OFFERER_WITH_PHYSICAL_VENUE):
event_subcategory_index = (venue_event_index + event_index) % len(event_subcategories)
Expand All @@ -59,11 +58,8 @@ 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),
)
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
@@ -0,0 +1,37 @@
import logging

import pcapi.core.offers.factories as offers_factories
from pcapi.core.offers.models import Offer
from pcapi.models.offer_mixin import OfferStatus


logger = logging.getLogger(__name__)

HEADLINE_OFFER_LIMIT_PER_OFFERER = 1


def create_industrial_headline_offers(offers_by_name: dict[str, Offer]) -> None:
logger.info("create_industrial_headline_offers")

headline_offer_limit_per_offerer = {}
offerers = {offer.venue.managingOfferer.name: offer.venue.managingOfferer for offer in offers_by_name.values()}
for offerer_name in offerers.keys():
headline_offer_limit_per_offerer[offerer_name] = HEADLINE_OFFER_LIMIT_PER_OFFERER

headline_offers_by_name = {}
for offer_name, offer in offers_by_name.items():
offerer_name = offer.venue.managingOfferer.name
if (
headline_offer_limit_per_offerer[offerer_name]
and offer.status == OfferStatus.ACTIVE
and not offer.venue.has_headline_offer
):
headline_offers_by_name[offer_name] = offers_factories.HeadlineOfferFactory(offer=offer, venue=offer.venue)

headline_offer_limit_per_offerer[offerer_name] = (
headline_offer_limit_per_offerer[offerer_name] - 1
if headline_offer_limit_per_offerer[offerer_name] > 0
else headline_offer_limit_per_offerer[offerer_name]
)

logger.info("created %d headline offers", len(headline_offers_by_name))
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ def create_industrial_thing_offers(
physical_venue_name = virtual_venue.name.replace(" (Offre numérique)", "")
physical_venue = venues_by_name.get(physical_venue_name)

headline_offer_limit_per_offerer = 1

for venue_thing_index in range(0, THINGS_PER_OFFERER):
thing_venue = None
subcategory_index = (venue_thing_index + thing_index) % len(thing_subcategories)
Expand Down Expand Up @@ -65,12 +63,9 @@ 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),
)
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 3cf7c3d

Please sign in to comment.