def _initialize_offer_with_new_data(offer_data: PostOfferBodyModel, subcategory: subcategories.Subcategory, venue: Venue) -> Offer: data = offer_data.dict(by_alias=True) product = Product() if data.get("url"): data["isNational"] = True product.populate_from_dict(data) offer = Offer() offer.populate_from_dict(data) offer.product = product offer.subcategoryId = subcategory.id if subcategory else None offer.product.owningOfferer = venue.managingOfferer return offer
def create_offer(offer_data: PostOfferBodyModel, user: User) -> Offer: venue = load_or_raise_error(Venue, offer_data.venue_id) check_user_has_access_to_offerer(user, offerer_id=venue.managingOffererId) if offer_data.product_id: product = load_or_raise_error(Product, offer_data.product_id) offer = Offer( product=product, type=product.type, name=product.name, description=product.description, url=product.url, mediaUrls=product.mediaUrls, conditions=product.conditions, ageMin=product.ageMin, ageMax=product.ageMax, durationMinutes=product.durationMinutes, isNational=product.isNational, extraData=product.extraData, ) else: if offer_data.type == str(EventType.ACTIVATION): validation.check_user_can_create_activation_event(user) data = offer_data.dict(by_alias=True) product = Product() if data.get("url"): data["isNational"] = True product.populate_from_dict(data) offer = Offer() offer.populate_from_dict(data) offer.product = product offer.product.owningOfferer = venue.managingOfferer offer.venue = venue offer.bookingEmail = offer_data.booking_email offer.externalTicketOfficeUrl = offer_data.external_ticket_office_url offer.audioDisabilityCompliant = offer_data.audio_disability_compliant offer.mentalDisabilityCompliant = offer_data.mental_disability_compliant offer.motorDisabilityCompliant = offer_data.motor_disability_compliant offer.visualDisabilityCompliant = offer_data.visual_disability_compliant repository.save(offer) admin_emails.send_offer_creation_notification_to_administration( offer, user) return offer
def create_offer(offer_data: PostOfferBodyModel, user: User) -> models.Offer: venue = load_or_raise_error(VenueSQLEntity, offer_data.venue_id) ensure_current_user_has_rights(rights=RightsType.editor, offerer_id=venue.managingOffererId, user=user) if offer_data.product_id: product = load_or_raise_error(Product, offer_data.product_id) offer = models.Offer( product=product, type=product.type, name=product.name, description=product.description, url=product.url, mediaUrls=product.mediaUrls, conditions=product.conditions, ageMin=product.ageMin, ageMax=product.ageMax, durationMinutes=product.durationMinutes, isNational=product.isNational, extraData=product.extraData, ) else: if offer_data.type == str(EventType.ACTIVATION): validation.check_user_can_create_activation_event(user) data = offer_data.dict(by_alias=True) product = Product() if data.get("url"): data["isNational"] = True product.populate_from_dict(data) offer = Offer() offer.populate_from_dict(data) offer.product = product offer.product.owningOfferer = venue.managingOfferer offer.venue = venue offer.bookingEmail = offer_data.booking_email repository.save(offer) admin_emails.send_offer_creation_notification_to_administration(offer, user, mailing.send_raw_email) return offer