Feature: In journal, balances are only shown for Accounts which appear in the Balance Sheet
This commit is contained in:
parent
0ff8397a4c
commit
71898ceca7
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user