def _payperiods_preshot(self):
logger.info('payperiods preshot')
# BEGIN DB update
conn = engine.connect()
data_sess = scoped_session(
sessionmaker(autocommit=False, autoflush=False, bind=conn)
)
pp = BiweeklyPayPeriod.period_for_date(dtnow(), data_sess).previous
data_sess.add(Budget(
name='Budget3', is_periodic=True, starting_balance=0
))
data_sess.add(Budget(
name='Budget4', is_periodic=True, starting_balance=0
))
data_sess.flush()
data_sess.commit()
budgets = list(data_sess.query(Budget).filter(
Budget.is_active.__eq__(True),
Budget.is_income.__eq__(False),
Budget.is_periodic.__eq__(True)
).all())
for i in range(0, 12): # payperiods
mult = choice([-1, 1])
target = 2011.67 + (mult * uniform(0, 500))
total = 0
count = 0
while total < target:
count += 1
amt = uniform(0, target * 0.2)
if total + amt > target:
amt = target - total
total += amt
amt = Decimal(Decimal(amt).quantize(
Decimal('.001'), rounding=ROUND_HALF_UP
))
data_sess.add(Transaction(
account_id=1,
budgeted_amount=amt,
actual_amount=amt,
budget=choice(budgets),
date=pp.start_date + timedelta(days=1),
description='Transaction %d.%d' % (i, count)
))
data_sess.flush()
data_sess.commit()
pp = pp.next
data_sess.close()
conn.close()
# END DB update
self.get('/payperiods')
sleep(1)
评论列表
文章目录