Beispiel #1
0
    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
Beispiel #2
0
    def get_classcards_formatted(self,
                                 auth_user_id=None,
                                 public_only=True,
                                 per_row=3,
                                 link_type=None):
        """
            :param public_only: show only public cards - Default: True
            :param per_row: Number of cards in each row - Default 4. Allowed values: [3, 4]
            :param link_type: Specified what kind of link will be shown in the footer of each classcard.
                Allowed values: ['backend', 'shop']
                - backend adds a modal to choose date
                - shop adds a button to add the card to the shopping cart
            Returns classcards formatted in BS3 style

        """
        def get_validity(row):
            """
                takes a db.school_classcards() row as argument
            """
            validity = SPAN(str(row.Validity), ' ')

            validity_in = represent_validity_units(row.ValidityUnit, row)
            if row.Validity == 1:  # Cut the last 's"
                validity_in = validity_in[:-1]

            validity.append(validity_in)

            return validity

        from .os_customer import Customer

        TODAY_LOCAL = current.TODAY_LOCAL
        os_gui = current.globalenv['os_gui']
        T = current.T

        customer_has_membership = False
        if auth_user_id:
            customer = Customer(auth_user_id)
            customer_has_membership = customer.has_membership_on_date(
                TODAY_LOCAL)

        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_classcards(auth_user_id=auth_user_id,
                                   public_only=public_only)

        cards = DIV()
        display_row = DIV(_class='row')
        row_item = 0

        for i, row in enumerate(rows):
            repr_row = list(rows[i:i + 1].render())[0]

            card_name = max_string_length(row.Name, 37)
            validity = get_validity(row)

            over_trial_times = self._get_classcards_formatted_trialcard_over_times_available(
                row)

            description = repr_row.Description
            btn_cart = self._get_classcards_formatted_button_to_cart(
                row.id, row.school_memberships_id, customer_has_membership)
            if over_trial_times:
                description = T(
                    "You've reached the maximum number of times you can purchase this card."
                )
                btn_cart = SPAN(os_gui.get_fa_icon('fa-ban fa-2x'),
                                _class='grey')

            card = DIV(DIV(DIV(
                self._get_formatted_display_widget_header(
                    card_name, repr_row.Price)),
                           DIV(DIV(description, _class='col-md-12'),
                               _class='box-body'),
                           DIV(
                               DIV(DIV(DIV(H5(validity,
                                              _class="description-header"),
                                           SPAN(T("Validity"),
                                                _class="description-text"),
                                           _class="description-block"),
                                       _class="col-sm-4 border-right"),
                                   DIV(DIV(H5(repr_row.Classes,
                                              _class="description-header"),
                                           SPAN(T("Classes"),
                                                _class="description-text"),
                                           _class="description-block"),
                                       _class="col-sm-4 border-right"),
                                   DIV(DIV(H5(btn_cart,
                                              _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)

            display_row.append(card)

            row_item += 1

            if row_item == per_row or i == (len(rows) - 1):
                cards.append(display_row)
                display_row = DIV(_class='row')

                row_item = 0

        return cards
Beispiel #3
0
    def get_prices_customer(self, cuID):
        """
            Returns the price for a class
            :param cuID: db.auth_user.id
            :return: dict of class prices
        """
        from openstudio.os_customer import Customer

        db = current.db
        customer = Customer(cuID)
        has_membership = customer.has_membership_on_date(self.date)

        dropin = 0
        trial = 0
        trial_tax_rates_id = None
        dropin_tax_rates_id = None
        trial_tax_percentage = None
        dropin_tax_percentage = None
        dropin_glaccount = None
        trial_glaccount = None
        dropin_costcenter = None
        trial_costcenter = None


        query = (db.classes_price.classes_id == self.clsID) & \
                (db.classes_price.Startdate <= self.date) & \
                ((db.classes_price.Enddate >= self.date) |
                 (db.classes_price.Enddate == None))
        prices = db(query).select(db.classes_price.ALL,
                                  orderby=db.classes_price.Startdate)

        if prices:
            prices = prices.first()

            dropin_glaccount = prices.accounting_glaccounts_id_dropin
            trial_glaccount = prices.accounting_glaccounts_id_trial
            dropin_costcenter = prices.accounting_costcenters_id_dropin
            trial_costcenter = prices.accounting_costcenters_id_trial

            dropin = prices.Dropin or 0
            trial = prices.Trial or 0

            dropin_tax = db.tax_rates(prices.tax_rates_id_dropin)
            trial_tax = db.tax_rates(prices.tax_rates_id_trial)

            if has_membership and prices.DropinMembership:
                dropin = prices.DropinMembership
                dropin_tax = db.tax_rates(
                    prices.tax_rates_id_dropin_membership)

            if has_membership and prices.TrialMembership:
                trial = prices.TrialMembership
                trial_tax = db.tax_rates(prices.tax_rates_id_trial_membership)

            try:
                dropin_tax_rates_id = dropin_tax.id
                dropin_tax_percentage = dropin_tax.Percentage
            except AttributeError:
                pass

            try:
                trial_tax_rates_id = trial_tax.id
                trial_tax_percentage = trial_tax.Percentage
            except AttributeError:
                pass

        return dict(trial=trial,
                    dropin=dropin,
                    trial_tax_rates_id=trial_tax_rates_id,
                    dropin_tax_rates_id=dropin_tax_rates_id,
                    trial_tax_percentage=trial_tax_percentage,
                    dropin_tax_percentage=dropin_tax_percentage,
                    dropin_glaccount=dropin_glaccount,
                    dropin_costcenter=dropin_costcenter,
                    trial_glaccount=trial_glaccount,
                    trial_costcenter=trial_costcenter)