why not account-get-transactions and simpler cash-flow test for already seen split?
Derek Atkins
warlord at MIT.EDU
Fri Jul 7 12:08:59 EDT 2006
Hi,
This really belongs on the -devel list, as this is a development
question, not a user question.... I've cross posted there, but
please only follow-up to -devel
Larry Evans <cppljevans at cox-internet.com> writes:
[snip]
> both seem to have similar code for processing a set of accounts and
> their transactions. In pseudo-code, this idiom is:
>
> for-each account in set-of-accounts
> for-each account-split in account
> transaction = parent-of account-split
> for-each transaction-split in transaction
> if(transaction-split != account-split)
> do-something with transaction-split
>
> Now the function and variable names in actual code and pseudo code are:
>
> pseudo actual
> ------ ------
> parent-of gnc:split-get-parent
> account-split split
> transaction-split s
> transaction parent
>
> and the if test in actual code is:
>
> advanced-portfolio:
>
> same-split? s split
>
> cash-flow:
>
> split-in-list? s seen-split-list
>
> where: seen-split-list is a list of splits which is appended to
> for each time the test fails.
>
> Could the advanced-portfolio test couldn't be used in place of the
> cash-flow test, and thereby, save some time?
Maybe.. Maybe not. It also depends a lot on what's done in the 'yes'
and 'no' states of the test. I'd have to look, which I haven't yet,
to refresh my memory on what exactly is being done.
> Also, could someone explain why there couldn't just be a function:
>
> gnc:account-get-transactions
>
> which could be used to get the list of transaction in an account instead
> of getting the splits with gnc:account-get-split-list?
The account keeps a list of splits, not a list of transactions. Keep
in mind that it's perfectly legal to have a multi-split transaction
where more that one split is in a single account. So, in the
split-list you'd see two entries for that one transaction -- one for
each split in that account. So if you created a
gnc:account-get-transactions it would still need to use
gnc:account-get-splits and then walk the list and then keep track of
which transactions have already been seen so you only get transactions
once.... That's pretty expensive, don't you think?
> It seems from
> looking at the code that the parent is actually a transaction because
> there's this code:
>
> gnc:transaction-get-splits parent
Yes, the data model is effectively:
Account:
split-list
Transaction:
split-list
Split:
parent -> Transaction
account -> Account
> TIA.
-derek
--
Derek Atkins, SB '93 MIT EE, SM '95 MIT Media Laboratory
Member, MIT Student Information Processing Board (SIPB)
URL: http://web.mit.edu/warlord/ PP-ASEL-IA N1NWH
warlord at MIT.EDU PGP key available
More information about the gnucash-user
mailing list