misc cleanup; lot-related bug fixes; add more traces

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@6914 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 2002-05-26 04:42:08 +00:00
parent 47eaa5c35d
commit f47b53a310
8 changed files with 64 additions and 43 deletions

View File

@ -47,7 +47,7 @@
#include "gncObject.h" #include "gncObject.h"
#include "QueryObject.h" #include "QueryObject.h"
static short module = MOD_ENGINE; static short module = MOD_ACCOUNT;
/********************************************************************\ /********************************************************************\
@ -305,7 +305,8 @@ xaccFreeAccount (Account *acc)
/* any split pointing at this account needs to be unmarked */ /* any split pointing at this account needs to be unmarked */
for(lp = acc->splits; lp; lp = lp->next) for(lp = acc->splits; lp; lp = lp->next)
{ {
xaccSplitSetAccount((Split *) lp->data, NULL); Split *s = lp->data;
s->acc = NULL;
} }
acc->editlevel = 0; acc->editlevel = 0;
@ -947,6 +948,7 @@ xaccAccountInsertLot (Account *acc, GNCLot *lot)
Account * old_acc = NULL; Account * old_acc = NULL;
if (!acc || !lot) return; if (!acc || !lot) return;
ENTER ("(acc=%p, lot=%p)", acc, lot);
/* pull it out of the old account */ /* pull it out of the old account */
if (lot->account && lot->account != acc) if (lot->account && lot->account != acc)
@ -958,8 +960,13 @@ xaccAccountInsertLot (Account *acc, GNCLot *lot)
} }
xaccAccountBeginEdit(acc); xaccAccountBeginEdit(acc);
lot->account = acc;
/* Avoid inserting into list more than once */
if (lot->account != acc)
{
acc->lots = g_list_prepend (acc->lots, lot); acc->lots = g_list_prepend (acc->lots, lot);
lot->account = acc;
}
/* Move all slots over to the new account. At worst, /* Move all slots over to the new account. At worst,
* this is a no-op. */ * this is a no-op. */
@ -976,6 +983,7 @@ xaccAccountInsertLot (Account *acc, GNCLot *lot)
} }
xaccAccountCommitEdit(acc); xaccAccountCommitEdit(acc);
xaccAccountCommitEdit(old_acc); xaccAccountCommitEdit(old_acc);
LEAVE ("(acc=%p, lot=%p)", acc, lot);
} }
/********************************************************************\ /********************************************************************\
@ -988,6 +996,7 @@ xaccAccountInsertSplit (Account *acc, Split *split)
if (!acc) return; if (!acc) return;
if (!split) return; if (!split) return;
ENTER ("(acc=%p, split=%p)", acc, split);
/* check for book mix-up */ /* check for book mix-up */
g_return_if_fail (acc->book == split->book); g_return_if_fail (acc->book == split->book);
@ -1015,7 +1024,11 @@ xaccAccountInsertSplit (Account *acc, Split *split)
xaccSplitGetAccount(split) != acc) xaccSplitGetAccount(split) != acc)
xaccAccountRemoveSplit (xaccSplitGetAccount(split), split); xaccAccountRemoveSplit (xaccSplitGetAccount(split), split);
xaccSplitSetAccount (split, acc); split->acc = acc;
if (split->lot && (NULL == split->lot->account))
{
xaccAccountInsertLot (acc, split->lot);
}
if (g_list_index(acc->splits, split) == -1) if (g_list_index(acc->splits, split) == -1)
{ {
@ -1035,6 +1048,7 @@ xaccAccountInsertSplit (Account *acc, Split *split)
xaccTransCommitEdit(trans); xaccTransCommitEdit(trans);
xaccAccountCommitEdit(acc); xaccAccountCommitEdit(acc);
LEAVE ("(acc=%p, split=%p)", acc, split);
} }
/********************************************************************\ /********************************************************************\
@ -1045,6 +1059,7 @@ xaccAccountRemoveSplit (Account *acc, Split *split)
{ {
if (!acc) return; if (!acc) return;
if (!split) return; if (!split) return;
ENTER ("(acc=%p, split=%p)", acc, split);
xaccAccountBeginEdit(acc); xaccAccountBeginEdit(acc);
{ {
@ -1065,7 +1080,7 @@ xaccAccountRemoveSplit (Account *acc, Split *split)
acc->balance_dirty = TRUE; acc->balance_dirty = TRUE;
xaccTransBeginEdit (trans); xaccTransBeginEdit (trans);
xaccSplitSetAccount(split, NULL); split->acc = NULL;
if (split->lot) if (split->lot)
{ {
gnc_lot_remove_split (split->lot, split); gnc_lot_remove_split (split->lot, split);
@ -1078,6 +1093,7 @@ xaccAccountRemoveSplit (Account *acc, Split *split)
} }
} }
xaccAccountCommitEdit(acc); xaccAccountCommitEdit(acc);
LEAVE ("(acc=%p, split=%p)", acc, split);
} }
@ -1240,7 +1256,8 @@ static int revorder[NUM_ACCOUNT_TYPES] = {
int int
xaccAccountOrder (Account **aa, Account **ab) { xaccAccountOrder (Account **aa, Account **ab)
{
char *da, *db; char *da, *db;
char *endptr = NULL; char *endptr = NULL;
int ta, tb; int ta, tb;
@ -1317,7 +1334,8 @@ xaccAccountSetType (Account *acc, GNCAccountType tip)
} }
void void
xaccAccountSetName (Account *acc, const char *str) { xaccAccountSetName (Account *acc, const char *str)
{
char * tmp; char * tmp;
if ((!acc) || (!str)) return; if ((!acc) || (!str)) return;
@ -1336,7 +1354,8 @@ xaccAccountSetName (Account *acc, const char *str) {
} }
void void
xaccAccountSetCode (Account *acc, const char *str) { xaccAccountSetCode (Account *acc, const char *str)
{
char * tmp; char * tmp;
if ((!acc) || (!str)) return; if ((!acc) || (!str)) return;
@ -1354,7 +1373,8 @@ xaccAccountSetCode (Account *acc, const char *str) {
} }
void void
xaccAccountSetDescription (Account *acc, const char *str) { xaccAccountSetDescription (Account *acc, const char *str)
{
char * tmp; char * tmp;
if ((!acc) || (!str)) return; if ((!acc) || (!str)) return;
@ -1512,8 +1532,8 @@ DxaccAccountSetSecurity (Account *acc, gnc_commodity * security,
} }
void void
DxaccAccountSetCurrencySCU (Account * acc, int scu) { DxaccAccountSetCurrencySCU (Account * acc, int scu)
{
if (!acc) return; if (!acc) return;
xaccAccountBeginEdit(acc); xaccAccountBeginEdit(acc);
@ -1525,7 +1545,8 @@ DxaccAccountSetCurrencySCU (Account * acc, int scu) {
} }
int int
DxaccAccountGetCurrencySCU (Account * acc) { DxaccAccountGetCurrencySCU (Account * acc)
{
kvp_value *v; kvp_value *v;
if (!acc) return 0; if (!acc) return 0;
@ -1720,7 +1741,8 @@ DxaccAccountGetSecurity (Account *acc, GNCBook *book)
} }
gnc_numeric gnc_numeric
xaccAccountGetBalance (Account *acc) { xaccAccountGetBalance (Account *acc)
{
if (!acc) return gnc_numeric_zero(); if (!acc) return gnc_numeric_zero();
return acc->balance; return acc->balance;
} }
@ -1989,8 +2011,10 @@ xaccAccountHasAncestor (Account *account, Account * ancestor)
#define GNC_RETURN_ENUM_AS_STRING(x) case (x): return #x; #define GNC_RETURN_ENUM_AS_STRING(x) case (x): return #x;
char * char *
xaccAccountTypeEnumAsString(GNCAccountType type) { xaccAccountTypeEnumAsString(GNCAccountType type)
switch(type) { {
switch(type)
{
GNC_RETURN_ENUM_AS_STRING(NO_TYPE); GNC_RETURN_ENUM_AS_STRING(NO_TYPE);
GNC_RETURN_ENUM_AS_STRING(BANK); GNC_RETURN_ENUM_AS_STRING(BANK);
GNC_RETURN_ENUM_AS_STRING(CASH); GNC_RETURN_ENUM_AS_STRING(CASH);
@ -2022,7 +2046,8 @@ xaccAccountTypeEnumAsString(GNCAccountType type) {
if(safe_strcmp(#x, (str)) == 0) { *type = x; return(TRUE); } if(safe_strcmp(#x, (str)) == 0) { *type = x; return(TRUE); }
gboolean gboolean
xaccAccountStringToType(const char* str, GNCAccountType *type) { xaccAccountStringToType(const char* str, GNCAccountType *type)
{
GNC_RETURN_ON_MATCH(NO_TYPE); GNC_RETURN_ON_MATCH(NO_TYPE);
GNC_RETURN_ON_MATCH(BANK); GNC_RETURN_ON_MATCH(BANK);
@ -2163,6 +2188,7 @@ xaccAccountTypesCompatible (GNCAccountType parent_type,
/********************************************************************\ /********************************************************************\
\********************************************************************/ \********************************************************************/
gboolean gboolean
xaccAccountGetReconcileLastDate (Account *account, time_t *last_date) xaccAccountGetReconcileLastDate (Account *account, time_t *last_date)
{ {
@ -2209,6 +2235,7 @@ xaccAccountSetReconcileLastDate (Account *account, time_t last_date)
/********************************************************************\ /********************************************************************\
\********************************************************************/ \********************************************************************/
gboolean gboolean
xaccAccountGetReconcileLastInterval (Account *account, int *months, int *days) xaccAccountGetReconcileLastInterval (Account *account, int *months, int *days)
{ {
@ -2554,6 +2581,7 @@ xaccAccountGetQuoteTZ(Account *acc)
/********************************************************************\ /********************************************************************\
\********************************************************************/ \********************************************************************/
void void
xaccAccountSetReconcileChildrenStatus(Account *account, gboolean status) xaccAccountSetReconcileChildrenStatus(Account *account, gboolean status)
{ {
@ -2767,5 +2795,4 @@ gboolean xaccAccountRegister (void)
return gncObjectRegister (&account_object_def); return gncObjectRegister (&account_object_def);
} }
/********************************************************************\ /* ======================= END OF FILE =========================== */
\********************************************************************/

View File

@ -881,7 +881,7 @@ xaccGroupMergeAccounts (AccountGroup *grp)
gnc_engine_generate_event (&xaccSplitGetAccount(split)->guid, gnc_engine_generate_event (&xaccSplitGetAccount(split)->guid,
GNC_EVENT_MODIFY); GNC_EVENT_MODIFY);
xaccSplitSetAccount(split, NULL); split->acc = NULL;
xaccAccountInsertSplit (acc_a, split); xaccAccountInsertSplit (acc_a, split);
} }

View File

@ -81,7 +81,7 @@ gnc_book_insert_trans_clobber (GNCBook *book, Transaction *trans)
else else
{ {
/* force to null, so remove doesn't occur */ /* force to null, so remove doesn't occur */
xaccSplitSetAccount (s, NULL); s->acc = NULL;
xaccAccountInsertSplit (twin, s); xaccAccountInsertSplit (twin, s);
twin->balance_dirty = TRUE; twin->balance_dirty = TRUE;
twin->sort_dirty = TRUE; twin->sort_dirty = TRUE;
@ -141,7 +141,7 @@ gnc_book_insert_trans (GNCBook *book, Transaction *trans)
else else
{ {
/* force to null, so remove doesn't occur */ /* force to null, so remove doesn't occur */
xaccSplitSetAccount (s, NULL); s->acc = NULL;
xaccAccountInsertSplit (twin, s); xaccAccountInsertSplit (twin, s);
twin->balance_dirty = TRUE; twin->balance_dirty = TRUE;
twin->sort_dirty = TRUE; twin->sort_dirty = TRUE;

View File

@ -104,7 +104,7 @@ static void
xaccInitSplit(Split * split, GNCBook *book) xaccInitSplit(Split * split, GNCBook *book)
{ {
/* fill in some sane defaults */ /* fill in some sane defaults */
xaccSplitSetAccount(split, NULL); split->acc = NULL;
split->parent = NULL; split->parent = NULL;
split->lot = NULL; split->lot = NULL;
@ -210,7 +210,7 @@ xaccFreeSplit (Split *split)
split->value = gnc_numeric_zero(); split->value = gnc_numeric_zero();
split->parent = NULL; split->parent = NULL;
split->lot = NULL; split->lot = NULL;
xaccSplitSetAccount(split, NULL); split->acc = NULL;
split->date_reconciled.tv_sec = 0; split->date_reconciled.tv_sec = 0;
split->date_reconciled.tv_nsec = 0; split->date_reconciled.tv_nsec = 0;
@ -384,14 +384,6 @@ xaccSplitGetAccount (Split *s)
return s->acc; return s->acc;
} }
void
xaccSplitSetAccount (Split *s, Account *act)
{
if (!s) return;
s->acc = act;
}
/********************************************************************\ /********************************************************************\
\********************************************************************/ \********************************************************************/
@ -1869,7 +1861,7 @@ xaccTransRollbackEdit (Transaction *trans)
Account *account = s->acc; Account *account = s->acc;
s->parent = trans; s->parent = trans;
xaccSplitSetAccount(s, NULL); s->acc = NULL;
xaccStoreEntity(s->book->entity_table, s, &s->guid, GNC_ID_SPLIT); xaccStoreEntity(s->book->entity_table, s, &s->guid, GNC_ID_SPLIT);
xaccAccountInsertSplit (account, s); xaccAccountInsertSplit (account, s);
mark_split (s); mark_split (s);

View File

@ -211,13 +211,6 @@ void xaccTransSetGUID (Transaction *trans, const GUID *guid);
* call this on an existing split! */ * call this on an existing split! */
void xaccSplitSetGUID (Split *split, const GUID *guid); void xaccSplitSetGUID (Split *split, const GUID *guid);
/* Set the value of the splits account pointer. These are 'dangerous'
* routines, because they fail to actually remove the split from
* its old parent account, or insert it into its new parent account.
* Using these incorrectly is guarenteed to scramble your data
* or even lead to bizarre crashes and hangs! Achtung! */
void xaccSplitSetAccount(Split *s, Account *act);
/* The xaccFreeSplit() method simply frees all memory associated /* The xaccFreeSplit() method simply frees all memory associated
* with the split. It does not verify that the split isn't * with the split. It does not verify that the split isn't
* referenced in some account. If the split is referenced by an * referenced in some account. If the split is referenced by an

View File

@ -65,6 +65,8 @@ static gncLogLevel loglevel[MOD_LAST + 1] =
GNC_LOG_DEBUG, /* SX */ GNC_LOG_DEBUG, /* SX */
GNC_LOG_WARNING, /* BOOK */ GNC_LOG_WARNING, /* BOOK */
GNC_LOG_TRACE, /* TEST */ GNC_LOG_TRACE, /* TEST */
GNC_LOG_DEBUG, /* LOT */
GNC_LOG_WARNING, /* ACCOUNT */
}; };
static FILE *fout = NULL; static FILE *fout = NULL;

View File

@ -1,7 +1,7 @@
/********************************************************************\ /********************************************************************\
* gnc-engine-util.h -- GnuCash engine utility functions * * gnc-engine-util.h -- GnuCash engine utility functions *
* Copyright (C) 1997 Robin D. Clark * * Copyright (C) 1997 Robin D. Clark *
* Copyright (C) 1998-2001 Linas Vepstas <linas@linas.org> * * Copyright (C) 1998-2002 Linas Vepstas <linas@linas.org> *
* * * *
* This program is free software; you can redistribute it and/or * * This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as * * modify it under the terms of the GNU General Public License as *
@ -63,7 +63,9 @@ typedef enum
MOD_SX = 16, MOD_SX = 16,
MOD_BOOK = 17, MOD_BOOK = 17,
MOD_TEST = 18, MOD_TEST = 18,
MOD_LAST = 18 MOD_LOT = 19,
MOD_ACCOUNT = 20,
MOD_LAST = 20
} gncModuleType; } gncModuleType;
typedef enum typedef enum

View File

@ -44,13 +44,14 @@
#include "TransactionP.h" #include "TransactionP.h"
/* This static indicates the debugging module that this .o belongs to. */ /* This static indicates the debugging module that this .o belongs to. */
static short module = MOD_ENGINE; static short module = MOD_LOT;
/* ============================================================= */ /* ============================================================= */
static void static void
gnc_lot_init (GNCLot *lot, GNCBook *book) gnc_lot_init (GNCLot *lot, GNCBook *book)
{ {
ENTER ("(lot=%p, book=%p)", lot, book);
lot->kvp_data = NULL; lot->kvp_data = NULL;
lot->account = NULL; lot->account = NULL;
lot->splits = NULL; lot->splits = NULL;
@ -59,6 +60,7 @@ gnc_lot_init (GNCLot *lot, GNCBook *book)
lot->book = book; lot->book = book;
xaccGUIDNew (&lot->guid, book); xaccGUIDNew (&lot->guid, book);
xaccStoreEntity (book->entity_table, lot, &lot->guid, GNC_ID_LOT); xaccStoreEntity (book->entity_table, lot, &lot->guid, GNC_ID_LOT);
LEAVE ("(lot=%p, book=%p)", lot, book);
} }
GNCLot * GNCLot *
@ -78,6 +80,7 @@ gnc_lot_destroy (GNCLot *lot)
GList *node; GList *node;
if (!lot) return; if (!lot) return;
ENTER ("(lot=%p)", lot);
gnc_engine_generate_event (&lot->guid, GNC_EVENT_DESTROY); gnc_engine_generate_event (&lot->guid, GNC_EVENT_DESTROY);
xaccRemoveEntity (lot->book->entity_table, &lot->guid); xaccRemoveEntity (lot->book->entity_table, &lot->guid);
@ -203,6 +206,7 @@ gnc_lot_add_split (GNCLot *lot, Split *split)
Account * acc; Account * acc;
if (!lot || !split) return; if (!lot || !split) return;
ENTER ("(lot=%p, split=%p)", lot, split);
acc = xaccSplitGetAccount (split); acc = xaccSplitGetAccount (split);
if (NULL == lot->account) if (NULL == lot->account)
{ {
@ -231,6 +235,7 @@ gnc_lot_remove_split (GNCLot *lot, Split *split)
{ {
if (!lot || !split) return; if (!lot || !split) return;
ENTER ("(lot=%p, split=%p)", lot, split);
lot->splits = g_list_remove (lot->splits, split); lot->splits = g_list_remove (lot->splits, split);
split->lot = NULL; split->lot = NULL;