def get_subscriptions_formatted(self, auth_customer_id=None, per_row=3, public_only=True, link_type='shop'): """ :param public: boolean, defines whether to show only public or all subscriptions :return: list of school_subscriptions formatted for shop """ from general_helpers import get_last_day_month from openstudio.os_school_subscription import SchoolSubscription from openstudio.os_customer import Customer T = current.T TODAY_LOCAL = current.TODAY_LOCAL os_gui = current.globalenv['os_gui'] get_sys_property = current.globalenv['get_sys_property'] customer_has_membership = False customer_subscriptions_ids = [] if auth_customer_id: startdate = TODAY_LOCAL shop_subscriptions_start = get_sys_property( 'shop_subscriptions_start') if not shop_subscriptions_start == None: if shop_subscriptions_start == 'next_month': startdate = get_last_day_month( TODAY_LOCAL) + datetime.timedelta(days=1) customer = Customer(auth_customer_id) customer_has_membership = customer.has_membership_on_date( startdate) customer_subscriptions_ids = customer.get_school_subscriptions_ids_on_date( startdate) if per_row == 3: card_class = 'col-md-4' elif per_row == 4: card_class = 'col-md-3' else: raise ValueError('Incompatible value: per_row has to be 3 or 4') rows = self.get_subscriptions(public_only=public_only) subscriptions = DIV() display_row = DIV(_class='row') row_item = 0 for i, row in enumerate(rows): repr_row = list(rows[i:i + 1].render())[0] ssu = SchoolSubscription(row.id) name = max_string_length(row.Name, 33) classes = '' classes_unit = '' classes_text = T("Classes") if row.Unlimited: classes = T('Unlimited') classes_unit = T("Classes") elif row.SubscriptionUnit == 'week': if row.Classes == 1: classes_text = T("Class") classes = SPAN(str(row.Classes) + ' ' + classes_text) classes_unit = T("Per week") elif row.SubscriptionUnit == 'month': if row.Classes == 1: classes_text = T("Class") classes = SPAN(str(row.Classes) + ' ' + classes_text) classes_unit = T("Per month") subscription = DIV(DIV( self._get_formatted_display_widget_header( name, ssu.get_price_on_date(TODAY_LOCAL), ), DIV(DIV(T("Minimum duration"), ': ', repr_row.MinDuration, _class='col-md-12 bold'), DIV(repr_row.Description, _class='col-md-12'), _class='box-body'), DIV( DIV(DIV(DIV(H5('Payment', _class="description-header"), SPAN(T("Monthly"), _class="description-text"), _class="description-block"), _class="col-sm-4 border-right"), DIV(DIV(H5(classes, _class="description-header"), SPAN(classes_unit, _class="description-text"), _class="description-block"), _class="col-sm-4 border-right"), DIV(DIV(H5( self._get_subscriptions_formatted_button_to_cart( row.id, row.school_memberships_id, customer_subscriptions_ids), _class="description-header"), SPAN(T(""), _class="description-text"), _class="description-block"), _class="col-sm-4"), _class="row"), _class="box-footer", ), _class="box box-widget widget-user"), _class=card_class) # subscription_content = TABLE(TR(TD(T('Classes')), # TD(classes)), # TR(TD(T('Monthly')), # TD(ssu.get_price_on_date(datetime.date.today()))), # TR(TD(T('Description')), # TD(row.Description or '')), # _class='table') # # panel_class = 'box-primary' # # footer_content = '' # if link_type == 'shop': # footer_content = self._get_subscriptions_formatted_button_to_cart( # row.id, # row.MembershipRequired, # customer_has_membership, # customer_subscriptions_ids # ) # # subscription = DIV(os_gui.get_box_table(name, # subscription_content, # panel_class, # show_footer=True, # footer_content=footer_content), # _class=card_class) display_row.append(subscription) row_item += 1 if row_item == per_row or i == (len(rows) - 1): subscriptions.append(display_row) display_row = DIV(_class='row') row_item = 0 return subscriptions
def validate_cart(): """ Process shopping cart :return: """ # print request.env set_headers() error = False message = '' receipt_link = None receipt_items = None receipt_amounts = None receipt_pmID = None #If no customerID; just make receipt and update stock #if customerID; Make order, deliver order, add payment to invoice created by deliver order items = request.vars['items'] pmID = request.vars['payment_methodID'] cuID = request.vars['customerID'] print 'customerID' print type(cuID) print cuID print 'validate_cart_items:' print items # Verify items if not items: error = True message = T("No items were submitted for processing") if not error and not pmID: error = True message = T("No payment method was selected") # Verify customer doesn't already have subscription or membership if cuID and not error: from openstudio.os_customer import Customer customer = Customer(cuID) for item in items: if item['item_type'] == 'subscription': subscription_ids = customer.get_school_subscriptions_ids_on_date( TODAY_LOCAL) print 'validating subscriptions' print subscription_ids if item['data']['id'] in subscription_ids: error = True message = T("This customer already has this subscription") if item['item_type'] == 'membership': membership_ids = customer.get_school_memberships_ids_on_date( TODAY_LOCAL) print 'validating memberhsips' print membership_ids if item['data']['id'] in membership_ids: error = True message = T("This customer already has this membership") ## IMPORTANT: Get Item price & VAT info from server DB, not from Stuff submitted by Javascript. # JS can be manipulated. if not error: # IF customerID; add order; deliver invoice = None invoices_payment_id = None invoice_created = False if cuID: print 'create order' invoice = validate_cart_create_order(cuID, pmID, items) invoice_created = True # Always create payment receipt print 'create receipt' receipt = validate_cart_create_receipt( invoice_created, invoice, pmID, items, ) receipt_link = URL('finance', 'receipt', vars={'rID': receipt.receipts_id}, extension='', scheme=True, host=True) receipt_items = receipt.get_receipt_items_rows() print receipt_items receipt_amounts = receipt.get_amounts() receipt_pmID = receipt.row.payment_methods_id return dict(error=error, message=message, receipt_link=receipt_link, receipt_items=receipt_items, receipt_amounts=receipt_amounts, receipt_payment_methods_id=receipt_pmID)