示例#1
0
def downgrade():
    from sw.allotmentclub import ElectricMeter
    import transaction

    db = risclog.sqlalchemy.db.get_database()
    db._engines['portal'] = dict(
        engine=op.get_bind().engine,
        alembic_location="sw.allotmentclub:portal",
    )

    to_delete = (ElectricMeter.query().filter(
        ElectricMeter.number == NEW_NUMBER).one())
    to_delete.get_value(YEAR).delete()
    to_delete.delete()

    old = (ElectricMeter.query().filter(
        ElectricMeter.number == OLD_NUMBER).one())
    old.get_value(YEAR - 1).delete()
    transaction.commit()
示例#2
0
def upgrade():
    from sw.allotmentclub import ElectricMeter
    import transaction

    db = risclog.sqlalchemy.db.get_database()
    db._engines['portal'] = dict(
        engine=op.get_bind().engine,
        alembic_location="sw.allotmentclub:portal",
    )

    old = (ElectricMeter.query().filter(
        ElectricMeter.number == OLD_NUMBER).one())
    old.replace(old_value=OLD_VALUE,
                new_number=NEW_NUMBER,
                new_value=NEW_VALUE)
    transaction.commit()
示例#3
0
 def update_price(self):
     org_id = self.request.user.organization_id
     current_year = get_selected_year()
     price = (EnergyPrice.query().filter(
         EnergyValue.organization_id == org_id).filter(
             EnergyPrice.year == current_year).one())
     price.usage_hauptzaehler = price.value - (EnergyPrice.query().filter(
         EnergyValue.organization_id == org_id).filter(
             EnergyPrice.year == current_year - 1).one().value)
     price.usage_members = sum(e.usage for e in (EnergyValue.query().filter(
         EnergyValue.year == current_year).filter(
             EnergyValue.organization_id == org_id)))
     price.leakage_current = price.usage_hauptzaehler - price.usage_members
     price.price = price.bill / price.usage_hauptzaehler
     self.phases = sum(3 if e.electric_power else 1
                       for e in (ElectricMeter.query().filter(
                           ElectricMeter.disconnected.is_(False)).filter(
                               ElectricMeter.organization_id == org_id)))
     price.normal_fee = price.leakage_current * price.price / self.phases
     price.power_fee = price.normal_fee * 3