[billreminder] Take paid into consideration when querying Bill data.
- From: Og B. Maciel <ogmaciel src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [billreminder] Take paid into consideration when querying Bill data.
- Date: Thu, 1 Oct 2009 17:40:03 +0000 (UTC)
commit d49e573af4e49f6d337097cd494d91ee12e4028a
Author: Og B. Maciel <ogmaciel gnome org>
Date: Thu Oct 1 13:20:55 2009 -0400
Take paid into consideration when querying Bill data.
src/lib/actions.py | 38 ++++++++++++++++++++++++--------------
1 files changed, 24 insertions(+), 14 deletions(-)
---
diff --git a/src/lib/actions.py b/src/lib/actions.py
index d59ee46..e88e5af 100644
--- a/src/lib/actions.py
+++ b/src/lib/actions.py
@@ -21,7 +21,7 @@ class Actions(object):
self.dal = databaselayer
- def get_interval_bills(self, status, start, end):
+ def get_interval_bills(self, start, end, paid=None):
"""
"""
@@ -29,7 +29,10 @@ class Actions(object):
try:
session = self.dal.Session()
- records = session.query(Bill).options(eagerload('category')).filter(Bill.dueDate >= start).filter(Bill.dueDate <= end).all()
+ q = session.query(Bill).options(eagerload('category')).filter(Bill.dueDate >= start).filter(Bill.dueDate <= end)
+ if status:
+ q = q.filter(Bill.paid == status)
+ records = q.all()
except Exception, e:
print str(e)
pass
@@ -38,42 +41,50 @@ class Actions(object):
return records
- def get_monthly_totals(self, status, month, year):
+ def get_monthly_totals(self, month, year, paid=None):
"""
Return a list of categories and totals for the given month
"""
- records = 0.00
+ total = 0.00
- firstOfMonth = scheduler.first_of_month(month, year)
- lastOfMonth = scheduler.last_of_month(month, year)
+ firstDay = scheduler.first_of_month(month, year)
+ lastDay = scheduler.last_of_month(month, year)
try:
session = self.dal.Session()
# records is a tuple of type Decimal
- records = session.query(func.sum(Bill.amount)).filter(Bill.dueDate >= dt).filter(Bill.dueDate <= to).one()[0]
- records = float(records)
+ q = session.query(func.sum(Bill.amount)).filter(Bill.dueDate >= dt).filter(Bill.dueDate <= to)
+ if status:
+ q = q.filter(Bill.paid == status)
+ # Got anything back?
+ if q.count():
+ # Result is of type Decimal and needs to be converted.
+ total = float(q.one()[0])
except Exception, e:
print str(e)
pass
finally:
session.close()
- return records
+ return total
- def get_monthly_bills(self, status, month, year):
+ def get_monthly_bills(self, month, year, paid=None):
"""
Return a list of all bills for the given month with STATUS
"""
records = []
- firstOfMonth = scheduler.first_of_month(month, year)
- lastOfMonth = scheduler.last_of_month(month, year)
+ firstDay = scheduler.first_of_month(month, year)
+ lastDay = scheduler.last_of_month(month, year)
try:
session = self.dal.Session()
- records = session.query(Bill).filter(Bill.dueDate >= firstOfMonth).filter(Bill.dueDate <= lastOfMonth).all()
+ q = session.query(Bill).filter(Bill.dueDate >= firstDay).filter(Bill.dueDate <= lastDay)
+ if status:
+ q = q.filter(Bill.paid == status)
+ records = q.all()
except Exception, e:
print str(e)
finally:
@@ -96,4 +107,3 @@ class Actions(object):
session.close()
return records
-
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]