def test__EnergyValue__fee_4(database):
    """Fee is 0 no power_fee."""
    from sw.allotmentclub import EnergyValue, ElectricMeter, EnergyPrice
    from sw.allotmentclub import Allotment, Member
    EnergyPrice.create(year=2016, power_fee=12345)
    assert 0 == EnergyValue.create(electric_meter=ElectricMeter.create(
        allotment=Allotment.create(number='123', member=Member.create())),
                                   year=2016)._fee
def test__EnergyValue__price_2(database):
    """Price is 0 if EnergyPrice has no price."""
    from sw.allotmentclub import EnergyValue, EnergyPrice, ElectricMeter
    from sw.allotmentclub import Member, Allotment
    EnergyPrice.create(year=2016)
    assert 0 == EnergyValue.create(electric_meter=ElectricMeter.create(
        allotment=Allotment.create(number='123', member=Member.create())),
                                   year=2016)._price
def test__EnergyValue__fee_6(database):
    """Fee is power_fee if electic_power."""
    from sw.allotmentclub import EnergyValue, ElectricMeter, EnergyPrice
    from sw.allotmentclub import Allotment, Member
    EnergyPrice.create(year=2016, normal_fee=1, power_fee=3)
    assert 3 == EnergyValue.create(electric_meter=ElectricMeter.create(
        allotment=Allotment.create(number='123', member=Member.create()),
        electric_power=True),
                                   year=2016)._fee
def test__EnergyValue__fee_2(database):
    """Fee is 0 for disconnected meters."""
    from sw.allotmentclub import EnergyValue, ElectricMeter, EnergyPrice
    from sw.allotmentclub import Allotment, Member
    EnergyPrice.create(year=2016)
    assert 0 == EnergyValue.create(electric_meter=ElectricMeter.create(
        allotment=Allotment.create(number='123', member=Member.create()),
        disconnected=True),
                                   year=2016)._fee
def test__EnergyValue__price_3(database):
    """Price is price * usage."""
    from sw.allotmentclub import EnergyValue, ElectricMeter, EnergyPrice
    from sw.allotmentclub import Member, Allotment
    EnergyPrice.create(year=2016, price=2)
    assert 200 == EnergyValue.create(electric_meter=ElectricMeter.create(
        allotment=Allotment.create(number='123', member=Member.create())),
                                     year=2016,
                                     usage=100)._price
def test__EnergyValue__update_data_3(database):
    """Member is updated with owner of meter."""
    from sw.allotmentclub import EnergyValue, ElectricMeter, Member, Allotment
    mueller = Member.create(lastname='Müller')
    meyer = Member.create(lastname='Meyer')
    mueller_allotment = Allotment.create(number='123', member=mueller)
    meter = ElectricMeter.create(allotment=mueller_allotment)
    value = EnergyValue.create(electric_meter=meter, year=2016)
    assert value.member is None
    value.update_member()
    assert value.member is mueller
    # Its possible that someone pays the bill explicitely for a meter
    meter.discount_to = meyer
    value.member = None
    value.update_member()
    assert value.member is meyer
Ejemplo n.º 7
0
def import_energy_meters():
    from sw.allotmentclub import Allotment, ElectricMeter, EnergyValue
    from sw.allotmentclub import EnergyPrice
    EnergyPrice.find_or_create(year=2014,
                               value=1342354,
                               bill=42312300,
                               price=3020,
                               normal_fee=81700,
                               power_fee=243300)
    EnergyPrice.find_or_create(year=2015, value=1354334, bill=42134200)
    for allot, number, v2013, v2014, power, disc, comment in [
        ['102', '318992603', '6893', '6893', '', '', ''],
        ['104', '136426011', '10019', '10634', 'X', '', ''],
        ['106', '21785640', '23154', '24207', '', '', ''],
        ['108', '81112116', '8165', '8411', '', '', ''],
        ['110', '31850195', '65811', '66345', '', '', ''],
        ['112', '20232757', '56221', '56371', '', '', ''],
        ['114', '364754', '7361', '7407', 'X', '', ''],
        ['118', '21292097', '935', '960', '', '', ''],
        ['122', '0063487695', '7028', '7988', 'X', '', ''],
        ['124', '4270447', '7671', '8033', '', '', ''],
        ['203', '21181284', '5933', '5997', '', '', ''],
        ['203', '3295328', '1307', '1349', '', '', 'Satanlage'],
        ['249', '20868068', '12115', '12115', '', '', ''],
        ['251', '20236014', '17339', '17352', '', '', 'Wasserpumpe'],
        ['328', '409120', '5075', '5075', '', '', ''],
        ['405', '8056675', '66018', '66098', '', '', '']
    ]:
        allotment = Allotment.query().filter(Allotment.number == allot).one()
        meter = ElectricMeter.create(allotment=allotment,
                                     number=number,
                                     electric_power=bool(power),
                                     disconnected=bool(disc),
                                     comment=comment)
        for year, value in [(2013, v2013), (2014, v2014)]:
            value = EnergyValue.create(electric_meter=meter,
                                       year=year,
                                       value=int(value))
            value.update_member()
            value.update_usage()
            value.update_data()
            meter.energy_values.append(value)
        transaction.savepoint()
def test__EnergyValue__usage_1(database):
    """Usage is 0 if value is None."""
    from sw.allotmentclub import EnergyValue, ElectricMeter
    assert 0 == EnergyValue.create(electric_meter=ElectricMeter.create(),
                                   year=2016)._usage