-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(PC-33423)[API] feat: change headline offer creation in the sandbox
- Loading branch information
1 parent
423ca9f
commit 3cf7c3d
Showing
5 changed files
with
42 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
api/src/pcapi/sandboxes/scripts/creators/industrial/create_industrial_headline_offers.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters