def get_discounted_prices(self): prices = self.cleaned_data['prices'] price_list = [Decimal(price) for price in prices.split(';')] return assign_discount(price_list, self.discount)
def add_registration(*args, **kwargs): """ Add the registration Args are split up below into the appropriate attributes """ # arguments were getting kinda long # moved them to an unpacked version (request, event, reg_form, registrant_formset, addon_formset, price, event_price) = args total_amount = 0 count = 0 event_price = Decimal(str(event_price)) #kwargs admin_notes = kwargs.get('admin_notes', None) custom_reg_form = kwargs.get('custom_reg_form', None) override_table = False override_price_table = Decimal(0) if event.is_table and request.user.is_superuser: override_table = reg_form.cleaned_data.get('override_table', False) override_price_table = reg_form.cleaned_data.get('override_price_table', Decimal(0)) if override_price_table == None: override_price_table = 0 # get the list of amount for registrants. amount_list = [] if event.is_table: if override_table: amount_list.append(override_price_table) else: amount_list.append(event_price) else: override_price_total = Decimal(0) for i, form in enumerate(registrant_formset.forms): override = False override_price = Decimal(0) if request.user.is_superuser: override = form.cleaned_data.get('override', False) override_price = form.cleaned_data.get('override_price', Decimal(0)) price = form.cleaned_data.get('pricing', 0) if override: amount = override_price override_price_total += amount else: amount = price.price amount_list.append(amount) # apply discount if any discount_code = reg_form.cleaned_data.get('discount_code', None) discount_amount = Decimal(0) discount_list = [Decimal(0) for i in range(len(amount_list))] if discount_code: [discount] = Discount.objects.filter(discount_code=discount_code, apps__model=RegistrationConfiguration._meta.module_name)[:1] or [None] if discount and discount.available_for(1): amount_list, discount_amount, discount_list, msg = assign_discount(amount_list, discount) invoice_discount_amount = discount_amount reg8n_attrs = { "event": event, "payment_method": reg_form.cleaned_data.get('payment_method'), "amount_paid": str(total_amount), "reg_conf_price": price, 'is_table': event.is_table, 'override_table': override_table, 'override_price_table': override_price_table } if event.is_table: reg8n_attrs['quantity'] = price.quantity if request.user.is_authenticated(): reg8n_attrs['creator'] = request.user reg8n_attrs['owner'] = request.user # create registration reg8n = Registration.objects.create(**reg8n_attrs) if event.is_table: table_individual_first_price, table_individual_price = amount_list[0], Decimal('0') # discount_applied = False for i, form in enumerate(registrant_formset.forms): override = False override_price = Decimal(0) if not event.is_table: if request.user.is_superuser: override = form.cleaned_data.get('override', False) override_price = form.cleaned_data.get('override_price', Decimal(0)) price = form.cleaned_data['pricing'] # this amount has taken account into admin override and discount code amount = amount_list[i] if discount_code and discount_amount: discount_amount = discount_list[i] else: # table individual if i == 0: amount = table_individual_first_price else: amount = table_individual_price # if reg8n.override_table: # override = reg8n.override_table # override_price = amount # the table registration form does not have the DELETE field if event.is_table or not form in registrant_formset.deleted_forms: registrant_args = [ form, event, reg8n, price, amount ] registrant_kwargs = {'custom_reg_form': custom_reg_form, 'is_primary': i==0, 'override': override, 'override_price': override_price} if not event.is_table: registrant_kwargs['discount_amount'] = discount_list[i] registrant = create_registrant_from_form(*registrant_args, **registrant_kwargs) total_amount += registrant.amount count += 1 # create each regaddon for form in addon_formset.forms: form.save(reg8n) addons_price = addon_formset.get_total_price() total_amount += addons_price # update reg8n with the real amount reg8n.amount_paid = total_amount created = True # create invoice invoice = reg8n.save_invoice(admin_notes=admin_notes) if discount_code and invoice_discount_amount: invoice.discount_code = discount_code invoice.discount_amount = invoice_discount_amount invoice.save() if discount_code and discount: for dmount in discount_list: if dmount > 0: DiscountUse.objects.create( discount=discount, invoice=invoice, ) return (reg8n, created)
def get_discounted_prices(self): prices = self.cleaned_data['prices'] price_list = [Decimal(price) for price in prices.split(';')] return assign_discount(price_list, self.discount)
def add_registration(*args, **kwargs): """ Add the registration Args are split up below into the appropriate attributes """ # arguments were getting kinda long # moved them to an unpacked version (request, event, reg_form, registrant_formset, addon_formset, price, event_price) = args total_amount = 0 count = 0 event_price = Decimal(str(event_price)) #kwargs admin_notes = kwargs.get('admin_notes', None) custom_reg_form = kwargs.get('custom_reg_form', None) override_table = False override_price_table = Decimal(0) if event.is_table and request.user.is_superuser: override_table = reg_form.cleaned_data.get('override_table', False) override_price_table = reg_form.cleaned_data.get( 'override_price_table', Decimal(0)) if override_price_table == None: override_price_table = 0 # get the list of amount for registrants. amount_list = [] if event.is_table: if override_table: amount_list.append(override_price_table) else: amount_list.append(event_price) else: override_price_total = Decimal(0) for i, form in enumerate(registrant_formset.forms): override = False override_price = Decimal(0) if request.user.is_superuser: override = form.cleaned_data.get('override', False) override_price = form.cleaned_data.get('override_price', Decimal(0)) price = form.cleaned_data['pricing'] if override: amount = override_price override_price_total += amount else: amount = price.price amount_list.append(amount) # apply discount if any discount_code = reg_form.cleaned_data.get('discount_code', None) discount_amount = Decimal(0) discount_list = [Decimal(0) for i in range(len(amount_list))] if discount_code: [ discount ] = Discount.objects.filter(discount_code=discount_code)[:1] or [None] if discount and discount.available_for(1): amount_list, discount_amount, discount_list, msg = assign_discount( amount_list, discount) reg8n_attrs = { "event": event, "payment_method": reg_form.cleaned_data.get('payment_method'), "amount_paid": str(total_amount), "reg_conf_price": price, 'is_table': event.is_table, 'override_table': override_table, 'override_price_table': override_price_table } if discount_code and discount_amount: reg8n_attrs.update({ 'discount_code': discount_code, 'discount_amount': discount_amount }) if event.is_table: reg8n_attrs['quantity'] = price.quantity if request.user.is_authenticated(): reg8n_attrs['creator'] = request.user reg8n_attrs['owner'] = request.user # create registration reg8n = Registration.objects.create(**reg8n_attrs) if event.is_table: table_individual_first_price, table_individual_price = amount_list[ 0], Decimal('0') # discount_applied = False for i, form in enumerate(registrant_formset.forms): override = False override_price = Decimal(0) if not event.is_table: if request.user.is_superuser: override = form.cleaned_data.get('override', False) override_price = form.cleaned_data.get('override_price', Decimal(0)) price = form.cleaned_data['pricing'] # this amount has taken account into admin override and discount code amount = amount_list[i] if discount_code and discount_amount: discount_amount = discount_list[i] else: # table individual if i == 0: amount = table_individual_first_price else: amount = table_individual_price # if reg8n.override_table: # override = reg8n.override_table # override_price = amount # the table registration form does not have the DELETE field if event.is_table or not form in registrant_formset.deleted_forms: registrant_args = [form, event, reg8n, price, amount] registrant_kwargs = { 'custom_reg_form': custom_reg_form, 'is_primary': i == 0, 'override': override, 'override_price': override_price } if not event.is_table: registrant_kwargs['discount_amount'] = discount_list[i] registrant = create_registrant_from_form(*registrant_args, **registrant_kwargs) total_amount += registrant.amount count += 1 # create each regaddon for form in addon_formset.forms: form.save(reg8n) addons_price = addon_formset.get_total_price() total_amount += addons_price # update reg8n with the real amount reg8n.amount_paid = total_amount created = True # create invoice invoice = reg8n.save_invoice(admin_notes=admin_notes) if discount_code and discount: for dmount in discount_list: if dmount > 0: DiscountUse.objects.create( discount=discount, invoice=invoice, ) return (reg8n, created)