def get_order_for_event(event, form, registration=None, partner_registration=None): assert isinstance(event, Event) user_order = Order() for product_model in event.products: product = get_product_by_model(product_model) product_form = form.get_product_by_key(product_model.product_key) if product.is_selected(product_form): order_product = product.get_order_product_model( product_model, product_form, form) if type(order_product) is list: order_product[0].registration = registration order_product[1].registration = partner_registration user_order.order_products.append(order_product[0]) user_order.order_products.append(order_product[1]) else: # registration_model = get_registration_from_form(form) order_product.registration = registration if product_form.needs_partner(): # partner_registration_model = get_partner_registration_from_form(form) order_product.registration = partner_registration user_order.order_products.append(order_product) products_price = user_order.products_price user_order.transaction_fee = transaction_fee(products_price) user_order.total_price = user_order.products_price add_payment_to_user_order(user_order) return user_order
def process_mts_group_registrations(user_order, form): group_discount_model = user_order.event.products.filter_by( type='FestivalGroupDiscountProduct').first() discount_product = get_product_by_model(group_discount_model) group_form = form.get_product_by_key(group_discount_model.product_key) if discount_product.is_selected(group_form) and \ discount_product.get_total_price(group_discount_model, group_form, form): if group_form.group_participation.data == 'new': group = RegistrationGroup( name=group_form.group_name.data, location=group_form.location.data, description=group_form.group_description.data, event_id=user_order.event.id) db_session.add(group) db_session.commit() else: serialiser = GroupToken() group = serialiser.deserialize(group_form.group_token.data.strip()) registrations = Registration.query.join( OrderProduct, aliased=False).filter_by(order_id=user_order.id).all() for reg in registrations: reg.registration_group = group db_session.commit()
def balance_event_waiting_lists(event_model): for product_model in event_model.products: product = get_product_by_model(product_model) if hasattr(product, 'balance_waiting_list'): results = product.balance_waiting_list(product_model) for order_product in results: send_acceptance_from_waiting_list(order_product) return results
def add_payment_to_user_order(user_order): payment = Payment() for order_product in user_order.order_products: product = get_product_by_model(order_product.product) payment_item = product.get_payment_item(order_product) payment.payment_items.append(payment_item) update_payment_total(payment) payment.transaction_fee = transaction_fee(payment.amount) user_order.payments.append(payment)
def process_partner_registrations(user_order, form): for product_model in user_order.event.products: product = get_product_by_model(product_model) product_form = form.get_product_by_key(product_model.product_key) if isinstance(product, RegularPartnerWorkshop) and product_form.add.data: waiting_lists_couple = product.get_waiting_lists(product_model)[1] if product_form.partner_token.data: order_product = user_order.order_products.join( Product, aliased=True).filter_by(id=product_model.id).first() partner_order_product = order_product_deserialize( product_form.partner_token.data) group = create_partners_group(order_product, partner_order_product) db_session.add(group) if partner_order_product.status == ORDER_PRODUCT_STATUS_WAITING: partner_role = partner_order_product.details_as_dict[ 'dance_role'] if not waiting_lists_couple[partner_role]: partner_order_product.accept() send_acceptance_from_waiting_list( partner_order_product) elif product_form.add.data == 'couple': order_products = OrderProduct.query.filter_by(order_id=user_order.id). \ join(Product, aliased=True).filter_by(id=product_model.id).all() group = create_partners_group(order_products[0], order_products[1]) db_session.add(group) db_session.commit() elif isinstance(product, CouplesOnlyWorkshop) and product_form.add.data: if product_form.partner_token.data: order_product = user_order.order_products.join( Product, aliased=True).filter_by(id=product_model.id).first() partner_order_product = order_product_deserialize( product_form.partner_token.data) group = create_partners_group(order_product, partner_order_product) db_session.add(group) partner_order_product.accept() send_acceptance_from_waiting_partner(partner_order_product) elif product_form.add.data == 'couple': order_products = OrderProduct.query.filter_by(order_id=user_order.id). \ join(Product, aliased=True).filter_by(id=product_model.id).all() group = create_partners_group(order_products[0], order_products[1]) db_session.add(group) db_session.commit()
def create_crowdfunding_form(event): assert (isinstance(event, Event)) class EventForm(CrowdfundingSignupForm): pass product_keys = [] for product_model in event.products: product = get_product_by_model(product_model) product_key = product_model.product_key setattr(EventForm, product_key, FormField(product.get_form(product_model=product_model))) product_keys.append(product_key) setattr(EventForm, 'product_keys', product_keys) return EventForm
def get_order_for_crowdfunding_event(event, form, registration=None, partner_registration=None): assert isinstance(event, Event) user_order = Order() for product_model in event.products: product = get_product_by_model(product_model) product_form = form.get_product_by_key(product_model.product_key) price = product.get_total_price(product_model, product_form, form) if price > 0: # registration_model = get_registration_from_form(form) if hasattr(product_form, 'add'): print(product_form.add.object_data, type(product_form.add.object_data)) print(product_form.add.object_data == None) if product_form.add.data not in ['0', 'None']: for n in range(int(product_form.add.data)): order_product = product.get_order_product_model( product_model, product_form, form) order_product.registration = registration user_order.order_products.append(order_product) else: order_product = product.get_order_product_model( product_model, product_form, form) order_product.registration = registration user_order.order_products.append(order_product) products_price = user_order.products_price user_order.transaction_fee = transaction_fee(products_price) user_order.total_price = user_order.products_price add_payment_to_user_order(user_order) return user_order
def name(self): product = get_product_by_model(self._order_product.product) if hasattr(product, 'get_name'): return product.get_name(self._order_product) else: return self._order_product.product.name
def mts_get_order_for_event(event, form, registration=None, partner_registration=None): assert isinstance(event, Event) user_order = Order() free_classes_remaining = 0 mts_form_controller = MtsSignupFormController(form) weekend_ticket_key = mts_form_controller.weekend_ticket_key if weekend_ticket_key: weekend_ticket_form = form.get_product_by_key(weekend_ticket_key) if mts_form_controller.full_pass_selected: free_classes_remaining = 3 for product_model in event.products: product = get_product_by_model(product_model) product_form = form.get_product_by_key(product_model.product_key) if product.is_selected(product_form): order_product = product.get_order_product_model( product_model, product_form, form) if type(order_product) is list: if weekend_ticket_key: product_keywords = product.keywords.split(',') if weekend_ticket_form.includes and set( weekend_ticket_form.includes.split( ',')).intersection(product_keywords): order_product[0].price = 0 order_product[1].price = 0 elif isinstance(product, RegularPartnerWorkshop): if free_classes_remaining: order_product[0].price = 0 order_product[1].price = 0 free_classes_remaining -= 1 elif mts_form_controller.is_special_extra_block_price: order_product[ 0].price = product.get_discount_price_by_key( 'extra_block') order_product[ 1].price = product.get_discount_price_by_key( 'extra_block') order_product[0].registration = registration order_product[1].registration = partner_registration user_order.order_products.append(order_product[0]) user_order.order_products.append(order_product[1]) else: if weekend_ticket_key: product_keywords = product.keywords.split(',') if weekend_ticket_form.includes and set( weekend_ticket_form.includes.split( ',')).intersection(product_keywords): order_product.price = 0 elif isinstance(product, RegularPartnerWorkshop): if free_classes_remaining: order_product.price = 0 free_classes_remaining -= 1 elif mts_form_controller.is_special_extra_block_price: order_product.price = product.get_discount_price_by_key( 'extra_block') # registration_model = get_registration_from_form(form) order_product.registration = registration if product_form.needs_partner(): # partner_registration_model = get_partner_registration_from_form(form) order_product.registration = partner_registration user_order.order_products.append(order_product) products_price = user_order.products_price user_order.transaction_fee = transaction_fee(products_price) user_order.total_price = user_order.products_price add_payment_to_user_order(user_order) return user_order
from salty_tickets.models import Event from salty_tickets import products for product_model in Event.query.filter_by(id=5).one().products: print(product_model.name) product = products.get_product_by_model(product_model) print('\t', product.get_registration_stats(product_model)) for order_product in product_model.product_orders: if order_product.order.status == 'paid': print('\t', order_product.registrations[0].name, order_product.registrations[0].email, order_product.details_as_dict['dance_role'], order_product.status)