Exemple #1
0
def test_can_download_and_upload_energy_list(browser):
    from sw.allotmentclub import EnergyValue, ElectricMeter
    year = datetime.now().year
    setUp()
    assert [8165, 8411
            ] == sorted([v.value for v in ElectricMeter.get(4).energy_values])
    browser.login()
    browser.open('http://localhost/electricity/export')
    wb = openpyxl.load_workbook(BytesIO(browser.contents))
    sheet = wb.get_active_sheet()
    for index, row in enumerate(sheet.rows):
        if index in (0, 1):
            continue
        row[-3].value = row[5].value or 0 + 100
        row[-1].value = True
        if row[0].value == 4:
            row[-1].value = False
    to_import = BytesIO()
    wb.save(to_import)
    to_import.seek(0)
    browser._upload(
        'http://localhost/electricity/import',
        ('import.xlsx',
         'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
         to_import))
    assert 16 == (EnergyValue.query().filter(EnergyValue.year == year).count())
    assert 1 == (EnergyValue.query().filter(EnergyValue.year == year).filter(
        EnergyValue.estimated_value.is_(True)).count())
    assert [100, 8165, 8411
            ] == sorted([v.value for v in ElectricMeter.get(4).energy_values])
Exemple #2
0
 def _data(self, query):
     data = super(EnergyMeterExporterView, self)._data(query)
     for item in data:
         item = list(item)
         meter = ElectricMeter.get(item[1])
         item[1] = meter.allotment.member.lastname
         item[2] = meter.comment or meter.allotment.member.firstname
         year = get_selected_year()
         value_sec3last_year = meter.get_value(year - 3)
         value_sec2last_year = meter.get_value(year - 2)
         value_last_year = meter.get_value(year - 1)
         value_current_year = meter.get_value(year)
         item[-4] = self._get_value(value_sec3last_year)
         item[-3] = self._get_value(value_sec2last_year)
         item[-2] = self._get_value(value_last_year)
         item[-1] = self._get_value(value_current_year)
         yield item
     item = [0, 'Hauptzähler', 'kWh', 0, 48328153, '', '', '', '']
     for i in range(-1, -5, -1):
         price = (EnergyPrice.query().filter(EnergyPrice.year == year + i +
                                             1).first())
         if price:
             item[i] = price.value
     yield item
     item = [0, 'Endabrechnung', 'microcent', 0, 48328153, '', '', '', '']
     for i in range(-1, -5, -1):
         price = (EnergyPrice.query().filter(EnergyPrice.year == year + i +
                                             1).first())
         if price:
             item[i] = price.bill
     yield item
Exemple #3
0
 def add_data(self, line):
     year = datetime.datetime.now().year
     if line[1].value == 'Hauptzähler':
         EnergyPrice.find_or_create(
             year=year).value = line[self.cell_index].value
         transaction.savepoint()
         return
     if line[1].value == 'Endabrechnung':
         EnergyPrice.find_or_create(
             year=year).bill = line[self.cell_index].value
         transaction.savepoint()
         return
     if line[0].value is None and line[1].value is None:
         return
     meter = ElectricMeter.by_number(line[4].value)
     if meter is None:
         meter = ElectricMeter.get(line[0].value)
         if line[4].value:
             meter.number = line[4].value
     if not line[self.cell_index].value:
         value = int(line[self.cell_index - 1].value)
         estimated = True
     else:
         value = int(line[self.cell_index].value)
         estimated = not line[self.cell_index + 2].value
     energy_value = EnergyValue.create(electric_meter=meter,
                                       year=year,
                                       value=value,
                                       estimated_value=estimated)
     if energy_value not in meter.energy_values:
         meter.energy_values.append(energy_value)
     energy_value.update_member()
     energy_value.update_usage()  # verbrauch berechnen
     transaction.savepoint()
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'
Exemple #5
0
def get_discount_to(electric_meter_id, request=None):
    meter = ElectricMeter.get(electric_meter_id)
    allotment = meter.allotment
    if meter.discount_to:
        member = meter.discount_to
    else:
        member = meter.allotment.member
    return '{} ({}, {})'.format(allotment.number, member.lastname,
                                member.firstname)
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'
Exemple #7
0
 def __call__(self):
     year = datetime.datetime.now().year
     # Sonderbehandlung Satellitenanlage
     meter = ElectricMeter.get(124)
     if meter and not meter.get_value(year):
         last = meter.get_last_value()
         energy_value = EnergyValue.create(electric_meter=meter,
                                           year=year,
                                           value=last.value + 552)
         energy_value.update_member()
         energy_value.update_usage()  # verbrauch berechnen
         if energy_value not in meter.energy_values:
             meter.energy_values.append(energy_value)
     return super(EnergyMeterImporterView, self).__call__()
def test__EnergyValue__update_data_2(database):
    """Updates bill data of EnergyValue."""
    from sw.allotmentclub import EnergyValue, ElectricMeter, EnergyPrice
    setUp()
    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 value.price is None
    value.update_member()
    value.update_usage()
    value.update_data()
    assert 239 == value.usage
    assert 721780 == value.price
    assert 81700 == value.fee
    assert value.whole_price == value.fee + value.price
    assert value.whole_price == value.to_pay
    assert 267826 == value.advance_pay