From 71898ceca7457686a4fd362e1a181fd669d9dfd8 Mon Sep 17 00:00:00 2001 From: tanshu Date: Sat, 24 Dec 2016 17:40:42 +0530 Subject: [PATCH] Feature: In journal, balances are only shown for Accounts which appear in the Balance Sheet --- brewman/views/account.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/brewman/views/account.py b/brewman/views/account.py index 6dedea48..b381b468 100644 --- a/brewman/views/account.py +++ b/brewman/views/account.py @@ -69,16 +69,20 @@ def show_balance(request): date = request.GET.get('d', None) date = None if date is None or date == '' else datetime.datetime.strptime(date, '%d-%b-%Y') id = uuid.UUID(request.matchdict['id']) - return {'Date': balance(id, date, request), 'Total': balance(id, None, request)} + return {'Date': balance(id, date, request.dbsession), 'Total': balance(id, None, request.dbsession)} -def balance(ledger_id, date, request): - bal = request.dbsession.query(func.sum(Journal.amount * Journal.debit)).join(Journal.voucher) +def balance(id_, date, dbsession): + account = dbsession.query(Ledger).filter(Ledger.id == id_).first() + if not account.type_object.balance_sheet: + return 0 + + bal = dbsession.query(func.sum(Journal.amount * Journal.debit)).join(Journal.voucher) if date is not None: bal = bal.filter(Voucher.date <= date) bal = bal.filter(Voucher.type != VoucherType.by_name('Issue').id) \ - .filter(Journal.ledger_id == ledger_id) \ + .filter(Journal.ledger_id == id_) \ .scalar() return 0 if bal is None else bal