2 Calculate the current state of the books
7 from bluechips.lib.base import *
8 from bluechips.lib.totals import *
12 from datetime import date, timedelta
13 from decimal import Decimal
15 log = logging.getLogger(__name__)
17 class StatusController(BaseController):
20 c.settle = settle(c.debts)
23 c.total = self._total(True)
25 year = date.today() - timedelta(days=365)
26 this_year = date.today().replace(month=1, day=1)
27 this_month = date.today().replace(day=1)
28 last_month = (date.today() - timedelta(days=30)).replace(day=1)
30 c.year_total, c.this_year_total, c.this_month_total =\
31 [self._total(model.expenditures.c.date >= i)
32 for i in [year, this_year, this_month]]
35 c.last_month_total = self._total(sqlalchemy.and_(
36 model.expenditures.c.date >= last_month,
37 model.expenditures.c.date < this_month))
39 return render('/status/index.mako')
41 def _total(self, where):
42 return (meta.Session.execute(sqlalchemy.sql.select([
43 sqlalchemy.func.sum(model.expenditures.c.amount).\
45 where(where)).scalar() or Decimal("0.00")) / 100