@@ 220-233 (lines=14) @@ | ||
217 | .filter(cls.type==trans_type)\ |
|
218 | .filter(event.Event.deleted==False) |
|
219 | ||
220 | if start: |
|
221 | q = q.filter(event.Event.timestamp>=start) |
|
222 | if end: |
|
223 | q = q.filter(event.Event.timestamp<end) |
|
224 | ||
225 | q = q.order_by(desc(event.Event.timestamp)) |
|
226 | ||
227 | return q |
|
228 | ||
229 | @classmethod |
|
230 | @datefilter_one_or_zero(label=None) |
|
231 | def get_balance(cls, trans_type, account_obj): |
|
232 | r = DBSession.query(coalesce(func.sum(cls.amount), 0).label("balance"))\ |
|
233 | .join(event.Event)\ |
|
234 | .filter(or_(cls.fr_account_cash_id==account_obj.id, |
|
235 | cls.to_account_cash_id==account_obj.id, |
|
236 | cls.fr_account_virt_id==account_obj.id, |
|
@@ 277-289 (lines=13) @@ | ||
274 | @classmethod |
|
275 | @datefilter_one_or_zero(label='a') |
|
276 | def total(cls): |
|
277 | r = DBSession.query(func.sum(cls.amount).label('a'))\ |
|
278 | .join(event.Event)\ |
|
279 | .filter(event.Event.deleted==False) |
|
280 | return r |
|
281 | ||
282 | # Get the total amount of discounts people have received for keeping |
|
283 | # money in their account |
|
284 | @classmethod |
|
285 | def discounts(cls, start=None, end=None): |
|
286 | r = DBSession.query(func.sum((cls.amount / (1-cls.discount)) - cls.amount).label('d'))\ |
|
287 | .join(event.Event)\ |
|
288 | .filter(cls.discount > 0)\ |
|
289 | .filter(event.Event.deleted==False) |
|
290 | ||
291 | if start: |
|
292 | r = r.filter(event.Event.timestamp>=start) |
|
@@ 262-274 (lines=13) @@ | ||
259 | r = DBSession.query(cls).join(event.Event)\ |
|
260 | .filter(event.Event.deleted==False) |
|
261 | ||
262 | if start: |
|
263 | r = r.filter(event.Event.timestamp>=start) |
|
264 | if end: |
|
265 | r = r.filter(event.Event.timestamp<end) |
|
266 | ||
267 | if distinct_on is None: |
|
268 | raise NotImplementedError("required argument distinct_on missing") |
|
269 | ||
270 | r = r.distinct(distinct_on) |
|
271 | ||
272 | return r.count() |
|
273 | ||
274 | @classmethod |
|
275 | @datefilter_one_or_zero(label='a') |
|
276 | def total(cls): |
|
277 | r = DBSession.query(func.sum(cls.amount).label('a'))\ |