python bindings - absolute beginner's questions
Sampsa Riikonen
sampsa.lists at gmail.com
Sun Jan 1 10:46:57 EST 2012
Dear List,
I am a gnucash beginner, while at the same time, somewat experienced
python user.
First of all, I think that a serious accounting program with a
programmable python interface is
a superb idea..!
.. so right know I am working my way through the python classes and
methods in order
to create a simple report which shows transactions of all the accounts,
grouped by account, say:
--------------
account name
date, transaction description, other account involved in
transaction, amount
...
account name
...
...
------------
This is how far I have been able to go for the moment with the aid of
the example scripts and using the
python "dir" clause.
--------------------
from gnucash import *
# opening a session..
ses=Session("rapkotest.gnucash",ignore_lock=True)
root=ses.book.get_root_account()
# getting an account object..
test=root.lookup_by_code("30.2.2")
# .. or one may get an account object from the hierarchy as follows..
test=root.get_children()
test=Account(instance=test[0])
# accessing data of the account..
test.GetName()
test.GetBalance().to_double()
# probing transactions:
trans=test.GetSplitList()[0] # "split" object
trans.GetAmount().to_double() # how much?
trans.GetCorrAccountName() # where to/from?
atrans=trans.GetOtherSplit() # "split" object in the other account
involved in the transaction
atrans.GetAccount().GetName() # name of the other account involved on
the transaction
trans.parent.GetDescription() # this gives the description of the
transaction
-------------------------
So, if I have understood something from all this, from the point of view
of an "account" object, everything that
happens on the account is a "split" object and a "transaction" object is
a collection of "splits".
Correct?
Now I could make an iteration over all splits and achieve that report I
was talking about.
Or is there another way to achieve that? In more detail, how do the methods
ForEachTransaction
TreeForEachTransaction
of the account object work?
Then another question:
If I have a hierarchy of accounts, say a main account (M) with
several sub accounts (S1..SN), is there some fancy method for account (M)
which returns the total balance of its subaccounts, i.e. the sum of balance
of accounts S1..SN.
.. or do I have to make some recursive python routine myself which does
this?
Regards,
Sampsa
More information about the gnucash-user
mailing list