Esempio n. 1
0
def test_init_with_already_empty_should_handle_like_empty():
    set_up()

    persisted_state.database_instance().depotauszuege.add(
        datum('03.01.2020'), '1demoisin', '1demokonto', 0)
    persisted_state.database_instance().depotauszuege.add(
        datum('03.01.2020'), '2demoisin', '1demokonto', 0)
    persisted_state.database_instance().depotauszuege.add(
        datum('03.01.2020'), '3demoisin', '1demokonto', 0)
    persisted_state.database_instance().depotauszuege.add(
        datum('03.01.2020'), '1demoisin', '2demokonto', 0)
    persisted_state.database_instance().depotauszuege.add(
        datum('03.01.2020'), '2demoisin', '2demokonto', 0)
    persisted_state.database_instance().depotauszuege.add(
        datum('03.01.2020'), '3demoisin', '2demokonto', 0)

    context = add_depotauszug.index(GetRequest())
    assert context['approve_title'] == 'Depotauszug hinzufügen'
    assert context['default_items'] == [
        {
            'datum':
            datum_to_string(date.today()),
            'empty_items': [],
            'filled_items': [{
                'description': '1demowert (1demoisin)',
                'isin': '1demoisin',
                'wert': 0
            }, {
                'description': '2demowert (2demoisin)',
                'isin': '2demoisin',
                'wert': 0
            }, {
                'description': '3demowert (3demoisin)',
                'isin': '3demoisin',
                'wert': 0
            }],
            'konto':
            '1demokonto'
        },
        {
            'datum':
            datum_to_string(date.today()),
            'empty_items': [],
            'filled_items': [{
                'description': '1demowert (1demoisin)',
                'isin': '1demoisin',
                'wert': 0
            }, {
                'description': '2demowert (2demoisin)',
                'isin': '2demoisin',
                'wert': 0
            }, {
                'description': '3demowert (3demoisin)',
                'isin': '3demoisin',
                'wert': 0
            }],
            'konto':
            '2demokonto'
        },
    ]
Esempio n. 2
0
def test_init():
    set_up()
    context = add_depotauszug.index(GetRequest())
    assert context['approve_title'] == 'Depotauszug hinzufügen'
    assert context['default_items'] == [
        {
            'datum':
            datum_to_string(date.today()),
            'empty_items': [{
                'description': '2demowert (2demoisin)',
                'isin': '2demoisin',
                'wert': 0
            }, {
                'description': '3demowert (3demoisin)',
                'isin': '3demoisin',
                'wert': 0
            }],
            'filled_items': [{
                'description': '1demowert (1demoisin)',
                'isin': '1demoisin',
                'wert': 20
            }],
            'konto':
            '1demokonto'
        },
        {
            'datum':
            datum_to_string(date.today()),
            'empty_items': [{
                'description': '1demowert (1demoisin)',
                'isin': '1demoisin',
                'wert': 0
            }],
            'filled_items': [{
                'description': '2demowert (2demoisin)',
                'isin': '2demoisin',
                'wert': 30
            }, {
                'description': '3demowert (3demoisin)',
                'isin': '3demoisin',
                'wert': 40
            }],
            'konto':
            '2demokonto'
        },
    ]
Esempio n. 3
0
def handle_request(request):
    if not database_instance().sparkontos.get_depots():
        return viewcore.generate_error_context('add_depotauszug', NO_VALID_DEPOT_IN_DB)

    if not database_instance().depotwerte.get_depotwerte():
        return viewcore.generate_error_context('add_depotauszug', NO_VALID_SHARE_IN_DB)

    if post_action_is(request, 'add'):
        current_date = None
        for element in request.values:
            if element.startswith('datum_'):
                current_date = datum(request.values[element])
        if not current_date:
            return viewcore.generate_error_context('add_depotauszug', 'Interner Fehler <Kein Datum gefunden>.')
        konto = request.values['konto']

        if "edit_index" in request.values:
            for element in request.values:
                if element.startswith(KEY_WERT):
                    depotwert = element.split('_')[-1]
                    db_index = database_instance().depotauszuege.resolve_index(current_date, konto, depotwert)
                    value = request.values[element].replace(",", ".")
                    value = float(value)

                    if db_index is not None:
                        database_instance().depotauszuege.edit(db_index,
                                                               datum=current_date,
                                                               depotwert=depotwert,
                                                               wert="%.2f" % value,
                                                               konto=konto)
                        non_persisted_state.add_changed_depotauszuege(
                            {
                                'fa': 'pencil',
                                'datum': datum_to_german(current_date),
                                'wert': from_double_to_german(value),
                                'depotwert': depotwert,
                                'konto': konto
                            })
                    else:
                        database_instance().depotauszuege.add(datum=current_date,
                                                              depotwert=depotwert,
                                                              wert="%.2f" % value,
                                                              konto=konto)
                        non_persisted_state.add_changed_depotauszuege(
                            {
                                'fa': 'plus',
                                'datum': datum_to_german(current_date),
                                'wert': from_double_to_german(value),
                                'depotwert': depotwert,
                                'konto': konto
                            })


        else:

            result = database_instance().depotauszuege.get_by(current_date, konto)
            if len(result) > 0:
                return viewcore.generate_error_context('add_depotauszug',
                                                       'Für es besteht bereits ein Kontoauszug für {} am {}'.format(
                                                           konto,
                                                           datum_to_german(current_date)))

            for element in request.values:
                if element.startswith(KEY_WERT):
                    depotwert = element.split('_')[-1]
                    value = request.values[element].replace(",", ".")
                    value = float(value)

                    if value == 0 and not database_instance().depotauszuege.exists_wert(konto, depotwert):
                        continue

                    database_instance().depotauszuege.add(datum=current_date,
                                                          depotwert=depotwert,
                                                          wert="%.2f" % value,
                                                          konto=konto)
                    non_persisted_state.add_changed_depotauszuege(
                        {
                            'fa': 'plus',
                            'datum': datum_to_german(current_date),
                            'wert': from_double_to_german(value),
                            'depotwert': depotwert,
                            'konto': konto
                            })

    context = viewcore.generate_transactional_context('add_depotauszug')
    context['approve_title'] = 'Depotauszug hinzufügen'

    depotwerte = database_instance().depotwerte.get_depotwerte_descriptions()
    if post_action_is(request, 'edit'):
        print("Please edit:", request.values['edit_index'])
        db_index = int(request.values['edit_index'])
        db_row = database_instance().depotauszuege.get(db_index)

        edit_datum = db_row['Datum']
        edit_konto = db_row['Konto']
        db_row = database_instance().depotauszuege.get_by(edit_datum, edit_konto)

        filled_items = calculate_filled_items(db_row, depotwerte)
        empty_items = calculate_empty_items(depotwerte, filled_items)

        default_item = [{
            'datum': datum_to_string(edit_datum),
            'konto': edit_konto,
            'filled_items': filled_items,
            'empty_items': empty_items
        }]

        context['default_items'] = default_item
        context['bearbeitungsmodus'] = True
        context['edit_index'] = db_index
        context['approve_title'] = 'Depotauszug aktualisieren'

    if 'default_items' not in context:
        context['default_items'] = []
        for konto in database_instance().sparkontos.get_depots():
            default_datum = database_instance().depotauszuege.get_latest_datum_by(konto)
            if not default_datum:
                default_datum = date.today()

            db_row = database_instance().depotauszuege.get_by(default_datum, konto)

            filled_items = calculate_filled_items(db_row, depotwerte)
            empty_items = calculate_empty_items(depotwerte, filled_items)

            if len(filled_items) == 0:
                filled_items = empty_items
                empty_items = []

            default_item = {
                'datum': datum_to_string(date.today()),
                'konto': konto,
                'filled_items': filled_items,
                'empty_items': empty_items
            }
            context['default_items'].append(default_item)

    context['letzte_erfassung'] = reversed(non_persisted_state.get_changed_depotauszuege())
    return context
def test_content():
    set_up()

    depotwerte = persisted_state.database_instance().depotwerte
    depotwerte.add(name='large_etf', isin='1isin6789012', typ=depotwerte.TYP_ETF)
    depotwerte.add(name='small_etf', isin='2isin6789012', typ=depotwerte.TYP_ETF)

    persisted_state.database_instance().depotauszuege.add(depotwert='1isin6789012', datum=today(), konto='', wert=900)
    persisted_state.database_instance().depotauszuege.add(depotwert='2isin6789012', datum=today(), konto='', wert=100)

    persisted_state.shares_data().save(
        isin='1isin6789012',
        source='',
        date=datum_to_string(today()),
        data={
            SharesInfo.REGIONEN: {
                'DEU': 0.40,
                'USA': 0.60
            },
            SharesInfo.SEKTOREN: {
                sectors.BASISKONSUMGUETER: 50,
                sectors.ENERGIE: 50
            },
            SharesInfo.KOSTEN: 0.20
        }
    )
    persisted_state.shares_data().save(
        isin='2isin6789012',
        source='',
        date=datum_to_string(today()),
        data={
            SharesInfo.REGIONEN: {
                'NOR': 0.10,
                'DEU': 0.90
            },
            SharesInfo.SEKTOREN: {
                sectors.BASISKONSUMGUETER: 50,
                sectors.IMMOBILIEN: 50
            },
            SharesInfo.KOSTEN: 1.5,
        }
    )

    result = index(GetRequest())

    assert result['regions'] == {
                                    'header': ['Gesamt',
                                               'large_etf (1isin6789012)',
                                               'small_etf (2isin6789012)'],
                                    'data': [
                                        ['United States',
                                         {'euro': 5.4,
                                          'euro_str': '5.40',
                                          'percent': 0.54,
                                          'percent_str': '0.54'},
                                         {'euro': 5.4,
                                          'euro_str': '5.40',
                                          'percent': 0.6,
                                          'percent_str': '0.60'},
                                         {'euro': 0,
                                          'euro_str': '0,00',
                                          'percent': 0,
                                          'percent_str': '0,00'}],
                                        ['Germany',
                                         {'euro': 4.5,
                                          'euro_str': '4.50',
                                          'percent': 0.45,
                                          'percent_str': '0.45'},
                                         {'euro': 3.6,
                                          'euro_str': '3.60',
                                          'percent': 0.4,
                                          'percent_str': '0.40'},
                                         {'euro': 0.9,
                                          'euro_str': '0.90',
                                          'percent': 0.9,
                                          'percent_str': '0.90'}],
                                        ['Norway',
                                         {'euro': 0.1,
                                          'euro_str': '0.10',
                                          'percent': 0.01,
                                          'percent_str': '0.01'},
                                         {'euro': 0,
                                          'euro_str': '0,00',
                                          'percent': 0,
                                          'percent_str': '0,00'},
                                         {'euro': 0.1,
                                          'euro_str': '0.10',
                                          'percent': 0.1,
                                          'percent_str': '0.10'}]],
                                   }

    assert result['sectors'] == {
        'data': [[
            'Basiskonsumgüter',
            {'euro': 500.0,
             'euro_str': '500.00',
             'percent': 50.0,
             'percent_str': '50.00'},
            {'euro': 450.0,
             'euro_str': '450.00',
             'percent': 50,
             'percent_str': '50.00'},
            {'euro': 50.0,
             'euro_str': '50.00',
             'percent': 50,
             'percent_str': '50.00'}],
            ['Energie',
             {'euro': 450.0,
              'euro_str': '450.00',
              'percent': 45.0,
              'percent_str': '45.00'},
             {'euro': 450.0,
              'euro_str': '450.00',
              'percent': 50,
              'percent_str': '50.00'},
             {'euro': 0,
              'euro_str': '0,00',
              'percent': 0,
              'percent_str': '0,00'}],
           ['Immobilien',
            {'euro': 50.0,
             'euro_str': '50.00',
             'percent': 5.0,
             'percent_str': '5.00'},
            {'euro': 0,
             'euro_str': '0,00',
             'percent': 0,
             'percent_str': '0,00'},
            {'euro': 50.0,
             'euro_str': '50.00',
             'percent': 50,
             'percent_str': '50.00'}]],
        'header': ['Gesamt', 'large_etf (1isin6789012)', 'small_etf (2isin6789012)']}
    assert result['costs'] == {
        'data': [{'costs_eur': '1.80',
                  'costs_percent': '0.20',
                  'name': 'large_etf (1isin6789012)'},
                 {'costs_eur': '1.50',
                  'costs_percent': '1.50',
                  'name': 'small_etf (2isin6789012)'}],
        'gesamt': {'costs_eur': '3.30',
                   'costs_percent': '0.33',
                   'name': 'Gesamt'},
    }
Esempio n. 5
0
def handle_request(request):
    context = viewcore.generate_transactional_context('addeinzelbuchung')
    context['element_titel'] = 'Neue Ausgabe'
    context['approve_title'] = 'Ausgabe hinzufügen'
    einzelbuchungen = persisted_state.database_instance().einzelbuchungen

    if post_action_is(request, 'add'):
        value = dezimal_float(request.values['wert']) * -1
        if 'edit_index' in request.values:
            database_index = int(request.values['edit_index'])
            datum_object = datum(request.values['date'])
            einzelbuchungen.edit(database_index, datum_object,
                                 request.values['kategorie'],
                                 request.values['name'], value)
            non_persisted_state.add_changed_einzelbuchungen({
                'fa':
                'pencil',
                'datum':
                datum_to_german(datum_object),
                'kategorie':
                request.values['kategorie'],
                'name':
                request.values['name'],
                'wert':
                from_double_to_german(value)
            })
        else:
            datum_object = datum(request.values['date'])
            einzelbuchungen.add(datum_object, request.values['kategorie'],
                                request.values['name'], value)

            non_persisted_state.add_changed_einzelbuchungen({
                'fa':
                'plus',
                'datum':
                datum_to_german(datum_object),
                'kategorie':
                request.values['kategorie'],
                'name':
                request.values['name'],
                'wert':
                from_double_to_german(value)
            })

    if post_action_is(request, 'edit'):
        db_index = int(request.values['edit_index'])

        selected_item = einzelbuchungen.get(db_index)
        selected_item['Datum'] = datum_to_string(selected_item['Datum'])
        selected_item['Wert'] = from_double_to_german(selected_item['Wert'] *
                                                      -1)
        context['default_item'] = selected_item

        context['bearbeitungsmodus'] = True
        context['edit_index'] = db_index
        context['set_kategorie'] = True
        context['element_titel'] = 'Einzelbuchung bearbeiten'
        context['active_name'] = 'Einzelbuchung bearbeiten'
        context['approve_title'] = 'Ausgabe aktualisieren'

    if 'default_item' not in context:
        context['default_item'] = {
            'Name': '',
            'Datum': '',
            'Wert': '',
        }

    context['kategorien'] = sorted(
        einzelbuchungen.get_kategorien_ausgaben(
            hide_ausgeschlossene_kategorien=True))
    context['letzte_erfassung'] = reversed(
        non_persisted_state.get_changed_einzelbuchungen())
    return context
Esempio n. 6
0
def handle_request(request):
    if request.method == 'POST' and request.values['action'] == 'add':
        value = dezimal_float(request.values['wert'])
        if request.values['typ'] == TYP_AUSGABE:
            value = value * -1

        if 'edit_index' in request.values:
            startdatum = datum(request.values['startdatum'])
            endedatum = datum(request.values['endedatum'])
            database_instance().dauerauftraege.edit(
                int(request.values['edit_index']), startdatum, endedatum,
                request.values['kategorie'], request.values['name'],
                request.values['rhythmus'], value)
            non_persisted_state.add_changed_dauerauftraege({
                'fa':
                'pencil',
                'startdatum':
                datum_to_german(startdatum),
                'endedatum':
                datum_to_german(endedatum),
                'kategorie':
                request.values['kategorie'],
                'name':
                request.values['name'],
                'rhythmus':
                request.values['rhythmus'],
                'wert':
                from_double_to_german(value)
            })
        else:
            startdatum = datum(request.values['startdatum'])
            endedatum = datum(request.values['endedatum'])
            database_instance().dauerauftraege.add(startdatum, endedatum,
                                                   request.values['kategorie'],
                                                   request.values['name'],
                                                   request.values['rhythmus'],
                                                   value)
            non_persisted_state.add_changed_dauerauftraege({
                'fa':
                'plus',
                'startdatum':
                datum_to_german(startdatum),
                'endedatum':
                datum_to_german(endedatum),
                'kategorie':
                request.values['kategorie'],
                'name':
                request.values['name'],
                'rhythmus':
                request.values['rhythmus'],
                'wert':
                from_double_to_german(value)
            })

    context = viewcore.generate_transactional_context('adddauerauftrag')
    context['approve_title'] = 'Dauerauftrag hinzufügen'

    if post_action_is(request, 'edit'):
        db_index = int(request.values['edit_index'])
        default_item = database_instance().dauerauftraege.get(db_index)
        default_item['Startdatum'] = datum_to_string(
            default_item['Startdatum'])
        default_item['Endedatum'] = datum_to_string(default_item['Endedatum'])
        default_item['Rhythmus'] = default_item['Rhythmus']

        if default_item['Wert'] < 0:
            default_item['typ'] = TYP_AUSGABE
        else:
            default_item['typ'] = TYPE_EINNAHME

        default_item['Wert'] = from_double_to_german(abs(default_item['Wert']))

        context['default_item'] = default_item
        context['bearbeitungsmodus'] = True
        context['edit_index'] = db_index
        context['approve_title'] = 'Dauerauftrag aktualisieren'
        context['element_titel'] = 'Dauerauftrag bearbeiten'
        context['active_name'] = 'Dauerauftrag bearbeiten'

    if 'default_item' not in context:
        context['default_item'] = {
            'Startdatum': '',
            'Endedatum': '',
            'typ': TYP_AUSGABE,
            'Rhythmus': ALL_FREQUENCY_NAMES[0],
            'Wert': '',
            'Name': ''
        }

    context['kategorien'] = sorted(
        database_instance().einzelbuchungen.get_alle_kategorien(
            hide_ausgeschlossene_kategorien=True))
    context['letzte_erfassung'] = reversed(
        non_persisted_state.get_changed_dauerauftraege())
    context['rhythmen'] = ALL_FREQUENCY_NAMES

    return context
Esempio n. 7
0
def handle_request(request):
    if not database_instance().sparkontos.get_sparfaehige_kontos():
        return viewcore.generate_error_context('add_sparbuchung',
                                               NO_VALID_SAVINGS_ACCOUNT_IN_DB)

    if post_action_is(request, 'add'):
        date = datum(request.values['datum'])
        value = request.values['wert'].replace(",", ".")
        value = float(value)

        if request.values[EIGENSCHAFT] == EIGENSCHAFT_AUSZAHLUNG:
            value = value * -1

        if "edit_index" in request.values:
            database_instance().sparbuchungen.edit(
                int(request.values['edit_index']),
                datum=date,
                name=request.values['name'],
                wert="%.2f" % value,
                typ=request.values['typ'],
                konto=request.values['konto'])
            non_persisted_state.add_changed_sparbuchungen({
                'fa':
                'pencil',
                'datum':
                datum_to_german(date),
                'wert':
                from_double_to_german(value),
                'name':
                request.values['name'],
                'typ':
                request.values['typ'],
                'konto':
                request.values['konto']
            })

        else:
            database_instance().sparbuchungen.add(
                datum=date,
                name=request.values['name'],
                wert="%.2f" % value,
                typ=request.values['typ'],
                konto=request.values['konto'])
            non_persisted_state.add_changed_sparbuchungen({
                'fa':
                'plus',
                'datum':
                datum_to_german(date),
                'wert':
                from_double_to_german(value),
                'name':
                request.values['name'],
                'typ':
                request.values['typ'],
                'konto':
                request.values['konto']
            })

    context = viewcore.generate_transactional_context('add_sparbuchung')
    context['approve_title'] = 'Sparbuchung hinzufügen'
    if post_action_is(request, 'edit'):
        print("Please edit:", request.values['edit_index'])
        db_index = int(request.values['edit_index'])
        db_row = database_instance().sparbuchungen.get(db_index)

        if db_row['Wert'] > 0:
            eigenschaft = EIGENSCHAFT_EINZAHLUNG
        else:
            eigenschaft = EIGENSCHAFT_AUSZAHLUNG

        default_item = {
            'edit_index': str(db_index),
            'datum': datum_to_string(db_row['Datum']),
            'name': db_row['Name'],
            'wert': from_double_to_german(abs(db_row['Wert'])),
            'typ': db_row['Typ'],
            'eigenschaft': eigenschaft,
            'konto': db_row['Konto']
        }

        context['default_item'] = default_item
        context['bearbeitungsmodus'] = True
        context['edit_index'] = db_index
        context['approve_title'] = 'Sparbuchung aktualisieren'

    if 'default_item' not in context:
        context['default_item'] = {
            'name': '',
            'wert': '',
            'datum': '',
            'typ': '',
            'konto': ''
        }

    context['kontos'] = database_instance().sparkontos.get_sparfaehige_kontos()
    context['typen'] = database_instance().sparbuchungen.AUFTRAGS_TYPEN
    context[EIGENSCHAFTEN] = [EIGENSCHAFT_EINZAHLUNG, EIGENSCHAFT_AUSZAHLUNG]
    context['letzte_erfassung'] = reversed(
        non_persisted_state.get_changed_sparbuchungen())
    return context
Esempio n. 8
0
def handle_request(request):
    if not database_instance().sparkontos.get_depots():
        return viewcore.generate_error_context('add_order',
                                               NO_VALID_DEPOT_IN_DB)

    if not database_instance().depotwerte.get_depotwerte():
        return viewcore.generate_error_context('add_order',
                                               NO_VALID_SHARE_IN_DB)

    if post_action_is(request, 'add'):
        date = datum(request.values['datum'])
        value = request.values['wert'].replace(",", ".")
        value = float(value)

        if request.values[TYP] == TYP_VERKAUF:
            value = value * -1

        if "edit_index" in request.values:
            database_instance().order.edit(
                int(request.values['edit_index']),
                datum=date,
                name=request.values['name'],
                wert="%.2f" % value,
                depotwert=request.values['depotwert'],
                konto=request.values['konto'])
            non_persisted_state.add_changed_order({
                'fa':
                'pencil',
                'datum':
                datum_to_german(date),
                'wert':
                from_double_to_german(abs(value)),
                'name':
                request.values['name'],
                TYP:
                request.values[TYP],
                'depotwert':
                request.values['depotwert'],
                'konto':
                request.values['konto']
            })

        else:
            database_instance().order.add(
                datum=date,
                name=request.values['name'],
                wert="%.2f" % value,
                depotwert=request.values['depotwert'],
                konto=request.values['konto'])
            non_persisted_state.add_changed_order({
                'fa':
                'plus',
                'datum':
                datum_to_german(date),
                'wert':
                from_double_to_german(value),
                'name':
                request.values['name'],
                TYP:
                request.values[TYP],
                'value':
                '%.2f' % abs(value),
                'depotwert':
                request.values['depotwert'],
                'konto':
                request.values['konto']
            })

    context = viewcore.generate_transactional_context('add_order')
    context['approve_title'] = 'Order hinzufügen'
    if post_action_is(request, 'edit'):
        print("Please edit:", request.values['edit_index'])
        db_index = int(request.values['edit_index'])
        db_row = database_instance().order.get(db_index)

        if db_row['Wert'] > 0:
            typ = TYP_KAUF
        else:
            typ = TYP_VERKAUF

        default_item = {
            'edit_index': str(db_index),
            'datum': datum_to_string(db_row['Datum']),
            'name': db_row['Name'],
            'wert': from_double_to_german(abs(db_row['Wert'])),
            'depotwert': db_row['Depotwert'],
            'typ': typ,
            'konto': db_row['Konto']
        }

        context['default_item'] = default_item
        context['bearbeitungsmodus'] = True
        context['edit_index'] = db_index
        context['approve_title'] = 'Order aktualisieren'

    if 'default_item' not in context:
        context['default_item'] = {
            'name': '',
            'wert': '',
            'datum': '',
            'depotwert': '',
            'konto': ''
        }

    context['kontos'] = database_instance().sparkontos.get_depots()
    context[TYPEN] = [TYP_KAUF, TYP_VERKAUF]
    context['depotwerte'] = database_instance(
    ).depotwerte.get_depotwerte_descriptions()
    context['letzte_erfassung'] = reversed(
        non_persisted_state.get_changed_order())
    return context
Esempio n. 9
0
def handle_request(request, import_prefix='', gemeinsam=False):
    context = viewcore.generate_transactional_context('import')
    if request.method == "POST":
        if post_action_is(request, 'load_online_transactions'):
            serverurl = request.values['server']
            serverurl = _add_protokoll_if_needed(serverurl)
            _save_server_creds(serverurl, request.values['email'])

            auth_container = login(serverurl, request.values['email'],
                                   request.values['password'])

            json_report = get_einzelbuchungen(serverurl, auth_container)
            print(json_report)
            print('Mapping to text report')
            text_report = JSONToTextMapper().map(json_report)
            print(text_report)

            response = handle_request(PostRequest({'import': text_report}),
                                      import_prefix='Internet')

            delete_einzelbuchungen(serverurl, auth_container=auth_container)
            return response

        if post_action_is(request, 'load_online_gemeinsame_transactions'):
            serverurl = request.values['server']
            serverurl = _add_protokoll_if_needed(serverurl)
            _save_server_creds(serverurl, request.values['email'])
            print(serverurl)
            auth_container = login(serverurl, request.values['email'],
                                   request.values['password'])
            online_username = auth_container.online_name()
            print('butler_online username: '******'table before person mapping', table)
            table.Person = table.Person.map(
                lambda x: database_instance().name if x == online_username else
                configuration_provider.get_configuration('PARTNERNAME'))
            online_content = TextReportWriter().generate_report(table)
            response = handle_request(PostRequest({'import': online_content}),
                                      import_prefix='Internet_Gemeinsam',
                                      gemeinsam=True)

            delete_gemeinsame_buchungen(serverurl,
                                        auth_container=auth_container)
            return response

        elif post_action_is(request, 'set_kategorien'):
            kategorien = ','.join(
                sorted(database_instance().einzelbuchungen.get_alle_kategorien(
                    hide_ausgeschlossene_kategorien=True)))
            serverurl = request.values['server']

            serverurl = _add_protokoll_if_needed(serverurl)
            _save_server_creds(serverurl, request.values['email'])

            auth_container = login(serverurl, request.values['email'],
                                   request.values['password'])
            set_kategorien(serverurl,
                           kategorien=kategorien,
                           auth_container=auth_container)
            set_success_message(
                context,
                'Kategorien erfolgreich in die Online-Version übertragen.')

        elif post_action_is(request, 'upload_gemeinsame_transactions'):
            serverurl = request.values['server']
            serverurl = _add_protokoll_if_needed(serverurl)
            _save_server_creds(serverurl, request.values['email'])
            print(serverurl)
            auth_container = login(serverurl, request.values['email'],
                                   request.values['password'])
            online_username = auth_container.online_name()
            print('butler_online username:'******'butler offline username:'******'butler online partnername:', online_partnername)
            offline_partnername = configuration_provider.get_configuration(
                'PARTNERNAME')
            print('butler offline partnername:', offline_partnername)

            buchungen = database_instance(
            ).gemeinsamebuchungen.get_renamed_list(offline_username,
                                                   online_username,
                                                   offline_partnername,
                                                   online_partnername)
            request_data = []

            for buchung in buchungen:
                request_data.append({
                    'datum': datum_to_string(buchung['Datum']),
                    'name': buchung['Name'],
                    'wert': buchung['Wert'],
                    'kategorie': buchung['Kategorie'],
                    'zielperson': buchung['Person']
                })
            anzahl_buchungen = len(buchungen)
            result = upload_gemeinsame_buchungen(serverurl, request_data,
                                                 auth_container)
            if result:
                set_success_message(
                    context,
                    '{anzahl_buchungen} Buchungen wurden erfolgreich hochgeladen.'
                    .format(anzahl_buchungen=anzahl_buchungen))
                database_instance().gemeinsamebuchungen.drop_all()
            else:
                set_error_message(
                    context,
                    'Fehler beim Hochladen der gemeinsamen Buchungen.')

        else:
            print(request.values)
            content = request.values['import'].replace('\r', '')
            write_import(import_prefix + 'Import_' + str(datetime.now()),
                         content)

            imported_values = TextReportReader().read(content)
            datenbank_kategorien = set(
                database_instance().einzelbuchungen.get_alle_kategorien())
            nicht_passende_kategorien = []
            for imported_kategorie in set(imported_values.Kategorie):
                if imported_kategorie not in datenbank_kategorien:
                    nicht_passende_kategorien.append(imported_kategorie)

            if 'Person' in imported_values.columns:
                gemeinsam = True

            if not nicht_passende_kategorien:
                print('keine unpassenden kategorien gefunden')
                print('beginne mit dem direkten import')
                _import(imported_values, gemeinsam)

                last_elements = []
                for row_index, row in imported_values.iterrows():
                    last_elements.append((row_index, row.Datum, row.Name,
                                          row.Kategorie, row.Wert))
                context['ausgaben'] = last_elements
                context = set_success_message(
                    context, _get_success_message(last_elements))
            elif _mapping_passt(request.values, nicht_passende_kategorien):
                print(
                    'import kann durchgeführt werden, weil mapping vorhanden')
                imported_values = _map_kategorien(imported_values,
                                                  nicht_passende_kategorien,
                                                  request.values)
                _import(imported_values, gemeinsam)

                last_elements = []
                for row_index, row in imported_values.iterrows():
                    last_elements.append((row_index, row.Datum, row.Name,
                                          row.Kategorie, row.Wert))
                context['ausgaben'] = last_elements
                context = set_success_message(
                    context, _get_success_message(last_elements))
            else:
                print("Nicht passende Kategorien: ", nicht_passende_kategorien)
                options = ['neue Kategorie anlegen']
                for kategorie_option in datenbank_kategorien:
                    options.append('als ' + str(kategorie_option) +
                                   ' importieren')
                options = sorted(options)
                options.insert(0, 'neue Kategorie anlegen')
                context['element_titel'] = 'Kategorien zuweisen'
                context['unpassende_kategorien'] = nicht_passende_kategorien
                context['optionen'] = options
                context['import'] = request.values['import']
                context['special_page'] = 'shared/import_mapping.html'

    context[
        'ONLINE_DEFAULT_SERVER'] = configuration_provider.get_configuration(
            'ONLINE_DEFAULT_SERVER')
    context['ONLINE_DEFAULT_USER'] = configuration_provider.get_configuration(
        'ONLINE_DEFAULT_USER')
    return context
Esempio n. 10
0
def handle_request(request):
    if post_action_is(request, 'add'):
        date = datum(request.values['date'])
        value = request.values['wert'].replace(",", ".")
        value = float(value)
        value = value * -1
        if "edit_index" in request.values:
            database_instance().gemeinsamebuchungen.edit(
                int(request.values['edit_index']),
                datum=date,
                name=str(request.values['name']),
                kategorie=request.values['kategorie'],
                wert=value,
                person=request.values['person'])
            non_persisted_state.add_changed_gemeinsamebuchungen({
                'fa':
                'pencil',
                'datum':
                datum_to_german(date),
                'kategorie':
                request.values['kategorie'],
                'name':
                request.values['name'],
                'wert':
                from_double_to_german(value),
                'person':
                request.values['person']
            })

        else:
            database_instance().gemeinsamebuchungen.add(
                ausgaben_datum=date,
                kategorie=request.values['kategorie'],
                ausgaben_name=request.values['name'],
                wert="%.2f" % value,
                person=request.values['person'])
            non_persisted_state.add_changed_gemeinsamebuchungen({
                'fa':
                'plus',
                'datum':
                datum_to_german(date),
                'kategorie':
                request.values['kategorie'],
                'name':
                request.values['name'],
                'wert':
                from_double_to_german(value),
                'person':
                request.values['person']
            })

    context = viewcore.generate_transactional_context("addgemeinsam")
    context['approve_title'] = 'Gemeinsame Ausgabe hinzufügen'
    if post_action_is(request, 'edit'):
        print("Please edit:", request.values['edit_index'])
        db_index = int(request.values['edit_index'])
        db_row = database_instance().gemeinsamebuchungen.get(db_index)
        default_item = {
            'edit_index': str(db_index),
            'datum': datum_to_string(db_row['Datum']),
            'name': db_row['Name'],
            'wert': from_double_to_german(db_row['Wert'] * -1),
            'kategorie': db_row['Kategorie'],
            'person': db_row['Person']
        }

        context['default_item'] = default_item
        context['bearbeitungsmodus'] = True
        context['edit_index'] = db_index
        context['approve_title'] = 'Gemeinsame Ausgabe aktualisieren'

    if 'default_item' not in context:
        context['default_item'] = {'name': '', 'wert': '', 'datum': ''}

    context['personen'] = [
        database_instance().name,
        viewcore.name_of_partner()
    ]
    context['kategorien'] = sorted(
        database_instance().einzelbuchungen.get_kategorien_ausgaben(
            hide_ausgeschlossene_kategorien=True))
    context['letzte_erfassung'] = reversed(
        non_persisted_state.get_changed_gemeinsamebuchungen())
    return context
Esempio n. 11
0
def _handle_request(request):
    context = viewcore.generate_base_context('gemeinsamabrechnen')
    db = database_instance()
    alle_gemeinsamen_buchungen = db.gemeinsamebuchungen

    if alle_gemeinsamen_buchungen.is_empty():
        context['%Errortext'] = 'Keine gemeinsame Buchungen erfasst'
        return context

    name_self = db.name
    name_partner = name_of_partner()

    mindate = alle_gemeinsamen_buchungen.min_date()
    maxdate = alle_gemeinsamen_buchungen.max_date()

    set_mindate = get_post_parameter_or_default(request,
                                                'set_mindate',
                                                mindate,
                                                mapping_function=datum)
    set_maxdate = get_post_parameter_or_default(request,
                                                'set_maxdate',
                                                maxdate,
                                                mapping_function=datum)
    selector = alle_gemeinsamen_buchungen.select().select_range(
        set_mindate, set_maxdate)

    replay_value_if_defined(context, 'set_verhaeltnis', request, default=50)
    set_verhaeltnis = int(context['set_verhaeltnis'])
    replay_value_if_defined(context, 'set_limit', request)
    replay_value_if_defined(context, 'set_limit_value', request, default=50)
    replay_value_if_defined(context, 'set_limit_fuer', request)
    replay_value_if_defined(context, 'set_self_kategorie', request)
    replay_value_if_defined(context, 'set_self_kategorie_value', request)
    replay_value_if_defined(context, 'set_other_kategorie', request)
    replay_value_if_defined(context, 'set_other_kategorie_value', request,
                            'Korrekturbuchung')

    select_self = selector.fuer(name_self)
    select_partner = selector.fuer(name_partner)
    ausgabe_self = select_self.sum()
    ausgabe_partner = select_partner.sum()
    ausgabe_gesamt = selector.sum()

    ergebnis = ''

    if set_verhaeltnis != 50:
        ergebnis += '{self_name} übernimmt einen Anteil von {verhaeltnis}% der Ausgaben.<br>'.format(
            self_name=name_self, verhaeltnis=set_verhaeltnis)

    if is_post_parameter_set(request, 'set_limit'):
        ergebnis_satz = '''Durch das Limit bei {name} von {limit_value} EUR wurde das Verhältnis von {verhaeltnis_alt} auf {verhaeltnis_neu} aktualisiert<br>'''
        verhaeltnis_alt = set_verhaeltnis
        limited_person = request.values['set_limit_fuer']
        limit_value = int(request.values['set_limit_value'])

        if limited_person == name_partner:
            partner_soll = abs(ausgabe_gesamt *
                               ((100 - set_verhaeltnis) / 100))
            if partner_soll > limit_value:
                set_verhaeltnis = 100 - abs(
                    (limit_value / ausgabe_gesamt) * 100)
                ergebnis += ergebnis_satz.format(
                    name=name_partner,
                    limit_value=limit_value,
                    verhaeltnis_alt=verhaeltnis_alt,
                    verhaeltnis_neu=set_verhaeltnis)
        else:
            self_soll = abs(ausgabe_gesamt * (set_verhaeltnis / 100))
            if self_soll > limit_value:
                set_verhaeltnis = abs((limit_value / ausgabe_gesamt) * 100)
                ergebnis += ergebnis_satz.format(
                    name=name_self,
                    limit_value=limit_value,
                    verhaeltnis_alt=verhaeltnis_alt,
                    verhaeltnis_neu=set_verhaeltnis)

    self_soll = (ausgabe_gesamt * (set_verhaeltnis / 100))
    self_diff = self_soll - ausgabe_self
    partner_soll = (ausgabe_gesamt * ((100 - set_verhaeltnis) / 100))
    partner_diff = partner_soll - ausgabe_partner

    ergebnis_satz = 'Die gemeinsamen Ausgaben sind ausgeglichen.'
    if partner_diff > 0 or self_diff < 0:
        ergebnis_satz = name_partner + ' bekommt von ' + name_self + ' noch ' + str(
            '%.2f' % partner_diff) + '€.'

    if self_diff > 0 or partner_diff < 0:
        ergebnis_satz = name_self + ' bekommt von ' + name_partner + ' noch ' + str(
            '%.2f' % self_diff) + '€.'
    ergebnis += ergebnis_satz

    context['str_ergebnis'] = ergebnis.replace('<br>', '\n')
    context['ausgabe_partner'] = "%.2f" % abs(ausgabe_partner)
    context['ausgabe_self'] = "%.2f" % abs(ausgabe_self)
    context['self_diff'] = "%.2f" % self_diff
    context['partner_diff'] = "%.2f" % partner_diff
    context['self_soll'] = "%.2f" % abs(self_soll)
    context['partner_soll'] = "%.2f" % abs(partner_soll)
    context['ausgabe_gesamt'] = "%.2f" % abs(ausgabe_gesamt)
    context['ergebnis'] = ergebnis
    context['myname'] = name_self
    context['partnername'] = name_partner

    context['mindate'] = datum_to_german(mindate)
    context['maxdate'] = datum_to_german(maxdate)
    context['count'] = alle_gemeinsamen_buchungen.select().count()

    context['set_mindate_rfc'] = datum_to_string(set_mindate)
    context['set_maxdate_rfc'] = datum_to_string(set_maxdate)
    context['set_mindate'] = datum_to_german(set_mindate)
    context['set_maxdate'] = datum_to_german(set_maxdate)
    context['set_count'] = selector.count()
    context['set_verhaeltnis_real'] = int(set_verhaeltnis)

    context['kategorien'] = db.einzelbuchungen.get_alle_kategorien(
        hide_ausgeschlossene_kategorien=True)

    return context