From c8fcd36996ddc86582f985c766959e40473817d0 Mon Sep 17 00:00:00 2001 From: Dave Peticolas Date: Thu, 12 Jul 2001 06:35:01 +0000 Subject: [PATCH] 2001-07-11 Dave Peticolas * src/engine/io-gncxml-v2.c: same as below * src/engine/io-gncbin-r.c: same as below * src/engine/io-example-account.c: same as below * src/engine/Ledger-xml-parser-v1.c: remove autocode * src/engine/Group.[ch]: remove autocode api. This hasn't really been used in a while, and account codes are generally assigned based on account function, not just hierarchy position. * src/engine/Account.[ch]: remove autocode api * src/guile/gnc.gwp: remove auto code api * src/scm/commodity-utilities.scm: fix function calls git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@4944 57a11ea4-9604-0410-9ed3-97b8803252fd --- ChangeLog | 18 ++++ src/engine/Account.c | 21 ---- src/engine/Account.h | 10 -- src/engine/Group.c | 154 ------------------------------ src/engine/Group.h | 26 ----- src/engine/Ledger-xml-parser-v1.c | 3 - src/engine/io-example-account.c | 1 - src/engine/io-gncbin-r.c | 3 - src/engine/io-gncxml-v2.c | 3 - src/scm/commodity-utilities.scm | 8 +- 10 files changed, 22 insertions(+), 225 deletions(-) diff --git a/ChangeLog b/ChangeLog index 19b3e6513e..b6d32ea53a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,23 @@ 2001-07-11 Dave Peticolas + * src/engine/io-gncxml-v2.c: same as below + + * src/engine/io-gncbin-r.c: same as below + + * src/engine/io-example-account.c: same as below + + * src/engine/Ledger-xml-parser-v1.c: remove autocode + + * src/engine/Group.[ch]: remove autocode api. This hasn't + really been used in a while, and account codes are generally + assigned based on account function, not just hierarchy position. + + * src/engine/Account.[ch]: remove autocode api + + * src/guile/gnc.gwp: remove auto code api + + * src/scm/commodity-utilities.scm: fix function calls + * src/test/test-xml-transaction.c: CIT (currency-in-transaction) * src/test/test-xml-account.c: CIT diff --git a/src/engine/Account.c b/src/engine/Account.c index 94a0254623..04a428a21a 100644 --- a/src/engine/Account.c +++ b/src/engine/Account.c @@ -911,27 +911,6 @@ xaccAccountOrder (Account **aa, Account **ab) { return 0; } -/********************************************************************\ -\********************************************************************/ -/* account codes will be assigned base-36, with three digits */ - -#define BASE 36 - -void -xaccAccountAutoCode (Account *acc, int digits) { - if (!acc) return; - if (acc->accountCode) return; /* no-op if code already assinged */ - if (!(acc->parent)) return; - - xaccAccountBeginEdit(acc); - { - acc->accountCode = xaccGroupGetNextFreeCode (acc->parent, digits); - acc->parent->saved = FALSE; - acc->core_dirty = TRUE; - } - xaccAccountCommitEdit(acc); -} - /********************************************************************\ \********************************************************************/ diff --git a/src/engine/Account.h b/src/engine/Account.h index 1428c420a6..66885964a7 100644 --- a/src/engine/Account.h +++ b/src/engine/Account.h @@ -177,16 +177,6 @@ void xaccTransFixSplitDateOrder (Transaction *trans); */ int xaccAccountOrder (Account **account_1, Account **account_2); -/* The xaccAccountAutoCode() method will assign an automatically - * generated account code to the account, if one does not already - * exist. Account codes will have the indicated number of digits - * in them. The numbering scheme roughly follows generally - * accepted accounting practice, in that top-level accounts - * will be number 100, 200, etc., second level accounts 110, 120, - * .. 210, 220, ...etc. and third level accounts 111, 112, .. etc. - */ -void xaccAccountAutoCode (Account *account, int digits); - void xaccAccountSetType (Account *account, int); void xaccAccountSetName (Account *account, const char *name); void xaccAccountSetCode (Account *account, const char *code); diff --git a/src/engine/Group.c b/src/engine/Group.c index fee7bc6576..b170e13ec7 100644 --- a/src/engine/Group.c +++ b/src/engine/Group.c @@ -651,160 +651,6 @@ xaccGroupInsertAccount (AccountGroup *grp, Account *acc) gnc_engine_generate_event (&acc->guid, GNC_EVENT_MODIFY); } -/********************************************************************\ -\********************************************************************/ -/* account codes will be assigned base-36, with three digits */ - -#define BASE 36 - -char * -xaccGroupGetNextFreeCode (AccountGroup *grp, int digits) -{ - GList *node; - Account *acc; - int maxcode = 0; - int i; - - if (!grp) return NULL; - - /* count levels to top */ - acc = grp->parent; - while (acc) - { - digits --; - assert (acc->parent); - acc = acc->parent->parent; - } - - /* if (0>digits) we could insert a decimal place, but I am too lazy - * to write this code. It doesn't seem important at the moment ... */ - - /* find the largest used code */ - acc = grp->parent; - if (acc && acc->accountCode) - maxcode = strtol (acc->accountCode, NULL, BASE); - - for (node = grp->accounts; node; node = node->next) - { - Account *account = node->data; - - if (account->accountCode) - { - int code = strtol (account->accountCode, NULL, BASE); - if (code > maxcode) maxcode = code; - } - } - - /* right-shift */ - for (i = 1; i < digits; i++) - maxcode /= BASE; - - maxcode++; - - /* left-shift */ - for (i = 1; i < digits; i++) - maxcode *= BASE; - - /* print */ - return ultostr ((unsigned long) maxcode, BASE); -} - -/********************************************************************\ -\********************************************************************/ -/* almost identical code to above, but altered to deal with - * specified account */ - -char * -xaccAccountGetNextChildCode (Account *parent_acc, int digits) -{ - GList *node; - Account *acc; - int maxcode = 0; - AccountGroup *grp; - int i; - - if (!parent_acc) return NULL; - - /* count levels to top */ - acc = parent_acc; - while (acc) - { - digits --; - assert (acc->parent); /* all acounts must be in a group */ - acc = acc->parent->parent; - } - - /* if (0>digits) we could insert a decimal place, but I am too lazy - * to write this code. It doesn't seem important at the moment ... */ - - /* find the largest used code */ - acc = parent_acc; - if (acc && acc->accountCode) - maxcode = strtol (acc->accountCode, NULL, BASE); - - grp = parent_acc->children; - if (grp) - { - for (node = grp->accounts; node; node = node->next) - { - Account *account = node->data; - - if (account->accountCode) - { - int code = strtol (account->accountCode, NULL, BASE); - if (code > maxcode) maxcode = code; - } - } - } - - /* right-shift */ - for (i = 1; i < digits; i++) - maxcode /= BASE; - - maxcode++; - - /* left-shift */ - for (i = 1; i < digits; i++) - maxcode *= BASE; - - /* print */ - return ultostr ((unsigned long) maxcode, BASE); -} - -/********************************************************************\ -\********************************************************************/ - -void -xaccGroupDepthAutoCode (AccountGroup *grp) -{ - int depth; - - if (!grp) return; - - /* get the depth */ - depth = xaccGroupGetDepth (grp); - - if (depth < 3) depth = 3; - - xaccGroupAutoCode (grp, depth); -} - -void -xaccGroupAutoCode (AccountGroup *grp, int depth) -{ - GList *node; - - if (!grp || (depth < 0)) return; - - for (node = grp->accounts; node; node = node->next) - { - Account *account = node->data; - - xaccAccountAutoCode (account, depth); - xaccGroupAutoCode (account->children, depth); - } -} - /********************************************************************\ \********************************************************************/ diff --git a/src/engine/Group.h b/src/engine/Group.h index d232632a17..5026f58643 100644 --- a/src/engine/Group.h +++ b/src/engine/Group.h @@ -164,32 +164,6 @@ AccountGroup * xaccGetAccountRoot (Account *account); */ Account * xaccGroupGetParentAccount (AccountGroup *group); -/* - * The xaccGroupGetNextFreeCode() method will try to guess a reasonable - * candidate for the next unused account code in this group. - * The returned string is malloced, you must free the returned - * pointer when done. - * - * The xaccAccountGetNextChildCode() method does same as above, - * except that it returns a value appropriate for a child account. - * The returned string is malloced, you must free the returned - * pointer when done. - * - * The xaccGroupAutoCode() method will traverse the group, automatically - * inserting account codes into those accounts whose account codes - * are blank. It uses the algorithm used in xaccAccountAutoCode() - * to pick an account code. - * - * The xaccGroupDepthAutoCode() first measures the depth of the account - * tree, and uses that depth to pick the number of digits in the account - * code. - */ - -char * xaccGroupGetNextFreeCode (AccountGroup *grp, int num_digits); -char * xaccAccountGetNextChildCode (Account *acc, int num_digits); -void xaccGroupAutoCode (AccountGroup *grp, int num_digits); -void xaccGroupDepthAutoCode (AccountGroup *grp); - /* if the function returns null for a given item, it won't show up in the result list */ GSList *xaccGroupMapAccounts(AccountGroup *grp, diff --git a/src/engine/Ledger-xml-parser-v1.c b/src/engine/Ledger-xml-parser-v1.c index 59f84e411f..5cf9e16870 100644 --- a/src/engine/Ledger-xml-parser-v1.c +++ b/src/engine/Ledger-xml-parser-v1.c @@ -127,9 +127,6 @@ ledger_data_end_handler(gpointer data_for_children, */ xaccGroupMarkSaved (ag); - /* auto-number the accounts, if they are not already numbered */ - xaccGroupDepthAutoCode (ag); - /* commit all groups, this completes the BeginEdit started when the * account_end_handler finished reading the account. */ diff --git a/src/engine/io-example-account.c b/src/engine/io-example-account.c index 4b400d8bc8..7a0e2ff122 100644 --- a/src/engine/io-example-account.c +++ b/src/engine/io-example-account.c @@ -301,7 +301,6 @@ gnc_read_example_account(const gchar *filename) } xaccGroupMarkSaved(gea->group); - xaccGroupDepthAutoCode(gea->group); xaccAccountGroupCommitEdit(gea->group); return gea; diff --git a/src/engine/io-gncbin-r.c b/src/engine/io-gncbin-r.c index 03302c551a..6924ce8231 100644 --- a/src/engine/io-gncbin-r.c +++ b/src/engine/io-gncbin-r.c @@ -465,9 +465,6 @@ gnc_load_financials_from_fd(GNCBook *book, int fd) holder = xaccMallocAccountGroup(); grp = readGroup (fd, NULL, token); - /* auto-number the accounts, if they are not already numbered */ - xaccGroupDepthAutoCode (grp); - /* the number of unclaimed accounts should be zero if the * read succeeded. But just in case of a very unlikely * error, try to continue anyway. */ diff --git a/src/engine/io-gncxml-v2.c b/src/engine/io-gncxml-v2.c index 860718565b..e34a6881fb 100644 --- a/src/engine/io-gncxml-v2.c +++ b/src/engine/io-gncxml-v2.c @@ -453,9 +453,6 @@ gnc_book_load_from_xml_file_v2( /* also mark the pricedb as saved for the same reasons */ gnc_pricedb_mark_clean (gnc_book_get_pricedb (book)); - /* auto-number the accounts, if they are not already numbered */ - xaccGroupDepthAutoCode (gnc_book_get_group(book)); - /* Fix account and transaction commodities */ xaccGroupScrubCommodities (gnc_book_get_group(book)); diff --git a/src/scm/commodity-utilities.scm b/src/scm/commodity-utilities.scm index c252329bb8..7fc0b20a25 100644 --- a/src/scm/commodity-utilities.scm +++ b/src/scm/commodity-utilities.scm @@ -59,7 +59,7 @@ ;; which have two *different* commodities ;; involved. (lambda (s) (let ((trans-comm - (gnc:transaction-get-commodity + (gnc:transaction-get-currency (gnc:split-get-parent s))) (acc-comm (gnc:account-get-commodity @@ -127,7 +127,7 @@ (total-domestic (gnc:numeric-zero))) (map-in-order (lambda (a) - (let* ((transaction-comm (gnc:transaction-get-commodity + (let* ((transaction-comm (gnc:transaction-get-currency (gnc:split-get-parent a))) (account-comm (gnc:account-get-commodity (gnc:split-get-account a))) @@ -224,7 +224,7 @@ ;; go through all splits; convert all splits into a price. (map-in-order (lambda (a) - (let* ((transaction-comm (gnc:transaction-get-commodity + (let* ((transaction-comm (gnc:transaction-get-currency (gnc:split-get-parent a))) (account-comm (gnc:account-get-commodity (gnc:split-get-account a))) @@ -491,7 +491,7 @@ ;; and share-amounts (for-each (lambda (a) - (let* ((transaction-comm (gnc:transaction-get-commodity + (let* ((transaction-comm (gnc:transaction-get-currency (gnc:split-get-parent a))) (account-comm (gnc:account-get-commodity (gnc:split-get-account a)))