Esempio n. 1
0
def divisions():
    """
    List divisions
    """
    def get_button_set_default(division_id):
        if division_id == selected_division:
            return DIV(os_gui.get_label(
                'success',
                T('Selected'),
            ),
                       _class='pull-right')

        else:
            return os_gui.get_button('noicon',
                                     URL('division_set_default',
                                         vars={'division_id': division_id}),
                                     _class='pull-right',
                                     btn_class='btn-link',
                                     title=T("Select this division"))

    from ConfigParser import NoOptionError
    from openstudio.os_exact_online import OSExactOnline
    from openstudio.os_gui import OsGui

    response.title = T("Exact online")
    response.subtitle = T("Divisions")
    response.view = 'general/only_content.html'

    os_gui = OsGui()
    os_eo = OSExactOnline()
    api = os_eo.get_api()
    storage = os_eo.get_storage()
    try:
        selected_division = int(storage.get('transient', 'division'))
    except NoOptionError:
        selected_division = None

    division_choices, current_division = api.get_divisions()

    header = THEAD(TR(TH('Name'), TH('Exact ID'), TH()))

    table = TABLE(header, _class="table table-striped table-hover")

    for division_id in division_choices:
        tr = TR(
            TD(division_choices[division_id]),
            TD(division_id),
            TD(get_button_set_default(division_id))  # buttons
        )

        table.append(tr)

    content = table

    back = os_gui.get_button('back', URL('settings_integration',
                                         'exact_online'))

    return dict(content=content, back=back)
Esempio n. 2
0
def financial_glaccounts():
    """
    List G/L accounts
    """
    from ConfigParser import NoOptionError
    from openstudio.os_exact_online import OSExactOnline

    from exactonline.exceptions import ObjectDoesNotExist
    from exactonline.resource import GET, POST, PUT, DELETE

    from openstudio.os_gui import OsGui

    response.title = T("Exact online")
    response.subtitle = T("G/L Accounts")
    response.view = 'general/only_content.html'

    os_gui = OsGui()
    os_eo = OSExactOnline()
    api = os_eo.get_api()
    storage = os_eo.get_storage()
    try:
        selected_division = int(storage.get('transient', 'division'))
    except NoOptionError:
        selected_division = None

    items = api.financialglaccounts.all()
    sorted_items = sorted(items, key=lambda k: k['Code'])

    header = THEAD(
        TR(
            TH('G/L Account code'),
            TH('G/L Account Description'),
            TH('G/L Account ID'),
        ))

    table = TABLE(header, _class="table table-striped table-hover")

    for item in sorted_items:
        tr = TR(TD(item['Code']), TD(item['Description']), TD(item['ID']))

        table.append(tr)

    content = table

    back = os_gui.get_button('back', URL('settings_integration',
                                         'exact_online'))

    return dict(content=content, back=back)
Esempio n. 3
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)