示例#1
0
def bank_accounts_list_json():
    return jsonify(items=[{
        'name':
        bank_account.name,
        'bank':
        bank_account.bank,
        'ktonr':
        bank_account.account_number,
        'blz':
        bank_account.routing_number,
        'iban':
        bank_account.iban,
        'bic':
        bank_account.bic,
        'kto': {
            'href': url_for('.accounts_show',
                            account_id=bank_account.account_id),
            'title': 'Konto anzeigen',
            'btn_class': 'btn-primary'
        },
        'balance':
        money_filter(bank_account.account.balance),
        'last_imported_at':
        '{}'.format(
            map_or_default(bank_account.last_imported_at, datetime.date,
                           'nie'))
    } for bank_account in BankAccount.q.all()])
示例#2
0
def bank_accounts_errors_json():
    return jsonify(items=[{
        'name':
        error.bank_account.name,
        'fix': {
            'href': url_for('.fix_import_error', error_id=error.id),
            'title': 'korrigieren',
            'btn_class': 'btn-primary'
        },
        'imported_at':
        '{}'.format(map_or_default(error.imported_at, datetime.date, 'nie'))
    } for error in MT940Error.q.all()])
示例#3
0
文件: __init__.py 项目: agdsn/pycroft
def bank_accounts_import():
    form = BankAccountActivitiesImportForm()
    form.account.choices = [ (acc.id, acc.name) for acc in BankAccount.q.all()]
    (transactions, old_transactions) = ([], [])
    if form.validate_on_submit():
        # login with fints
        bank_account = BankAccount.q.get(form.account.data)
        process = True
        try:
            fints = FinTS3PinTanClient(
                bank_account.routing_number,
                form.user.data,
                form.pin.data,
                bank_account.fints_endpoint
            )

            acc = next((a for a in fints.get_sepa_accounts()
                        if a.iban == bank_account.iban), None)
            if acc is None:
                raise KeyError('BankAccount with IBAN {} not found.'.format(
                    bank_account.iban)
                )
            start_date = map_or_default(bank_account.last_updated_at,
                                        datetime.date, date(2018, 1, 1))
            statement = fints.get_statement(acc, start_date, date.today())
            flash(
                "Transaktionen vom {} bis {}.".format(start_date, date.today()))
        except FinTSDialogError:
            flash(u"Ungültige FinTS-Logindaten.", 'error')
            process = False
        except KeyError:
            flash(u'Das gewünschte Konto kann mit diesem Online-Banking-Zugang\
                    nicht erreicht werden.', 'error')
            process = False

        if process:
            (transactions, old_transactions) = finance.process_transactions(
                bank_account, statement)
        else:
            (transactions, old_transactions) = ([], [])

        if process and form.do_import.data is True:
            # save transactions to database
            session.add_all(transactions)
            session.commit()
            flash(u'Bankkontobewegungen wurden importiert.')
            return redirect(url_for(".accounts_show",
                                    account_id=bank_account.account_id))


    return render_template('finance/bank_accounts_import.html', form=form,
                           transactions=transactions,
                           old_transactions=old_transactions)
示例#4
0
文件: __init__.py 项目: agdsn/pycroft
def bank_accounts_errors_json():
    T = ImportErrorTable
    return jsonify(items=[{
        'name':
        error.bank_account.name,
        'fix':
        T.fix.value(href=url_for('.fix_import_error', error_id=error.id),
                    title='korrigieren',
                    btn_class='btn-primary'),
        'imported_at':
        '{}'.format(map_or_default(error.imported_at, datetime.date, 'nie'))
    } for error in MT940Error.q.all()])
示例#5
0
def bank_accounts_import():
    form = BankAccountActivitiesImportForm()
    form.account.choices = [(acc.id, acc.name) for acc in BankAccount.q.all()]
    (transactions, old_transactions) = ([], [])
    if form.validate_on_submit():
        # login with fints
        bank_account = BankAccount.q.get(form.account.data)
        process = True
        try:
            fints = FinTS3PinTanClient(bank_account.routing_number,
                                       form.user.data, form.pin.data,
                                       bank_account.fints_endpoint)

            acc = next((a for a in fints.get_sepa_accounts()
                        if a.iban == bank_account.iban), None)
            if acc is None:
                raise KeyError('BankAccount with IBAN {} not found.'.format(
                    bank_account.iban))
            start_date = map_or_default(bank_account.last_updated_at,
                                        datetime.date, date(2018, 1, 1))
            statement = fints.get_statement(acc, start_date, date.today())
            flash("Transaktionen vom {} bis {}.".format(
                start_date, date.today()))
        except FinTSDialogError:
            flash(u"Ungültige FinTS-Logindaten.", 'error')
            process = False
        except KeyError:
            flash(
                u'Das gewünschte Konto kann mit diesem Online-Banking-Zugang\
                    nicht erreicht werden.', 'error')
            process = False

        if process:
            (transactions, old_transactions) = finance.process_transactions(
                bank_account, statement)
        else:
            (transactions, old_transactions) = ([], [])

        if process and form.do_import.data is True:
            # save transactions to database
            session.add_all(transactions)
            session.commit()
            flash(u'Bankkontobewegungen wurden importiert.')
            return redirect(
                url_for(".accounts_show", account_id=bank_account.account_id))

    return render_template('finance/bank_accounts_import.html',
                           form=form,
                           transactions=transactions,
                           old_transactions=old_transactions)
示例#6
0
文件: __init__.py 项目: agdsn/pycroft
def bank_accounts_list_json():
    return jsonify(items=[
        {
            'name': bank_account.name,
            'bank': bank_account.bank,
            'ktonr': bank_account.account_number,
            'blz': bank_account.routing_number,
            'iban': bank_account.iban,
            'bic': bank_account.bic,
            'kto': {
                'href': url_for('.accounts_show',
                                account_id=bank_account.account_id),
                'title': 'Konto anzeigen',
                'btn_class': 'btn-primary'
            },
            'change_date': '{}'.format(
                map_or_default(bank_account.last_updated_at, datetime.date,
                               'nie'))
        } for bank_account in BankAccount.q.all()])
示例#7
0
def bank_accounts_import():
    form = BankAccountActivitiesImportForm()
    form.account.choices = [(acc.id, acc.name) for acc in BankAccount.q.all()]
    (transactions, old_transactions) = ([], [])
    if request.method != 'POST':
        del (form.start_date)
        form.end_date.data = date.today() - timedelta(days=1)

    if form.validate_on_submit():
        bank_account = BankAccount.q.get(form.account.data)

        # set start_date, end_date
        if form.start_date.data is None:
            form.start_date.data = map_or_default(
                bank_account.last_imported_at, datetime.date, date(2018, 1, 1))
        if form.end_date.data is None:
            form.end_date.data = date.today()

        # login with fints
        process = True
        try:
            fints = FinTS3Client(bank_account.routing_number, form.user.data,
                                 form.pin.data, bank_account.fints_endpoint)

            acc = next((a for a in fints.get_sepa_accounts()
                        if a.iban == bank_account.iban), None)
            if acc is None:
                raise KeyError('BankAccount with IBAN {} not found.'.format(
                    bank_account.iban))
            start_date = form.start_date.data
            end_date = form.end_date.data
            statement, with_error = fints.get_filtered_transactions(
                acc, start_date, end_date)
            flash("Transaktionen vom {} bis {}.".format(start_date, end_date))
            if len(with_error) > 0:
                flash(
                    "{} Statements enthielten fehlerhafte Daten und müssen "
                    "vor dem Import manuell korrigiert werden.".format(
                        len(with_error)), 'error')

        except (FinTSDialogError, FinTSClientPINError):
            flash(u"Ungültige FinTS-Logindaten.", 'error')
            process = False
        except KeyError:
            flash(
                u'Das gewünschte Konto kann mit diesem Online-Banking-Zugang\
                    nicht erreicht werden.', 'error')
            process = False

        if process:
            (transactions, old_transactions) = finance.process_transactions(
                bank_account, statement)
        else:
            (transactions, old_transactions) = ([], [])

        if process and form.do_import.data is True:
            # save errors to database
            for error in with_error:
                session.add(
                    MT940Error(mt940=error[0],
                               exception=error[1],
                               author=current_user,
                               bank_account=bank_account))

            # save transactions to database
            session.add_all(transactions)
            session.commit()
            flash(u'Bankkontobewegungen wurden importiert.')
            return redirect(
                url_for(".accounts_show", account_id=bank_account.account_id))

    return render_template('finance/bank_accounts_import.html',
                           form=form,
                           transactions=transactions,
                           old_transactions=old_transactions)