Beispiel #1
0
def staff_holiday_edit():
    """
        This function shows an edit page for a teacher holiday
    """
    response.view = 'general/only_content.html'
    response.title = T("Edit holiday")
    response.subtitle = ''

    sthID = request.vars['sthID']

    return_url = URL('staff_holidays')

    crud.messages.submit_button = T("Save")
    crud.messages.record_updated = T("Saved")
    crud.settings.update_onaccept = [cache_clear_classschedule]
    crud.settings.update_deletable = False
    crud.settings.update_next = return_url
    form = crud.update(db.teachers_holidays, sthID)

    result = set_form_id_and_get_submit_button(form, 'MainForm')
    form = result['form']
    submit = result['submit']

    back = os_gui.get_button("back", return_url)

    return dict(content=form, back=back, save=submit)
def edit():
    """
        Shows edit page for a tag
        request.vars['stID'] is expected to be schedule_tags.id
    """
    stID = request.vars['stID']
    response.title = T("Schedule")
    response.subtitle = T("Edit tag")
    response.view = 'general/only_content.html'

    return_url = URL('index')

    crud.messages.submit_button = T("Save")
    crud.messages.record_updated = T("Saved")
    crud.settings.update_next = return_url
    crud.settings.update_deletable = False
    crud.settings.formstyle = "divs"
    form = crud.update(db.schedule_tags, stID)

    result = set_form_id_and_get_submit_button(form, 'MainForm')
    form = result['form']
    submit = result['submit']

    back = os_gui.get_button('back', return_url)

    return dict(content=form, back=back, save=submit)
Beispiel #3
0
def my_expenses_expense_add():
    """
    Page to add a expense
    """
    from openstudio.os_forms import OsForms

    response.title = T('My Expenses')
    response.subtitle = T('Add new expense')
    response.view = 'ep/only_content.html'

    if auth.user.teacher == False and auth.user.employee == False:
        redirect(URL('ep', 'index'))

    return_url = URL('my_expenses')
    db.employee_claims.auth_user_id.default = auth.user.id
    db.employee_claims.Status.default = 'pending'

    form = SQLFORM(db.employee_claims,
                   submit_button=T('Save'),
                   formstyle='divs')

    if form.process().accepted:
        # response.flash = 'form accepted'
        redirect(return_url)

    result = set_form_id_and_get_submit_button(form, 'MainForm')
    form = result['form']
    submit = result['submit']

    back = os_gui.get_button('back', return_url)

    content = form

    return dict(content=content, save=submit, back=back)
Beispiel #4
0
def edit():
    """
        Shows edit page for an announcement
        request.vars['aID'] is expected to be announcements.id
    """
    aID = request.vars['aID']
    response.title = T("Pinboard")
    response.subtitle = T("Edit announcement")
    response.view = 'general/only_content.html'

    return_url = URL('index')

    crud.messages.submit_button = T("Save")
    crud.messages.record_updated = T("Saved")
    crud.settings.update_next = return_url
    crud.settings.update_deletable = False
    form = crud.update(db.announcements, aID)

    result = set_form_id_and_get_submit_button(form, 'MainForm')
    form = result['form']
    submit = result['submit']

    back = os_gui.get_button('back', return_url)

    return dict(content=form, back=back, save=submit)
Beispiel #5
0
def my_expenses_expense_edit():
    """
    Page to Edit Expense
    :return:
    """
    from openstudio.os_forms import OsForms
    response.title = T('My Expenses')
    response.subtitle = T('Edit expense')
    response.view = 'ep/only_content.html'

    return_url = URL('my_expenses')
    ecID = request.vars['ecID']

    ec = db.employee_claims(ecID)
    if not ec.auth_user_id == auth.user.id:
        session.flash = T("Unable to edit this expense")
        redirect(return_url)

    db.employee_claims.id.readable = False
    form = SQLFORM(db.employee_claims,
                   ecID,
                   submit_button=T('Save'),
                   formstyle='divs')

    if form.process().accepted:
        redirect(return_url)

    result = set_form_id_and_get_submit_button(form, 'MainForm')

    form = result['form']
    back = os_gui.get_button('back', return_url)

    content = form

    return dict(content=content, save=result['submit'], back=back)
Beispiel #6
0
def holiday_edit():
    """
        This function shows an edit page for a holiday
        request.args[0] is expected to be the holidayID (hoID)
    """
    shID = request.vars['shID']
    response.title = T("Edit holiday")
    response.subtitle = T('')
    response.view = 'general/tabs_menu.html'

    db.school_holidays.Classes.readable = False
    db.school_holidays.Classes.writable = False

    db.school_holidays.Classes.default = True

    return_url = URL('holidays')

    crud.messages.submit_button = T("Save")
    crud.messages.record_updated = T("Updated holiday")
    crud.settings.update_onaccept = [
        cache_clear_classschedule, holiday_edit_onacept
    ]
    crud.settings.update_next = return_url
    crud.settings.update_deletable = False
    crud.settings.formstyle = 'bootstrap3_stacked'
    form = crud.update(db.school_holidays, shID)

    result = set_form_id_and_get_submit_button(form, 'MainForm')
    form = result['form']
    submit = result['submit']

    back = os_gui.get_button('back', return_url)
    menu = holiday_edit_get_menu(request.function, shID)

    return dict(content=form, back=back, menu=menu, save=submit)
Beispiel #7
0
def holiday_add():
    """
        This function shows an add page for a holiday
    """
    response.title = T("New holiday")
    response.subtitle = T('')
    response.view = 'general/tabs_menu.html'

    db.school_holidays.Classes.readable = False
    db.school_holidays.Classes.writable = False
    db.school_holidays.Classes.default = True

    return_url = URL('holidays')

    crud.messages.submit_button = T("Next")
    crud.messages.record_created = T("Added holiday")
    crud.settings.create_onaccept = [cache_clear_classschedule]
    crud.settings.create_next = '/schedule/holiday_edit_locations?shID=[id]'
    crud.settings.formstyle = 'bootstrap3_stacked'
    form = crud.create(db.school_holidays)

    result = set_form_id_and_get_submit_button(form, 'MainForm')
    form = result['form']
    submit = result['submit']

    back = os_gui.get_button('back', return_url)
    menu = holiday_add_get_menu(request.function)

    return dict(content=form, back=back, menu=menu, save=submit)
Beispiel #8
0
def get_form_subtitle(month=None, year=None, function=None, _class='col-md-4'):
    months = get_months_list()
    subtitle = ''
    if year and month:
        for m in months:
            if m[0] == month:
                month_title = m[1]
        subtitle = month_title + " " + str(year)
    else:
        year = TODAY_LOCAL.year
        month = TODAY_LOCAL.month

    form = SQLFORM.factory(Field('month',
                                 requires=IS_IN_SET(months, zero=None),
                                 default=month,
                                 label=T("")),
                           Field('year', 'integer', default=year, label=T("")),
                           submit_button=T("Run report"))
    form.attributes['_name'] = 'form_select_date'
    form.attributes['_class'] = 'overview_form_select_date'

    input_month = form.element('select[name=month]')
    # input_month.attributes['_onchange'] = "this.form.submit();"

    input_year = form.element('input[name=year]')
    # input_year.attributes['_onchange'] = "this.form.submit();"
    input_year.attributes['_type'] = 'number'
    # input_year.attributes['_class']    = 'input_margins'

    form.element('input[name=year]')

    result = set_form_id_and_get_submit_button(form, 'MainForm')
    form = result['form']
    submit = result['submit']

    ## Show current
    url_current_month = URL('my_classes_show_current')
    show_current_month = A(T("Current month"),
                           _href=url_current_month,
                           _class='btn btn-default')
    month_chooser = ''
    if not function == 'attendance_classes':
        month_chooser = overview_get_month_chooser(function)

    form = DIV(XML(
        '<form id="MainForm" action="#" enctype="multipart/form-data" method="post">'
    ),
               DIV(form.custom.widget.month,
                   form.custom.widget.year,
                   _class=_class),
               form.custom.end,
               _class='row')

    return dict(form=form,
                subtitle=subtitle,
                month_chooser=month_chooser,
                current_month=show_current_month,
                submit=submit)
Beispiel #9
0
def renew_in_month():
    """

    :return:
    """
    response.title = T("Automation")
    response.subtitle = T(
        "Customer memberships - renew expiring memberships in month")
    response.view = 'general/only_content.html'

    months = get_months_list()

    form = SQLFORM.factory(Field('month',
                                 requires=IS_IN_SET(months, zero=None),
                                 default=TODAY_LOCAL.month,
                                 label=T("Month")),
                           Field('year',
                                 'integer',
                                 default=TODAY_LOCAL.year,
                                 requires=IS_INT_IN_RANGE(2010, 2999),
                                 label=T("Year")),
                           formstyle="bootstrap3_stacked",
                           submit_button=T("Renew memberships"))

    result = set_form_id_and_get_submit_button(form, 'MainForm')
    form = result['form']
    submit = result['submit']

    if 'year' in request.vars and 'month' in request.vars:
        year = request.vars['year']
        month = request.vars['month']
        description = request.vars['description'] or ''

        scheduler.queue_task(
            'customers_membership_renew_expired',
            pvars={
                'year': year,
                'month': month
            },
            stop_time=datetime.datetime.now() + datetime.timedelta(hours=1),
            last_run_time=datetime.datetime(1963, 8, 28, 14, 30),
            timeout=1800,  # run for max. half an hour.
        )

        session.flash = SPAN(
            T("Started renewing customer memberships... "),
            T("please refresh this page in a few minutes."), BR(),
            T("Please note that you can continue to work on other things in the meantime and you don't have to wait on this page."
              ))
        redirect(URL('index'))

    back = os_gui.get_button('back', URL('index'))

    return dict(
        save=submit,
        content=form,
        back=back,
    )
def staff_holidays_choose_status():
    """
        Page to choose status for all classes in period
    """
    response.view = 'general/only_content.html'
    response.title = T("Staff holiday")
    response.subtitle = T('Choose class & shift status')

    sthID = request.vars['sthID']

    statuses = [['normal', T('Normal')], ['cancelled',
                                          T('Cancelled')], ['open',
                                                            T('Open')]]

    form = SQLFORM.factory(
        Field(
            'status',
            requires=IS_IN_SET(statuses, zero=T("Please select...")),
            label=T("Change status of shifts and classes during holiday to")),
        # Field('apply_teacher2', 'boolean',
        #     label=T("Also when teacher2")),
        submit_button=T("Set status"),
        formstyle='divs')

    if form.process().accepted:
        staff_holidays_set_status(sthID, form.vars.status,
                                  form.vars.apply_teacher2)
        redirect(URL('staff_holidays'))

    result = set_form_id_and_get_submit_button(form, 'MainForm')
    form = result['form']
    submit = result['submit']

    query = (db.teachers_holidays.id == sthID)
    left = [
        db.auth_user.on(
            db.teachers_holidays.auth_teacher_id == db.auth_user.id)
    ]
    rows = db(query).select(db.teachers_holidays.ALL,
                            db.auth_user.display_name,
                            left=left)
    row = rows.first()

    title = H2(row.auth_user.display_name)
    description = DIV(row.teachers_holidays.Startdate.strftime(DATE_FORMAT),
                      ' - ',
                      row.teachers_holidays.Enddate.strftime(DATE_FORMAT),
                      BR(), row.teachers_holidays.Note)
    content = DIV(title, description, BR(), BR(),
                  DIV(form, _class='col-md-6 no_padding-left'))

    back = os_gui.get_button('back', URL('staff_holidays'))

    return dict(content=content, back=back, save=submit)
Beispiel #11
0
def index():
    """
        Page to set mailchimp API key
    """
    from general_helpers import set_form_id_and_get_submit_button

    response.title = T("Settings")
    response.subtitle = T("Point of Sale")
    response.view = 'general/tabs_menu.html'

    pos_barcodes_checkin = get_sys_property('pos_customers_barcodes')

    form = SQLFORM.factory(Field(
        'pos_customers_barcodes',
        requires=IS_IN_SET([
            ['customer_id', T("Customer ID")],
            ['membership_id', T("Customer membership ID")],
        ],
                           zero=None),
        default=pos_barcodes_checkin,
        label=T('Checkin barcodes'),
        comment=
        T("Does the barcode scanner read customer ids or customer membership ids when checking in customers?"
          )),
                           submit_button=T("Save"),
                           formstyle='bootstrap3_stacked',
                           separator=' ')

    result = set_form_id_and_get_submit_button(form, 'MainForm')
    form = result['form']
    submit = result['submit']

    if form.accepts(request.vars, session):
        pos_barcodes_checkin = request.vars['pos_customers_barcodes']
        set_sys_property('pos_customers_barcodes', pos_barcodes_checkin)

        # User feedback
        session.flash = T('Saved')
        # reload so the user sees how the values are stored in the db now
        redirect(URL('index'))

    menu = pos_get_menu(request.function)

    return dict(content=form, menu=menu, save=submit)
Beispiel #12
0
def add():
    """
        This function shows an add page for an announcement
    """
    response.title = T("Pinboard")
    response.subtitle = T("New announcement")
    response.view = 'general/only_content.html'

    return_url = URL('index')

    crud.messages.submit_button = T("Save")
    crud.messages.record_created = T("Added announcement")
    crud.settings.create_next = return_url
    form = crud.create(db.announcements)

    result = set_form_id_and_get_submit_button(form, 'MainForm')
    form = result['form']
    submit = result['submit']

    back = os_gui.get_button('back', return_url)

    return dict(content=form, back=back, save=submit)
Beispiel #13
0
def staff_holiday_add():
    """
        This function shows an add page for a teacher holiday
    """
    response.view = 'general/only_content.html'
    response.title = T("Add holiday")
    response.subtitle = ''

    return_url = URL('staff_holidays')

    crud.messages.submit_button = T("Next")
    crud.messages.record_created = T("Saved")
    crud.settings.create_next = return_url
    crud.settings.create_onaccept = [cache_clear_classschedule]
    form = crud.create(db.teachers_holidays)

    result = set_form_id_and_get_submit_button(form, 'MainForm')
    form = result['form']
    submit = result['submit']

    back = os_gui.get_button("back", return_url)

    return dict(content=form, back=back, save=submit)
Beispiel #14
0
def edit():
    """
        This function shows an edit page for a task
        request.vars['tID'] is expected to be tasks.id
    """
    # call js for styling the form
    response.js = 'set_form_classes();'

    tID = request.vars['tID']

    permission = auth.has_membership(group_id='Admins') or \
                 auth.has_permission('assign', 'tasks')
    if not permission:
        db.tasks.auth_user_id.writable = False

    return_url = URL('add_edit_redirect', vars=request.vars, extension='')

    crud.messages.submit_button = T("Save")
    crud.messages.record_updated = T("Saved task")
    crud.settings.update_next = return_url
    crud.settings.update_deletable = False
    form = crud.update(db.tasks, tID)

    result = set_form_id_and_get_submit_button(form, 'task_edit')
    form = result['form']
    submit = result['submit']

    cancel = os_gui.get_button('noicon',
                               return_url,
                               title=T('Cancel'),
                               btn_size='')
    table = form.element('table')
    table.append(TR(TD(), TD(cancel, DIV(submit, _class='pull-right'))))

    title = H4(T('Edit task'))

    return dict(content=DIV(title, form))
Beispiel #15
0
def index_get_form(date_from, date_until):
    """
    Get month chooser form for index
    """
    from general_helpers import get_months_list
    from general_helpers import set_form_id_and_get_submit_button

    months = get_months_list()

    form = SQLFORM.factory(
        Field('date_from', 'date', required=True,
            default=date_from,
            requires=IS_DATE_IN_RANGE(format=DATE_FORMAT,
                                      minimum=datetime.date(1900,1,1),
                                      maximum=datetime.date(2999,1,1)),
            represent=represent_date,
            label=T("From date"),
            widget=os_datepicker_widget),
        Field('date_until', 'date', required=True,
            default=date_until,
            requires=IS_DATE_IN_RANGE(format=DATE_FORMAT,
                                      minimum=datetime.date(1900,1,1),
                                      maximum=datetime.date(2999,1,1)),
            represent=represent_date,
            label=T("Until date"),
            widget=os_datepicker_widget),
        # Field('school_locations_id', db.school_locations,
        #       requires=IS_IN_DB(db(loc_query),
        #                         'school_locations.id',
        #                         '%(Name)s',
        #                         zero=T("All locations")),
        #       default=session.reports_tax_summary_index_school_locations_id,
        #       represent=lambda value, row: locations_dict.get(value, T("No location")),
        #       label=T("Location")),
        formstyle='bootstrap3_stacked',
        submit_button=T("Run report")
    )

    result = set_form_id_and_get_submit_button(form, 'MainForm')
    form = result['form']
    submit = result['submit']

    form_display = DIV(
        XML('<form id="MainForm" action="#" enctype="multipart/form-data" method="post">'),
        DIV(LABEL(form.custom.label.date_from),
            form.custom.widget.date_from,
            _class='col-md-6'
        ),
        DIV(LABEL(form.custom.label.date_until),
            form.custom.widget.date_until,
            _class='col-md-6'
        ),
        form.custom.end,
        _class='row'
    )

    return dict(
        form=result['form'],
        submit=result['submit'],
        form_display=form_display
    )
Beispiel #16
0
def edit():
    """
        :return: shows order
    """
    response.title = T('Order #') + request.vars['coID']
    response.subtitle = T('Edit')
    response.view = 'general/only_content.html'

    coID = request.vars['coID']

    order = Order(coID)
    cuID = order.order.auth_customer_id
    customer = Customer(cuID)
    # Info table
    info = TABLE(THEAD(
        TR(
            TH(T('Customer')),
            TH(T('Ordered on')),
            TH(T('Status')),
        )),
                 _class='table')

    # Display status
    for field in db.customers_orders:
        field.readable = False
        field.writable = False

    db.customers_orders.Status.readable = True
    db.customers_orders.Status.writable = True

    crud.messages.record_updated = T('Saved')
    form = crud.update(db.customers_orders, coID)

    result = set_form_id_and_get_submit_button(form, 'MainForm')
    form = result['form']
    submit = result['submit']

    form = DIV(
        XML('<form id="MainForm" action="#" enctype="multipart/form-data" method="post">'
            ), form.custom.widget.Status, form.custom.end)

    #status = form

    # status = represent_customers_orders_status(order.order.Status, order.order)
    # Display ordered on
    ordered_on = represent_datetime(order.order.DateCreated, order.order)
    customer_link = A(customer.get_name(),
                      _href=URL('customers', 'edit', args=customer.row.id))
    info.append(TR(TD(customer_link), TD(ordered_on), TD(form)))

    # Info content
    content = DIV(DIV(info, _class='col-md-8 no-padding-left'))

    # Display items
    rows = order.get_order_items_rows()

    header = THEAD(
        TR(
            TH(T('Product')),
            TH(T('Description')),
            TH(SPAN(T('Amount incl. VAT'), _class='right')),
            TH(T("G/L Account")),
            TH(T("Cost center")),
            TH(),
        ))
    table = TABLE(header, _class='table table-striped table-hover order-items')

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

        table.append(
            TR(
                TD(repr_row.customers_orders_items.ProductName),
                TD(repr_row.customers_orders_items.Description),
                TD(
                    SPAN(repr_row.customers_orders_items.TotalPriceVAT,
                         _class='right')),
                TD(repr_row.customers_orders_items.accounting_glaccounts_id),
                TD(repr_row.customers_orders_items.accounting_costcenters_id),
                TD(),
            ))

    # Display totals
    amounts = order.get_amounts()

    footer = TFOOT(
        TR(
            TD(), TD(B(T('Subtotal'))),
            TD(
                SPAN(CURRSYM,
                     ' ',
                     format(amounts.TotalPrice, '.2f'),
                     _class='bold right')), TD()),
        TR(
            TD(), TD(B(T('VAT'))),
            TD(
                SPAN(CURRSYM,
                     ' ',
                     format(amounts.VAT, '.2f'),
                     _class='bold right')), TD()),
        TR(
            TD(), TD(B(T('Total'))),
            TD(
                SPAN(CURRSYM,
                     ' ',
                     format(amounts.TotalPriceVAT, '.2f'),
                     _class='bold right')), TD()))
    table.append(footer)

    content.append(table)

    # Customer message
    customer_message = ''
    if order.order.CustomerNote:
        customer_message = DIV(
            B(T('Customer message')),
            BR(),
            BR(),
            XML(order.order.CustomerNote.replace("\n", "<br>")),
        )
    content.append(customer_message)

    back = os_gui.get_button('back', edit_get_return_url(cuID))

    return dict(content=content, back=back, save=submit)
Beispiel #17
0
def workflow():
    """
        Settings to control shop workflows
    """
    response.title = T('Shop')
    response.subtitle = T('Workflow')
    response.view = 'general/only_content.html'

    shop_requires_complete_profile = get_sys_property('shop_requires_complete_profile')
    shop_classes_advance_booking_limit = get_sys_property('shop_classes_advance_booking_limit')
    shop_classes_cancellation_limit = get_sys_property('shop_classes_cancellation_limit')
    shop_subscriptions_start = get_sys_property('shop_subscriptions_start')

    form = SQLFORM.factory(
        Field('shop_requires_complete_profile', 'boolean',
              default=shop_requires_complete_profile,
              label=T('Orders require complete profiles'),
              comment=T('Require complete profiles before customers can place an order')),
        Field('shop_classes_advance_booking_limit', 'integer',
              default=shop_classes_advance_booking_limit,
              requires=IS_INT_IN_RANGE(0, 1099),
              label=T('Classes advance booking limit in days'),
              comment=T("Number of days in advance customers will be able to book classes")),
        Field('shop_classes_cancellation_limit', 'integer',
              default=shop_classes_cancellation_limit,
              requires=IS_INT_IN_RANGE(0, 745),
              label=T('Classes cancellation limit in hours'),
              comment=T("Number of hours before a class starts a booking can be cancelled while returning credit")),
        Field('shop_subscriptions_start',
              default=shop_subscriptions_start,
              requires=IS_IN_SET([
                  ['today', T('Today')],
                  ['next_month', T('First day of next month')]],
                  zero=None),
              label=T('Subscriptions start date'),
              comment=T("Set the default start date for subscriptions in the shop")),
        submit_button=T("Save"),
        separator=' ',
        formstyle='bootstrap3_stacked'
    )

    result = set_form_id_and_get_submit_button(form, 'MainForm')
    form = result['form']
    submit = result['submit']

    if form.process().accepted:
        # check shop require complete profiles
        shop_requires_complete_profile = request.vars['shop_requires_complete_profile']
        row = db.sys_properties(Property='shop_requires_complete_profile')
        if not row:
            db.sys_properties.insert(Property='shop_requires_complete_profile',
                                     PropertyValue=shop_requires_complete_profile)
        else:
            row.PropertyValue = shop_requires_complete_profile
            row.update_record()

        # check shop_classes_advance_booking_limit
        shop_classes_advance_booking_limit = request.vars['shop_classes_advance_booking_limit']
        row = db.sys_properties(Property='shop_classes_advance_booking_limit')
        if not row:
            db.sys_properties.insert(Property='shop_classes_advance_booking_limit',
                                     PropertyValue=shop_classes_advance_booking_limit)
        else:
            row.PropertyValue = shop_classes_advance_booking_limit
            row.update_record()

        # check shop_classes_cancellation_limit
        shop_classes_cancellation_limit = request.vars['shop_classes_cancellation_limit']
        row = db.sys_properties(Property='shop_classes_cancellation_limit')
        if not row:
            db.sys_properties.insert(Property='shop_classes_cancellation_limit',
                                     PropertyValue=shop_classes_cancellation_limit)
        else:
            row.PropertyValue = shop_classes_cancellation_limit
            row.update_record()

        # check shop_subscriptions_start
        shop_subscriptions_start = request.vars['shop_subscriptions_start']
        row = db.sys_properties(Property='shop_subscriptions_start')
        if not row:
            db.sys_properties.insert(Property='shop_subscriptions_start',
                                     PropertyValue=shop_subscriptions_start)
        else:
            row.PropertyValue = shop_subscriptions_start
            row.update_record()

        # Clear cache
        cache_clear_sys_properties()
        cache_clear_classschedule()
        # User feedback
        session.flash = T('Saved')
        # reload so the user sees how the values are stored in the db now
        redirect(URL('workflow'))

    content = DIV(DIV(form, _class='col-md-6'),
                  _class='row')

    return dict(content=content,
                back='',
                menu='',
                save=submit)
Beispiel #18
0
def extend_validity():
    """

    :return:
    """
    response.title = T("Automation")
    response.subtitle = T("Customer memberships - bulk extend validity")
    response.view = 'general/only_content.html'

    months = get_months_list()

    form = SQLFORM.factory(
        Field('valid_on',
              'date',
              requires=IS_DATE_IN_RANGE(format=DATE_FORMAT,
                                        minimum=datetime.date(1900, 1, 1),
                                        maximum=datetime.date(2999, 1, 1)),
              default=TODAY_LOCAL,
              widget=os_datepicker_widget,
              label=T("For cards valid on")),
        Field(
            'days_to_add',
            'integer',
            default=1,
            requires=IS_INT_IN_RANGE(1, 5000),
            label=T(
                "Extend the validity with the following number of days to add")
        ),
        formstyle="bootstrap3_stacked",
        submit_button=T("Extend validity"))

    result = set_form_id_and_get_submit_button(form, 'MainForm')
    form = result['form']
    submit = result['submit']

    if 'valid_on' in request.vars and 'days_to_add' in request.vars:
        valid_on = request.vars['valid_on']
        days_to_add = request.vars['days_to_add']

        scheduler.queue_task(
            'customers_memberships_extend_validity',
            pvars={
                'valid_on': valid_on,
                'days_to_add': days_to_add
            },
            stop_time=datetime.datetime.now() + datetime.timedelta(hours=1),
            last_run_time=datetime.datetime(1963, 8, 28, 14, 30),
            timeout=1800,  # run for max. half an hour.
        )

        session.flash = SPAN(
            T("Started extending selected memberships... "),
            T("please refresh this page in a few minutes."), BR(),
            T("Please note that you can continue to work on other things in the meantime and you don't have to wait on this page."
              ))
        redirect(URL('index'))

    back = os_gui.get_button('back', URL('index'))

    return dict(
        save=submit,
        content=form,
        back=back,
    )
Beispiel #19
0
def workflow():
    """
        Settings to control shop workflows
    """
    response.title = T('Shop')
    response.subtitle = T('Workflow')
    response.view = 'general/only_content.html'

    shop_requires_complete_profile_classes = get_sys_property(
        'shop_requires_complete_profile_classes')
    shop_requires_complete_profile_memberships = get_sys_property(
        'shop_requires_complete_profile_memberships')
    shop_requires_complete_profile_classcards = get_sys_property(
        'shop_requires_complete_profile_classcards')
    shop_requires_complete_profile_events = get_sys_property(
        'shop_requires_complete_profile_events')
    shop_requires_complete_profile_subscriptions = get_sys_property(
        'shop_requires_complete_profile_subscriptions')
    shop_classes_advance_booking_limit = get_sys_property(
        'shop_classes_advance_booking_limit')
    shop_classes_cancellation_limit = get_sys_property(
        'shop_classes_cancellation_limit')
    shop_subscriptions_start = get_sys_property('shop_subscriptions_start')

    shop_subscriptions_payment_method = get_sys_property(
        'shop_subscriptions_payment_method')

    form = SQLFORM.factory(
        Field('shop_requires_complete_profile_classes',
              'boolean',
              default=shop_requires_complete_profile_classes,
              label=T('Booking classes require complete profiles'),
              comment=T(
                  'Require complete profiles before customers can book a class'
              )),
        Field(
            'shop_requires_complete_profile_memberships',
            'boolean',
            default=shop_requires_complete_profile_memberships,
            label=T('Memberships require complete profiles'),
            comment=
            T('Require complete profiles before customers can get a membership'
              )),
        Field(
            'shop_requires_complete_profile_classcards',
            'boolean',
            default=shop_requires_complete_profile_classcards,
            label=T('Classcards require complete profiles'),
            comment=T(
                'Require complete profiles before customers can buy a classcard'
            )),
        Field(
            'shop_requires_complete_profile_events',
            'boolean',
            default=shop_requires_complete_profile_events,
            label=T('Events require complete profiles'),
            comment=T(
                'Require complete profiles before customers can book an event')
        ),
        Field(
            'shop_requires_complete_profile_subscriptions',
            'boolean',
            default=shop_requires_complete_profile_subscriptions,
            label=T('Subscriptions require complete profiles'),
            comment=
            T('Require complete profiles before customers can sign up for a subscription'
              )),
        Field(
            'shop_classes_advance_booking_limit',
            'integer',
            default=shop_classes_advance_booking_limit,
            requires=IS_INT_IN_RANGE(0, 1099),
            label=T('Classes advance booking limit in days'),
            comment=
            T("Number of days in advance customers will be able to book classes"
              )),
        Field(
            'shop_classes_cancellation_limit',
            'integer',
            default=shop_classes_cancellation_limit,
            requires=IS_INT_IN_RANGE(0, 745),
            label=T('Classes cancellation limit in hours'),
            comment=
            T("Number of hours before a class starts a booking can be cancelled while returning credit"
              )),
        Field('shop_subscriptions_start',
              default=shop_subscriptions_start,
              requires=IS_IN_SET(
                  [['today', T('Today')],
                   ['next_month', T('First day of next month')]],
                  zero=None),
              label=T('Subscriptions start date'),
              comment=T(
                  "Set the default start date for subscriptions in the shop")),
        Field(
            'shop_subscriptions_payment_method',
            default=shop_subscriptions_payment_method,
            requires=IS_IN_SET(
                [['directdebit', T('Direct Debit')], ['mollie',
                                                      T('Mollie')]],
                zero=None),
            label=T('Subscriptions Payment Method'),
            comment=T(
                "Set the default payment method for subscriptions in the shop")
        ),
        submit_button=T("Save"),
        separator=' ',
        formstyle='bootstrap3_stacked')

    result = set_form_id_and_get_submit_button(form, 'MainForm')
    form = result['form']
    submit = result['submit']

    if form.process().accepted:
        form_vars = [
            'shop_requires_complete_profile_classes',
            'shop_requires_complete_profile_memberships',
            'shop_requires_complete_profile_classcards',
            'shop_requires_complete_profile_events',
            'shop_requires_complete_profile_subscriptions',
            'shop_classes_advance_booking_limit',
            'shop_classes_cancellation_limit',
            'shop_subscriptions_start',
            'shop_subscriptions_payment_method',
        ]

        for fvar in form_vars:
            if fvar in request.vars:
                set_sys_property(fvar, request.vars[fvar])
            else:
                set_sys_property(fvar, None)

        # Clear cache
        cache_clear_sys_properties()
        cache_clear_classschedule()
        # User feedback
        session.flash = T('Saved')
        # reload so the user sees how the values are stored in the db now
        redirect(URL('workflow'))

    content = DIV(DIV(form, _class='col-md-6'), _class='row')

    return dict(content=content, back='', menu='', save=submit)
Beispiel #20
0
def create_invoices_for_month():
    """

    :return:
    """
    response.title = T("Automation")
    response.subtitle = T("Customer subscriptions - create invoices for month")
    response.view = 'general/only_content.html'

    months = get_months_list()
    invoice_date_options = [['today', T("Today")],
                            ['first_of_month',
                             T("First day of chosen month")]]

    form = SQLFORM.factory(
        Field('month',
               requires=IS_IN_SET(months, zero=None),
               default=TODAY_LOCAL.month,
               label=T("Month")),
        Field('year', 'integer',
              default=TODAY_LOCAL.year,
              requires=IS_INT_IN_RANGE(2010, 2999),
              label=T("Year")),
        Field('description',
              label=T("Description"),
              comment=T(
                  "This will be the invoice description and shown on the customers' " + \
                  "bank statement in case you create a collection batch. " + \
                  "When an alt. price has been added for this month, this description will be used for that subscription.")),
        Field('invoice_date',
              default='today',
              requires=IS_IN_SET(invoice_date_options, zero=None),
              label=T("Invoice date"),
              comment=T("Choose the creation date shown on invoices.")),
        formstyle="bootstrap3_stacked",
        submit_button=T("Create invoices")
    )

    result = set_form_id_and_get_submit_button(form, 'MainForm')
    form = result['form']
    submit = result['submit']

    if 'year' in request.vars and 'month' in request.vars:
        year = request.vars['year']
        month = request.vars['month']
        description = request.vars['description'] or ''
        invoice_date = request.vars['invoice_date'] or 'today'

        scheduler.queue_task(
            'customers_subscriptions_create_invoices_for_month',
            pvars={
                'year': year,
                'month': month,
                'description': description,
                'invoice_date': invoice_date
            },
            stop_time=datetime.datetime.now() + datetime.timedelta(hours=1),
            last_run_time=datetime.datetime(1963, 8, 28, 14, 30),
            timeout=1800,  # run for max. half an hour.
        )

        session.flash = SPAN(
            T("Started creating customer subscription invoices... "),
            T("please refresh this page in a few minutes."), BR(),
            T("Please note that you can continue to work on other things in the meantime and you don't have to wait on this page."
              ))
        redirect(URL('index'))

    back = os_gui.get_button('back', URL('index'))

    return dict(
        save=submit,
        content=form,
        back=back,
    )
Beispiel #21
0
def add_subscription_credits_for_month():
    """
    Choose month for which to add subscription credits
    """
    response.title = T("Automation")
    response.subtitle = T("Customer subscriptions - add credits for month")
    response.view = 'general/only_content.html'

    months = get_months_list()

    form = SQLFORM.factory(Field('month',
                                 requires=IS_IN_SET(months, zero=None),
                                 default=TODAY_LOCAL.month,
                                 label=T("Month")),
                           Field('year',
                                 'integer',
                                 default=TODAY_LOCAL.year,
                                 requires=IS_INT_IN_RANGE(2010, 2999),
                                 label=T("Year")),
                           formstyle="bootstrap3_stacked",
                           submit_button=T("Add credits"))

    result = set_form_id_and_get_submit_button(form, 'MainForm')
    form = result['form']
    submit = result['submit']

    content = DIV(
        LABEL(T("Info")), BR(),
        P(
            T("This operation will only add credits for subscriptions where credits haven't been added yet for the selected month."
              )),
        P(
            T("Paused subscriptions and subscriptions where credits are already added for the selected month will be skipped."
              )), form)

    if 'year' in request.vars and 'month' in request.vars:
        year = request.vars['year']
        month = request.vars['month']
        description = request.vars['description'] or ''

        scheduler.queue_task(
            'customers_subscriptions_add_credits_for_month',
            pvars={
                'year': year,
                'month': month,
            },
            stop_time=datetime.datetime.now() + datetime.timedelta(hours=1),
            last_run_time=datetime.datetime(1963, 8, 28, 14, 30),
            timeout=1800,  # run for max. half an hour.
        )

        session.flash = SPAN(
            T("Started adding subscription credits.. "),
            T("please refresh this page in a few minutes."), BR(),
            T("Please note that you can continue to work on other things in the meantime and you don't have to wait on this page."
              ))
        redirect(URL('index'))

    back = os_gui.get_button('back', URL('index'))

    return dict(
        save=submit,
        content=content,
        back=back,
    )
Beispiel #22
0
def exact_online():
    """
        Page to set Mollie website profile
    """
    from general_helpers import set_form_id_and_get_submit_button
    from openstudio.os_exact_online import OSExactOnline
    from ConfigParser import NoOptionError

    response.title = T("Settings")
    response.subtitle = T("Integration")
    response.view = 'general/tabs_menu.html'


    os_eo = OSExactOnline()
    storage = os_eo.get_storage()

    try:
        server_auth_url = storage.get('server', 'auth_url')
    except NoOptionError:
        server_auth_url = None
    try:
        server_rest_url = storage.get('server', 'rest_url')
    except NoOptionError:
        server_rest_url = None
    try:
        server_token_url = storage.get('server', 'token_url')
    except NoOptionError:
        server_token_url = None

    try:
        client_base_url = storage.get('application', 'base_url')
    except NoOptionError:
        client_base_url = None
    try:
        client_id = storage.get('application', 'client_id')
    except NoOptionError:
        client_id = None
    try:
        client_secret = storage.get('application', 'client_secret')
    except NoOptionError:
        client_secret = None


    form = SQLFORM.factory(
        Field('auth_url',
              requires=IS_URL(),
              default=server_auth_url,
              label=T("Server auth URL")),
        Field('rest_url',
              requires=IS_URL(),
              default=server_rest_url,
              label=T('Server rest URL')),
        Field('token_url',
              requires=IS_URL(),
              default=server_token_url,
              label=T('Server token URL')),
        Field('base_url',
              requires=IS_URL(),
              default=client_base_url,
              label=T('Client base URL'),
              comment=T('The base URL this OpenStudio installation eg. "https://demo.openstudioproject.com"')),
        Field('client_id',
              requires=IS_NOT_EMPTY(),
              default=client_id,
              label=T('Client ID')),
        Field('client_secret',
              requires=IS_NOT_EMPTY(),
              default=client_secret,
              label=T('Client Secret')),
        submit_button=T("Save"),
        formstyle='bootstrap3_stacked',
        separator=' ')

    result = set_form_id_and_get_submit_button(form, 'MainForm')
    form = result['form']
    submit = DIV(result['submit'], _class='pull-right')

    if form.accepts(request.vars, session):
        #TODO: set using ini storage

        # check server vars
        server_vars = [
            'auth_url',
            'rest_url',
            'token_url'
        ]
        for var in server_vars:
            value = request.vars[var]
            storage.set('server', var, value)

        # # check application vars
        application_vars = [
            'base_url',
            'client_id',
            'client_secret'
        ]
        for var in application_vars:
            value = request.vars[var]
            storage.set('application', var, value)

        # User feedback
        session.flash = T('Saved')
        # reload so the user sees how the values are stored in the db now
        redirect(URL('exact_online'))

    menu = integration_get_menu(request.function)
    tools = exact_online_tools()

    return dict(content=form,
                menu=menu,
                tools=tools,
                save=submit)