Ejemplo n.º 1
0
def membership_buy_now():
    """
        Get a membership
    """
    from openstudio.os_customer_membership import CustomerMembership
    from openstudio.os_school_membership import SchoolMembership

    smID = request.vars['smID']

    # init mollie
    mollie = Client()
    mollie_api_key = get_sys_property('mollie_website_profile')
    mollie.set_api_key(mollie_api_key)

    # check if we have a mollie customer id
    create_mollie_customer(auth.user.id, mollie)

    # Create invoice
    sm = SchoolMembership(smID)
    cmID = sm.sell_to_customer(auth.user.id, TODAY_LOCAL)

    cm = CustomerMembership(cmID)
    iID = cm.get_linked_invoice()

    # Pay invoice ... SHOW ME THE MONEY!! :)
    redirect(URL('invoice_pay', vars={'iID': iID}))
Ejemplo n.º 2
0
    def item_add_membership(self, cmID, period_start, period_end):
        """
        :param cmID: db.customers_memberships.id
        :return: db.invoices_items.id
        """
        from openstudio.os_customer_membership import CustomerMembership
        from openstudio.os_school_membership import SchoolMembership

        db = current.db
        DATE_FORMAT = current.DATE_FORMAT

        next_sort_nr = self.get_item_next_sort_nr()

        cm = CustomerMembership(cmID)
        sm = SchoolMembership(cm.row.school_memberships_id)
        row = sm.get_tax_rates_on_date(period_start)

        if row:
            tax_rates_id = row.school_memberships_price.tax_rates_id
        else:
            tax_rates_id = None

        price = sm.get_price_on_date(cm.row.Startdate, False)
        description = cm.get_name() + ' ' + \
                      period_start.strftime(DATE_FORMAT) + ' - ' + \
                      period_end.strftime(DATE_FORMAT)

        iiID = db.invoices_items.insert(
            invoices_id=self.invoices_id,
            ProductName=current.T("Membership") + ' ' + unicode(cmID),
            Description=description,
            Quantity=1,
            Price=price,
            Sorting=next_sort_nr,
            tax_rates_id=tax_rates_id,
        )

        self.link_to_customer_membership(cmID)
        self.set_amounts()

        self.on_update()

        return iiID
Ejemplo n.º 3
0
def membership_buy_now():
    """
        Get a membership
    """
    from openstudio.os_customer_membership import CustomerMembership
    from openstudio.os_school_membership import SchoolMembership

    smID = request.vars['smID']

    # init mollie
    mollie = Mollie.API.Client()
    mollie_api_key = get_sys_property('mollie_website_profile')
    mollie.setApiKey(mollie_api_key)

    # check if we have a mollie customer id
    create_mollie_customer(auth.user.id, mollie)

    # add membership to customer
    cmID = db.customers_memberships.insert(
        auth_customer_id = auth.user.id,
        school_memberships_id = smID,
        Startdate = TODAY_LOCAL,
        payment_methods_id = 100, # important, 100 is the payment_methods_id for Mollie
    )

    cm = CustomerMembership(cmID)
    cm.set_date_id_and_barcode()

    # clear cache to make sure it shows in the back end
    cache_clear_customers_memberships(auth.user.id)

    # Create invoice
    sm = SchoolMembership(smID)
    iID = sm.sell_to_customer_create_invoice(cmID)

    # Pay invoice ... SHOW ME THE MONEY!! :)
    redirect(URL('invoice_pay', vars={'iID':iID}))
Ejemplo n.º 4
0
    def item_add_membership(self, cmID):
        """
        :param cmID: db.customers_memberships.id
        :return: db.invoices_items.id
        """
        from openstudio.os_customer_membership import CustomerMembership
        from openstudio.os_school_membership import SchoolMembership

        db = current.db
        DATE_FORMAT = current.DATE_FORMAT

        next_sort_nr = self.get_item_next_sort_nr()

        cm = CustomerMembership(cmID)
        sm = SchoolMembership(cm.row.school_memberships_id)

        price = sm.row.Price
        tax_rates_id = sm.row.tax_rates_id

        if price == 0:
            return # Don't do anything if the price is 0

        description = cm.get_name() + ' ' + \
                      cm.row.Startdate.strftime(DATE_FORMAT) + ' - ' + \
                      cm.row.Enddate.strftime(DATE_FORMAT)

        iiID = db.invoices_items.insert(
            invoices_id = self.invoices_id,
            ProductName = current.T("Membership") + ' ' + unicode(cmID),
            Description = description,
            Quantity = 1,
            Price = price,
            Sorting = next_sort_nr,
            tax_rates_id = tax_rates_id,
            accounting_glaccounts_id = sm.row.accounting_glaccounts_id,
            accounting_costcenters_id = sm.row.accounting_costcenters_id
        )

        self.link_item_to_customer_membership(cmID, iiID)
        # This calls self.on_update()
        self.set_amounts()

        return iiID
Ejemplo n.º 5
0
    def get_memberships_formatted(self,
                                  per_row=3,
                                  public_only=True,
                                  link_type='shop'):
        """
            :param public: boolean, defines whether to show only public or all memberships
            :return: list of school_memberships formatted for shop
        """
        from openstudio.tools import OsTools
        from openstudio.os_school_membership import SchoolMembership

        os_gui = current.globalenv['os_gui']
        T = current.T
        os_tools = OsTools()

        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_memberships(public_only=public_only)

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

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

            sm = SchoolMembership(row.id)
            name = max_string_length(row.Name, 33)

            validity = os_tools.format_validity(row.Validity, row.ValidityUnit)

            membership_content = TABLE(
                TR(TD(T('Validity')), TD(validity)),
                TR(TD(T('Price')),
                   TD(sm.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_memberships_formatted_button_to_cart(
                    row.id)

            membership = DIV(os_gui.get_box_table(
                name,
                membership_content,
                panel_class,
                show_footer=True,
                footer_content=footer_content),
                             _class=card_class)

            display_row.append(membership)

            row_item += 1

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

        return memberships
Ejemplo n.º 6
0
    def get_memberships_formatted(self,
                                  per_row=3,
                                  public_only=True,
                                  link_type='shop'):
        """
            :param public: boolean, defines whether to show only public or all memberships
            :return: list of school_memberships formatted for shop
        """
        from openstudio.tools import OsTools
        from openstudio.os_school_membership import SchoolMembership

        os_gui = current.globalenv['os_gui']
        T = current.T
        os_tools = OsTools()
        TODAY_LOCAL = current.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_memberships(public_only=public_only)

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

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

            sm = SchoolMembership(row.id)
            name = max_string_length(row.Name, 33)

            validity = os_tools.format_validity(row.Validity, row.ValidityUnit)

            membership = DIV(DIV(
                DIV(
                    self._get_formatted_display_widget_header(
                        name, repr_row.Price)),
                DIV(DIV(repr_row.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-6 border-right"),
                        DIV(DIV(H5(
                            self._get_memberships_formatted_button_to_cart(
                                row.id),
                            _class="description-header"),
                                SPAN(T(""), _class="description-text"),
                                _class="description-block"),
                            _class="col-sm-6"),
                        _class="row"),
                    _class="box-footer",
                ),
                _class="box box-widget widget-user"),
                             _class=card_class)

            display_row.append(membership)

            row_item += 1

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

        return memberships