Exemple #1
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)
Exemple #2
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)
Exemple #3
0
def fix_import_error(error_id):
    error = MT940Error.q.get(error_id)
    form = FixMT940Form()
    (transactions, old_transactions, doubtful_transactions) = ([], [], [])
    new_exception = None

    if request.method != 'POST':
        form.mt940.data = error.mt940

    if form.validate_on_submit():
        statement = []
        try:
            statement += mt940_to_array(form.mt940.data)
        except Exception as e:
            new_exception = str(e)

        if new_exception is None:
            flash('MT940 ist jetzt valide.', 'success')
            (transactions, old_transactions,
             doubtful_transactions) = finance.process_transactions(
                 error.bank_account, statement)

            if form.do_import.data is True:
                # save transactions to database
                session.add_all(transactions)
                session.delete(error)
                session.commit()
                flash(u'Bankkontobewegungen wurden importiert.')
                return redirect(url_for(".bank_accounts_import_errors"))
        else:
            flash('Es existieren weiterhin Fehler.', 'error')

    return render_template('finance/bank_accounts_error_fix.html',
                           error_id=error_id,
                           exception=error.exception,
                           new_exception=new_exception,
                           form=form,
                           transactions=transactions,
                           old_transactions=old_transactions,
                           doubtful_transactions=doubtful_transactions)
Exemple #4
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)