wes weston schrieb: > Why have transactions not associated with accounts? > All transactions are related to an account; have > a self.TransActList in Account.
> You have "amount" in both Withdrawl and Deposit > both derived from Transaction. If Transactions always > have an amount, why not put amount in the transactions > class?
That's a good idea. I don't know if Igorati is just doing an exercise or has the ambition to create a usable application. In the latter case it would be a good idea to learn the basics of double accounting (DA). In DA each transaction is associated with 2 accounts.
DA tries to avoid signed numbers, but uses the terms debit and credit instead. debit and credit aren't simply synonyms for minus and plus because there are two types of accounts: assets and liabilities. Liabilities have a minus sign built in.
For me this is crazy and I used to confuse things until I found three rules to memorize this:
1. Positive flow of money is always recorded on the debit side. 2. Assets account balances are computed without sign change. 3. Liability account balances are computed with sign change.
In matrix form:
debit credit assets accont + - liabil account - +
Example: You empty your piggybank to pay your debts:
Amount is recorded on the debit side of debts and on the credit side of piggybank (rule 1). Both balances are lower, because credit is negative for assets (rule 2) and debit is negative for liabilities (rule 3).
So the easiest way to handle this programmatically is to have two lists, accounts and transactions. Each transaction generates a new entry in the list of transactions:
translist.append(trans(credit_account, debit_account, amount))
where amount is always positive. The account class has a balance method:
class account: def balance(self, translist): bal = 0 for e in translist: if self == e.debit_account: bal += e.amount if self == e.credit_account: bal -= e.amount
if self.acctype == "liability": bal = -bal
return bal
-- ------------------------------------------------------------------- Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0 E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64') ------------------------------------------------------------------- -- http://mail.python.org/mailman/listinfo/python-list