Esempio n. 1
0
 def save(self, key, value):
     year = get_selected_year()
     if key == 'buyer_id':
         buyer = Member.get(value)
         for allotment in self.context.allotments:
             allotment.member = buyer
         SaleHistory.create(seller_id=self.context.id, buyer_id=buyer.id)
         self.context.leaving_year = year
         Booking.create(banking_account_id=2,
                        booking_day=datetime.date.today(),
                        purpose='Aufnahmebeitrag',
                        value=-250000,
                        member_id=buyer.id,
                        kind_id=13,
                        accounting_year=year)
     else:
         sale = (SaleHistory.query().filter(
             SaleHistory.date == datetime.date.today()).filter(
                 SaleHistory.seller_id == self.context.id)).one()
         buyer = Member.get(sale.buyer_id)
         query = dict(
             transfer_member_due='Mitgliedsbeitrag {}'.format(year),
             transfer_advance_pay_one='Energieabschlag I',
             transfer_advance_pay_two='Energieabschlag II',
             transfer_energy_bill='Energieabrechnung',
             transfer_assignment_due='Arbeitsstunden {}'.format(year))[key]
         for booking in (Booking.query().filter(
                 Booking.accounting_year == year).filter(
                     Booking.purpose.ilike('%{}%'.format(query))).filter(
                         Booking.member == self.context)).all():
             booking.member = buyer
     return True
Esempio n. 2
0
def test_import_sepa_raises_value_error_if_empty_sammler(database, member):
    from ..account import import_transactions, BankingAccount, SEPASammler
    from ..account import Booking
    account = BankingAccount.find_or_create(
        organization_id=1, number='3440000167')
    SEPASammler.create(pmtinfid='PII7ebef1ebc3ec4a5185583851c8f7dbb2',
                       booking_day=datetime.datetime.now(),
                       accounting_year=2018)
    statements = [{
        'date': datetime.datetime.now(),
        'currency': 'EUR',
        'purpose': 'Energieabrechnung',
        'amount': Amount(2743.12, 'EUR'),
        'applicant_name': 'Verein',
        'posting_text': 'SAMMEL-LS-EINZUG',
        'applicant_iban': 'DE123456778899',
        'applicant_bin': 'NOLADE21HAL',
        'customer_reference': ('DATUM 14.06.2018, 14.28 UHR ANZAHL 9\n'
                               'PII7ebef1ebc3ec4a5185583851c8f7dbb2')
    }]
    assert 0 == Booking.query().count()
    with pytest.raises(
            ValueError,
            match=(r"Keine Sammler-Einträge zu PmtInfId "
                   r"'PII7ebef1ebc3ec4a5185583851c8f7dbb2' gefunden.")):
        import_transactions(statements, account)
    assert 0 == Booking.query().count()
def test__EnergyValue__update_data_5(database):
    """Creates bookings for advanced pay for the next year."""
    from sw.allotmentclub import EnergyValue, ElectricMeter, EnergyPrice
    from sw.allotmentclub import Booking, BookingKind, BankingAccount
    setUp()
    BookingKind.create(title='Energieabschlag I')
    BookingKind.create(title='Energieabschlag II')
    BankingAccount.create(number='3')
    EnergyPrice.create(year=2016,
                       price=3020,
                       normal_fee=81700,
                       power_fee=243300)
    meter = ElectricMeter.get(1)
    value = EnergyValue.create(electric_meter=meter, year=2016, value=7132)
    assert Booking.query().filter(Booking.accounting_year == 2017).all() == []
    value.update_member()
    value.update_usage()
    value.update_data()
    ap1, ap2 = Booking.query().filter(Booking.accounting_year == 2017).all()
    assert ap1.value == ap2.value == -267800
    assert ap1.member == ap2.member == value.member
    assert ap1.booking_day == datetime.date(2017, 3, 31)
    assert ap2.booking_day == datetime.date(2017, 6, 30)
    assert ap1.purpose == 'Energieabschlag I für Zähler 318992603'
    assert ap2.purpose == 'Energieabschlag II für Zähler 318992603'
Esempio n. 4
0
def test_SplitBookingView_2(browser, json_fixture):
    """It splits booking on form submit."""
    from sw.allotmentclub import Booking
    setUp()
    assert len(Booking.query().all()) == 30
    browser.login()
    json_fixture.ajax(browser)
    assert 'success' == browser.json['status']
    assert Booking.get(1).is_splitted is True
    assert len(Booking.query().all()) == 32
Esempio n. 5
0
def test_SplitBookingView_3(browser, json_fixture):
    """It shows an error message if split failed."""
    from sw.allotmentclub import Booking
    setUp()
    assert len(Booking.query().all()) == 30
    browser.login()
    json_fixture.ajax(browser)
    assert 'error' == browser.json['status']
    expmsg = 'Neuer Wert muss gr\xf6\xdfer oder kleiner 0 sein.'
    assert expmsg == browser.json['msg']
    assert len(Booking.query().all()) == 30
    assert Booking.get(1).is_splitted is False
Esempio n. 6
0
def setUpSEPASammlerUpdate(kind_shorttitle):
    from sw.allotmentclub import (
        SEPASammler, Booking, BookingKind, BankingAccount, Member)
    kind = BookingKind.find_or_create(title='', shorttitle=kind_shorttitle)
    sammler = SEPASammler.create(
        booking_day='2016-06-30', accounting_year=2016, kind=kind)
    for value in [-2500, -821300]:
        Booking.find_or_create(
            value=value, banking_account=BankingAccount.find_or_create(),
            accounting_year=2016, kind=kind,
            member=Member.create(direct_debit=True))
    setUp()
    return sammler
Esempio n. 7
0
def test_import_sepa_creates_new_booking_entry_for_open_amount(database,
                                                               member):
    from ..account import import_transactions, SEPASammler, SEPASammlerEntry
    from ..account import BankingAccount, Booking
    account = BankingAccount.find_or_create(
        organization_id=1, number='3440000167')
    sammler = SEPASammler.create(
        pmtinfid='PII7ebef1ebc3ec4a5185583851c8f7dbb2',
        booking_day=datetime.datetime.now(),
        accounting_year=2018)
    SEPASammlerEntry.create(sepasammler=sammler, value=10000000)
    statements = [{
        'date': datetime.datetime.now(),
        'currency': 'EUR',
        'purpose': 'Energieabrechnung',
        'amount': Amount(2743.12, 'EUR'),
        'applicant_name': 'Verein',
        'posting_text': 'SAMMEL-LS-EINZUG',
        'applicant_iban': 'DE123456778899',
        'applicant_bin': 'NOLADE21HAL',
        'customer_reference': ('DATUM 14.06.2018, 14.28 UHR ANZAHL 9\n'
                               'PII7ebef1ebc3ec4a5185583851c8f7dbb2')
    }]
    assert 0 == Booking.query().count()
    import_transactions(statements, account)
    assert 3 == Booking.query().count()

    assert 27431200 == Booking.get(1).value
    assert 10000000 == Booking.get(2).value
    assert 17431200 == Booking.get(3).value

    assert 1 == Booking.get(2).splitted_from_id
    assert 1 == Booking.get(3).splitted_from_id

    assert 'SAMMEL-LS-EINZUG Verrechnet' == Booking.get(2).booking_text
Esempio n. 8
0
 def mitgliedsbeitrag(self):
     for booking in (Booking.query().filter(
             Booking.accounting_year == self.context.accounting_year).
                     filter(Booking.kind == self.context.kind)):
         SEPASammlerEntry().find_or_create(sepasammler=self.context,
                                           value=0 - booking.value,
                                           member=booking.member)
Esempio n. 9
0
def get_budget_sum(value, request=None, year=None):
    year = year if year else get_selected_year()
    kind = BookingKind.get(value)
    if kind.shorttitle == 'ENAB':
        kind = BookingKind.query().filter_by(shorttitle='ENAN').one()
        query = (Booking.query().filter(Booking.kind == kind).filter(
            Booking.accounting_year == year))
        return 0 - sum(b.value for b in query)
    return sum(b.value for b in get_budget_raw(value, request, year))
Esempio n. 10
0
 def advancepay(self):
     values = (Booking.query().filter(
         Booking.accounting_year == self.context.accounting_year).filter(
             Booking.kind == self.context.kind).all())
     for value in values:
         if value.value < 0:
             if value.member and value.member.direct_debit:
                 SEPASammlerEntry().find_or_create(sepasammler=self.context,
                                                   value=0 - value.value,
                                                   member=value.member)
Esempio n. 11
0
 def update(self):
     account = (BankingAccount.query().filter(
         BankingAccount.number == '1')).one()
     kind = (BookingKind.query().filter(
         BookingKind.title == 'Mitgliedsbeitrag')).one()
     year = get_selected_year()
     for member, fee_data in get_membership_fees(year).items():
         parcel_numbers = fee_data['parcel_number']
         parcel_size = fee_data['parcel_size']
         fee = fee_data['membership_fee']
         Booking.create(
             banking_account=account,
             purpose=(f'Mitgliedsbeitrag {year} Flurstück {parcel_numbers} '
                      f'({parcel_size}qm)'),
             value=0 - fee,
             accounting_year=year,
             booking_day=datetime.date(int(year), 3, 31),
             member=member,
             kind=kind)
def test__EnergyValue__update_data_6(database):
    """Creates multiple bookings for multiple meters of the same allotment."""
    from sw.allotmentclub import EnergyValue, ElectricMeter, EnergyPrice
    from sw.allotmentclub import Booking, BookingKind, BankingAccount
    setUp()
    BookingKind.create(title='Energieabrechnung')
    BookingKind.create(title='Energieabschlag I')
    BankingAccount.create(number='3')
    EnergyPrice.create(year=2016,
                       price=3020,
                       normal_fee=81700,
                       power_fee=243300)
    meter = ElectricMeter.get(1)
    value = EnergyValue.create(electric_meter=meter, year=2016, value=7132)
    meter2 = ElectricMeter.get(2)
    value2 = EnergyValue.create(electric_meter=meter2, year=2016, value=14123)
    meter.allotment = meter2.allotment

    assert Booking.query().filter(Booking.accounting_year == 2017).all() == []
    value.update_member()
    value.update_usage()
    value.update_data()
    value2.update_member()
    value2.update_usage()
    value2.update_data()

    ap1, ap2 = Booking.query().filter(Booking.accounting_year == 2017).all()
    assert ap1.value != ap2.value
    assert ap1.member == ap2.member == value.member
    assert ap1.booking_day == ap2.booking_day == datetime.date(2017, 3, 31)
    assert ap1.purpose == 'Energieabschlag I für Zähler 318992603'
    assert ap2.purpose == 'Energieabschlag I für Zähler 136426011'

    enab1, enab2 = Booking.query().filter(
        Booking.accounting_year == 2016).all()
    assert enab1.value != enab2.value
    assert enab1.member == enab2.member == value.member
    assert enab1.booking_day == enab2.booking_day == datetime.date(2016, 8, 31)
    assert enab1.purpose == 'Energieabrechnung für Zähler 318992603'
    assert enab2.purpose == 'Energieabrechnung für Zähler 136426011'
Esempio n. 13
0
 def arbeitsstunden(self):
     for member in self.active_members.all():
         bookings = (Booking.query().filter(
             Booking.accounting_year == self.context.accounting_year).
                     filter(Booking.kind == self.context.kind).filter(
                         Booking.member == member).all())
         value = 0
         for booking in bookings:
             value -= booking.value
         if value:
             SEPASammlerEntry().find_or_create(sepasammler=self.context,
                                               value=value,
                                               member=member)
Esempio n. 14
0
def test_booking_can_be_splitted(database):
    from sw.allotmentclub import Booking
    import_bookings()
    booking = _getOne()
    booking.split(259000)
    assert booking.is_splitted is True
    assert booking.splitted_from_id is None

    splitted = Booking.query().filter(
        Booking.splitted_from_id == booking.id).all()
    assert 2 == len(splitted)
    assert 259000 == splitted[0].value
    assert 341000 == splitted[1].value
Esempio n. 15
0
 def energieabrechnung(self):
     values = (Booking.query().filter(
         Booking.accounting_year == self.context.accounting_year).filter(
             Booking.kind == self.context.kind)).all()
     if self.context.is_ueberweisung:
         values = [v for v in values if v.value > 0]
     else:
         values = [v for v in values if v.value <= 0]
     for value in values:
         if value.member.direct_debit:
             SEPASammlerEntry().find_or_create(
                 sepasammler=self.context,
                 value=(value.value if self.context.is_ueberweisung else 0 -
                        value.value),
                 member=value.member)
Esempio n. 16
0
def test_BankingAccountListReportView_1(browser):
    from sw.allotmentclub import Booking, BookingKind, Member
    from ...conftest import assertFileEqual
    import transaction
    kind = BookingKind.find_or_create(
        title='Energieabschlag I', shorttitle='ENA1')
    BookingKind.find_or_create(
        title='Energieabschlag II', shorttitle='ENA2')
    member = Member.find_or_create(lastname='Wehrmann', firstname='Sebastian')
    setUp()
    for b in Booking.query():
        b.kind = kind
        b.member = member
    transaction.commit()

    browser.login()
    browser.open('http://localhost/accounts/report.pdf?for_year=2015')
    assertFileEqual(browser.contents, 'test_account_report_1.pdf')
Esempio n. 17
0
def get_incoming_raw(value, request=None, year=None):
    from sqlalchemy.sql.expression import false
    year = year if year else get_selected_year()
    kind = BookingKind.get(value)
    query = (Booking.query().join(Member).filter(Booking.kind == kind).filter(
        Booking.accounting_year == year).filter(
            Booking.ignore_in_reporting == false()).filter(
                Booking.is_splitted == false()).filter(
                    Booking.banking_account_id == 1).filter(
                        Booking.booking_text != 'SAMMEL-LS-EINZUG').filter(
                            ~Booking.purpose.like('%ANZAHL 00000%')))
    sammler = (SEPASammlerEntry.query().join(SEPASammler).join(Member).filter(
        SEPASammler.kind == kind).filter(
            SEPASammlerEntry.ignore_in_reporting == false()).filter(
                SEPASammler.accounting_year == year))
    result = query.all() + sammler.all()
    if kind.shorttitle == 'ENAB':
        result += (get_incoming_raw(
            BookingKind.query().filter_by(shorttitle='ENA1').one().id, request,
            year) + get_incoming_raw(
                BookingKind.query().filter_by(shorttitle='ENA2').one().id,
                request, year))
    return result
Esempio n. 18
0
def test_split_booking_failure_1(database):
    from sw.allotmentclub import Booking
    booking = Booking.create(value=10)
    assert booking.split(20) == 'Neuer Wert ist zu groß.'
Esempio n. 19
0
def _getOne():
    from sw.allotmentclub import Booking
    return Booking.query().filter(
        Booking.purpose == (
            "Vereinsbeitrag für 2015 Parzelle 214 Czech / Schroeter")
    ).one()
Esempio n. 20
0
def test_import_via_sparkassen_csv(database):
    from sw.allotmentclub import Booking, BankingAccount
    import_bookings()
    assert 1 == len(BankingAccount.query().all())
    assert 30 == len(Booking.query().all())
Esempio n. 21
0
def test_split_booking_failure_4(database):
    from sw.allotmentclub import Booking
    booking = Booking.create(value=-10)
    assert booking.split(20) == 'Neuer Wert muss negativ sein.'
Esempio n. 22
0
def test_split_booking_failure_5(database):
    from sw.allotmentclub import Booking
    booking = Booking.create()
    assert booking.split(0) == 'Neuer Wert muss größer oder kleiner 0 sein.'
Esempio n. 23
0
def test_split_booking_failure_2(database):
    from sw.allotmentclub import Booking
    booking = Booking.create(value=-10)
    assert booking.split(-20) == 'Neuer Wert ist zu klein.'