def _getBalancesForDate(self, date):
     """ Compute the total, debit and credit balances for a given
         date
     """
     if date is None: date = DateTime()
     currency = self.context.getAccountingCurrency()
     total = debit = credit = Money('0.00', currency)
     for account in self.context.objectValues():
         if IAccount.providedBy(account):
             balance = account.getBalanceForDate(date)
             total += balance
             if balance > 0:
                 debit += balance
             if balance < 0:
                 credit += -balance
     return total, debit, credit
    def test_create(self):
        portal = self.getPortal()

        id = 'upfrontbooks'
        books = portal._getOb(id)

        ledger = getattr(books, 'ledger')
        accounts = getattr(ledger, 'accounts')
        self.failUnless(isinstance(accounts, AccountFolder))

        path = accounts.getPhysicalPath() + ('listaccountsview',)

        accounts_view = books.restrictedTraverse(path)

        # test filter_date
        self.failUnless(DateTime().earliestTime() == 
                        accounts_view.filter_date().earliestTime())

        # test accounts
        accounts_list = accounts_view.accounts()

        self.failUnless(len(accounts_list) > 0)
        self.failUnless(IAccount.providedBy(accounts_list[0]['obj']))