mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Remove all traces of the AccountGroup data structure. Accounts now
point directly to their parent and have a simple GList of children. (The old method was alternating data structures in the form Account, AccountGroup, Account, AccountGroup, etc.) git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@15647 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
@@ -61,8 +61,7 @@ http://code.neil.williamsleesmill.me.uk/qsf.html
|
||||
QSF itself is now being built into the QOF library for use with pilot-link to allow
|
||||
Palm objects to be described in QOF, written to XML as QSF and imported directly into
|
||||
GnuCash and other QOF-compliant applications. As a generic format, it does not depend
|
||||
on any pre-defined objects - as the current GnuCash XML format depends on AccountGroup.
|
||||
Instead, QSF is a simple container for all QOF objects.
|
||||
on any pre-defined objects. Instead, QSF is a simple container for all QOF objects.
|
||||
|
||||
QSF grew from the qof_book_merge code base and uses the qof_book_merge code that is now
|
||||
part of QOF. Any QofBook generated by QSF still needs to be merged into the existing
|
||||
|
||||
@@ -74,9 +74,6 @@ struct QofInstance_s
|
||||
gboolean infant;
|
||||
};
|
||||
|
||||
/* reset the dirty flag */
|
||||
void qof_instance_mark_clean (QofInstance *);
|
||||
|
||||
void qof_instance_set_slots (QofInstance *, KvpFrame *);
|
||||
|
||||
/* Set the last_update time. Reserved for use by the SQL backend;
|
||||
|
||||
@@ -92,6 +92,9 @@ Sets this instance AND the collection as dirty.
|
||||
*/
|
||||
void qof_instance_set_dirty(QofInstance* inst);
|
||||
|
||||
/* reset the dirty flag */
|
||||
void qof_instance_mark_clean (QofInstance *);
|
||||
|
||||
gboolean qof_instance_check_edit(const QofInstance *inst);
|
||||
|
||||
gboolean qof_instance_do_free(const QofInstance *inst);
|
||||
|
||||
@@ -229,7 +229,7 @@ gboolean qof_session_save_may_clobber_data (QofSession *session);
|
||||
|
||||
/** The qof_session_save() method will commit all changes that have been
|
||||
* made to the session. For the file backend, this is nothing
|
||||
* more than a write to the file of the current AccountGroup & etc.
|
||||
* more than a write to the file of the current Accounts & etc.
|
||||
* For the SQL backend, this is typically a no-op (since all data
|
||||
* has already been written out to the database.
|
||||
*/
|
||||
|
||||
@@ -23,7 +23,7 @@ typedef void (*GNCOptionChangeCallback) (gpointer user_data);
|
||||
typedef int GNCOptionDBHandle;
|
||||
|
||||
QofBook * gnc_get_current_book (void);
|
||||
AccountGroup * gnc_get_current_group (void);
|
||||
Account * gnc_get_current_root_account (void);
|
||||
|
||||
char * gnc_gettext_helper(const char *string);
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#include <glib.h>
|
||||
#include "gnc-account-merge.h"
|
||||
#include "Account.h"
|
||||
#include "Group.h"
|
||||
|
||||
GncAccountMergeDisposition
|
||||
determine_account_merge_disposition(Account *existing_acct, Account *new_acct)
|
||||
@@ -17,50 +16,48 @@ determine_account_merge_disposition(Account *existing_acct, Account *new_acct)
|
||||
}
|
||||
|
||||
GncAccountMergeDisposition
|
||||
determine_merge_disposition(AccountGroup *existing_root, Account *new_acct)
|
||||
determine_merge_disposition(Account *existing_root, Account *new_acct)
|
||||
{
|
||||
Account *existing_acct;
|
||||
gchar *full_name;
|
||||
|
||||
full_name = xaccAccountGetFullName(new_acct);
|
||||
existing_acct = xaccGetAccountFromFullName(existing_root, full_name);
|
||||
existing_acct = gnc_account_lookup_by_full_name(existing_root, full_name);
|
||||
g_free(full_name);
|
||||
|
||||
return determine_account_merge_disposition(existing_acct, new_acct);
|
||||
}
|
||||
|
||||
void
|
||||
account_group_merge(AccountGroup *existing_grp, AccountGroup *new_grp)
|
||||
account_trees_merge(Account *existing_root, Account *new_accts_root)
|
||||
{
|
||||
GList *accounts_copy;
|
||||
AccountList *accounts;
|
||||
g_return_if_fail(new_grp != NULL);
|
||||
g_return_if_fail(existing_grp != NULL);
|
||||
GList *accounts, *node;
|
||||
g_return_if_fail(new_accts_root != NULL);
|
||||
g_return_if_fail(existing_root != NULL);
|
||||
|
||||
/* since we're have a chance of mutating the list (via
|
||||
* xaccGroupInsertAccount) while we're iterating over it, iterate over a
|
||||
* copy. */
|
||||
accounts_copy = g_list_copy(xaccGroupGetAccountList(new_grp));
|
||||
for (accounts = accounts_copy; accounts; accounts = accounts->next)
|
||||
* gnc_account_add_child) while we're iterating over it, iterate
|
||||
* over a copy. */
|
||||
accounts = gnc_account_get_children(new_accts_root);
|
||||
for (node = accounts; node; node = g_list_next(node))
|
||||
{
|
||||
Account *existing_named, *new_acct;
|
||||
const char *name;
|
||||
|
||||
new_acct = (Account*)accounts->data;
|
||||
new_acct = (Account*)node->data;
|
||||
name = xaccAccountGetName(new_acct);
|
||||
existing_named = xaccGetAccountFromName(existing_grp, name);
|
||||
existing_named = gnc_account_lookup_by_name(existing_root, name);
|
||||
switch (determine_account_merge_disposition(existing_named, new_acct))
|
||||
{
|
||||
case GNC_ACCOUNT_MERGE_DISPOSITION_USE_EXISTING:
|
||||
/* recurse */
|
||||
account_group_merge(xaccAccountGetChildren(existing_named),
|
||||
xaccAccountGetChildren(new_acct));
|
||||
account_trees_merge(existing_named, new_acct);
|
||||
break;
|
||||
case GNC_ACCOUNT_MERGE_DISPOSITION_CREATE_NEW:
|
||||
/* merge this one in. */
|
||||
xaccGroupInsertAccount(existing_grp, new_acct);
|
||||
gnc_account_append_child(existing_root, new_acct);
|
||||
break;
|
||||
}
|
||||
}
|
||||
g_list_free(accounts_copy);
|
||||
g_list_free(accounts);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#define GNC_ACCOUNT_MERGE_H
|
||||
|
||||
#include "Account.h"
|
||||
#include "Group.h"
|
||||
|
||||
typedef enum {
|
||||
GNC_ACCOUNT_MERGE_DISPOSITION_USE_EXISTING,
|
||||
@@ -18,8 +17,8 @@ typedef struct _merge_error {
|
||||
} GncAccountMergeError;
|
||||
|
||||
GncAccountMergeDisposition determine_account_merge_disposition(Account *existing_acct, Account *new_acct);
|
||||
GncAccountMergeDisposition determine_merge_disposition(AccountGroup *existing_root, Account *new_acct);
|
||||
GncAccountMergeDisposition determine_merge_disposition(Account *existing_root, Account *new_acct);
|
||||
|
||||
void account_group_merge(AccountGroup *existing_grp, AccountGroup *new_grp);
|
||||
void account_trees_merge(Account *existing_root, Account *new_accts_root);
|
||||
|
||||
#endif /* GNC_ACCOUNT_MERGE_H */
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "Group.h"
|
||||
#include "gnc-component-manager.h"
|
||||
#include "qof.h"
|
||||
#include "gnc-ui-util.h"
|
||||
|
||||
@@ -233,14 +233,13 @@ _get_vars_helper(Transaction *txn, void *var_hash_data)
|
||||
Account*
|
||||
gnc_sx_get_template_transaction_account(SchedXaction *sx)
|
||||
{
|
||||
AccountGroup *template_group;
|
||||
Account *sx_template_acct;
|
||||
Account *template_root, *sx_template_acct;
|
||||
const char *sx_guid_str;
|
||||
|
||||
template_group = gnc_book_get_template_group(gnc_get_current_book());
|
||||
template_root = gnc_book_get_template_root(gnc_get_current_book());
|
||||
sx_guid_str = guid_to_string(xaccSchedXactionGetGUID(sx));
|
||||
/* Get account named after guid string. */
|
||||
sx_template_acct = xaccGetAccountFromName(template_group, sx_guid_str);
|
||||
sx_template_acct = gnc_account_lookup_by_name(template_root, sx_guid_str);
|
||||
return sx_template_acct;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,6 @@
|
||||
#include "gnc-hooks.h"
|
||||
#include "gnc-module.h"
|
||||
#include "gnc-ui-util.h"
|
||||
#include "Group.h"
|
||||
#include "Transaction.h"
|
||||
#include "guile-mappings.h"
|
||||
#include "gnc-session.h"
|
||||
@@ -201,10 +200,10 @@ gnc_get_current_book (void)
|
||||
return qof_session_get_book (gnc_get_current_session ());
|
||||
}
|
||||
|
||||
AccountGroup *
|
||||
gnc_get_current_group (void)
|
||||
Account *
|
||||
gnc_get_current_root_account (void)
|
||||
{
|
||||
return gnc_book_get_group (gnc_get_current_book ());
|
||||
return gnc_book_get_root_account (gnc_get_current_book ());
|
||||
}
|
||||
|
||||
gnc_commodity_table *
|
||||
@@ -369,11 +368,9 @@ gnc_ui_account_get_balance_as_of_date (Account *account,
|
||||
|
||||
if (include_children)
|
||||
{
|
||||
AccountGroup *children_group;
|
||||
GList *children, *node;
|
||||
|
||||
children_group = xaccAccountGetChildren (account);
|
||||
children = xaccGroupGetSubAccounts (children_group);
|
||||
children = gnc_account_get_descendants(account);
|
||||
|
||||
for (node = children; node; node = node->next)
|
||||
{
|
||||
@@ -388,6 +385,8 @@ gnc_ui_account_get_balance_as_of_date (Account *account,
|
||||
child_balance, child_currency, currency);
|
||||
balance = gnc_numeric_add_fixed (balance, child_balance);
|
||||
}
|
||||
|
||||
g_list_free(children);
|
||||
}
|
||||
|
||||
/* reverse sign if needed */
|
||||
@@ -568,11 +567,11 @@ equity_base_name (GNCEquityType equity_type)
|
||||
}
|
||||
|
||||
Account *
|
||||
gnc_find_or_create_equity_account (AccountGroup *group,
|
||||
gnc_find_or_create_equity_account (QofBook *book,
|
||||
GNCEquityType equity_type,
|
||||
gnc_commodity *currency,
|
||||
QofBook *book)
|
||||
gnc_commodity *currency)
|
||||
{
|
||||
Account *root;
|
||||
Account *parent;
|
||||
Account *account;
|
||||
gboolean name_exists;
|
||||
@@ -583,11 +582,12 @@ gnc_find_or_create_equity_account (AccountGroup *group,
|
||||
g_return_val_if_fail (equity_type >= 0, NULL);
|
||||
g_return_val_if_fail (equity_type < NUM_EQUITY_TYPES, NULL);
|
||||
g_return_val_if_fail (currency != NULL, NULL);
|
||||
g_return_val_if_fail (group != NULL, NULL);
|
||||
g_return_val_if_fail (book != NULL, NULL);
|
||||
|
||||
base_name = equity_base_name (equity_type);
|
||||
|
||||
account = xaccGetAccountFromName (group, base_name);
|
||||
root = gnc_book_get_root_account(book);
|
||||
account = gnc_account_lookup_by_name(root, base_name);
|
||||
if (account && xaccAccountGetType (account) != ACCT_TYPE_EQUITY)
|
||||
account = NULL;
|
||||
|
||||
@@ -595,7 +595,7 @@ gnc_find_or_create_equity_account (AccountGroup *group,
|
||||
{
|
||||
base_name = base_name && *base_name ? _(base_name) : "";
|
||||
|
||||
account = xaccGetAccountFromName (group, base_name);
|
||||
account = gnc_account_lookup_by_name(root, base_name);
|
||||
if (account && xaccAccountGetType (account) != ACCT_TYPE_EQUITY)
|
||||
account = NULL;
|
||||
}
|
||||
@@ -608,7 +608,7 @@ gnc_find_or_create_equity_account (AccountGroup *group,
|
||||
|
||||
name = g_strconcat (base_name, " - ",
|
||||
gnc_commodity_get_mnemonic (currency), NULL);
|
||||
account = xaccGetAccountFromName (group, name);
|
||||
account = gnc_account_lookup_by_name(root, name);
|
||||
if (account && xaccAccountGetType (account) != ACCT_TYPE_EQUITY)
|
||||
account = NULL;
|
||||
|
||||
@@ -633,9 +633,10 @@ gnc_find_or_create_equity_account (AccountGroup *group,
|
||||
name = g_strdup (base_name);
|
||||
}
|
||||
|
||||
parent = xaccGetAccountFromName (group, _("Equity"));
|
||||
parent = gnc_account_lookup_by_name(root, _("Equity"));
|
||||
if (parent && xaccAccountGetType (parent) != ACCT_TYPE_EQUITY)
|
||||
parent = NULL;
|
||||
parent = root;
|
||||
g_assert(parent);
|
||||
|
||||
account = xaccMallocAccount (book);
|
||||
|
||||
@@ -645,14 +646,9 @@ gnc_find_or_create_equity_account (AccountGroup *group,
|
||||
xaccAccountSetType (account, ACCT_TYPE_EQUITY);
|
||||
xaccAccountSetCommodity (account, currency);
|
||||
|
||||
if (parent)
|
||||
{
|
||||
xaccAccountBeginEdit (parent);
|
||||
xaccAccountInsertSubAccount (parent, account);
|
||||
gnc_account_append_child (parent, account);
|
||||
xaccAccountCommitEdit (parent);
|
||||
}
|
||||
else
|
||||
xaccGroupInsertAccount (group, account);
|
||||
|
||||
xaccAccountCommitEdit (account);
|
||||
|
||||
@@ -677,10 +673,9 @@ gnc_account_create_opening_balance (Account *account,
|
||||
g_return_val_if_fail (account != NULL, FALSE);
|
||||
|
||||
equity_account =
|
||||
gnc_find_or_create_equity_account (xaccAccountGetRoot (account),
|
||||
gnc_find_or_create_equity_account (book,
|
||||
EQUITY_OPENING_BALANCE,
|
||||
xaccAccountGetCommodity (account),
|
||||
book);
|
||||
xaccAccountGetCommodity (account));
|
||||
if (!equity_account)
|
||||
return FALSE;
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@
|
||||
#include <locale.h>
|
||||
|
||||
#include "Account.h"
|
||||
#include "Group.h"
|
||||
#include "qof.h"
|
||||
|
||||
|
||||
@@ -55,7 +54,7 @@ void gnc_set_default_directory (const gchar *gconf_section,
|
||||
|
||||
/* Engine enhancements & i18n ***************************************/
|
||||
QofBook * gnc_get_current_book (void);
|
||||
AccountGroup * gnc_get_current_group (void);
|
||||
Account * gnc_get_current_root_account (void);
|
||||
gnc_commodity_table * gnc_get_current_commodities (void);
|
||||
|
||||
/*
|
||||
@@ -162,10 +161,9 @@ typedef enum
|
||||
NUM_EQUITY_TYPES
|
||||
} GNCEquityType;
|
||||
|
||||
Account * gnc_find_or_create_equity_account (AccountGroup *group,
|
||||
Account * gnc_find_or_create_equity_account (QofBook *book,
|
||||
GNCEquityType equity_type,
|
||||
gnc_commodity *currency,
|
||||
QofBook *book);
|
||||
gnc_commodity *currency);
|
||||
gboolean gnc_account_create_opening_balance (Account *account,
|
||||
gnc_numeric balance,
|
||||
time_t date,
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
#include "gnc-book.h"
|
||||
#include "qof.h"
|
||||
#include "Group.h"
|
||||
#include "Account.h"
|
||||
|
||||
|
||||
/* Helpful functions for calling functions that return
|
||||
|
||||
@@ -735,8 +735,8 @@
|
||||
this-account
|
||||
(find-first (cdr account-list))))))
|
||||
|
||||
(let* ((current-group (gnc-get-current-group))
|
||||
(account-list (xaccGroupGetSubAccountsSorted current-group)))
|
||||
(let* ((current-root (gnc-get-current-root-account))
|
||||
(account-list (gnc-account-get-descendants-sorted current-root)))
|
||||
(find-first account-list)))
|
||||
|
||||
(define (get-default)
|
||||
|
||||
@@ -44,7 +44,6 @@
|
||||
#include "sixtp-dom-parsers.h"
|
||||
#include "AccountP.h"
|
||||
#include "Account.h"
|
||||
#include "Group.h"
|
||||
|
||||
static QofLogModule log_module = GNC_MOD_IO;
|
||||
|
||||
@@ -71,12 +70,15 @@ const gchar *account_version_string = "2.0.0";
|
||||
#define act_security_scu_string "act:security-scu"
|
||||
|
||||
xmlNodePtr
|
||||
gnc_account_dom_tree_create(Account *act, gboolean exporting)
|
||||
gnc_account_dom_tree_create(Account *act,
|
||||
gboolean exporting,
|
||||
gboolean allow_incompat)
|
||||
{
|
||||
const char *str;
|
||||
kvp_frame *kf;
|
||||
xmlNodePtr ret;
|
||||
GList *n;
|
||||
Account *parent;
|
||||
|
||||
ENTER ("(account=%p)", act);
|
||||
|
||||
@@ -123,11 +125,12 @@ gnc_account_dom_tree_create(Account *act, gboolean exporting)
|
||||
}
|
||||
}
|
||||
|
||||
if(xaccAccountGetParentAccount(act))
|
||||
parent = gnc_account_get_parent(act);
|
||||
if (parent)
|
||||
{
|
||||
xmlAddChild(ret, guid_to_dom_tree(
|
||||
act_parent_string,
|
||||
xaccAccountGetGUID(xaccAccountGetParentAccount(act))));
|
||||
if (!gnc_account_is_root(parent) || allow_incompat)
|
||||
xmlAddChild(ret, guid_to_dom_tree(act_parent_string,
|
||||
xaccAccountGetGUID(parent)));
|
||||
}
|
||||
|
||||
n = xaccAccountGetLotList (act);
|
||||
@@ -323,7 +326,7 @@ account_parent_handler (xmlNodePtr node, gpointer act_pdata)
|
||||
g_return_val_if_fail(parent, FALSE);
|
||||
}
|
||||
|
||||
xaccAccountInsertSubAccount(parent, pdata->account);
|
||||
gnc_account_append_child(parent, pdata->account);
|
||||
|
||||
g_free (gid);
|
||||
|
||||
@@ -406,10 +409,11 @@ gnc_account_end_handler(gpointer data_for_children,
|
||||
gpointer *result, const gchar *tag)
|
||||
{
|
||||
int successful;
|
||||
Account *acc;
|
||||
Account *acc, *parent, *root;
|
||||
xmlNodePtr tree = (xmlNodePtr)data_for_children;
|
||||
gxpf_data *gdata = (gxpf_data*)global_data;
|
||||
QofBook *book = gdata->bookdata;
|
||||
int type;
|
||||
|
||||
successful = TRUE;
|
||||
|
||||
@@ -437,6 +441,21 @@ gnc_account_end_handler(gpointer data_for_children,
|
||||
* rebalances with #accounts rebalances at the end. A BIG win!
|
||||
*/
|
||||
xaccAccountBeginEdit(acc);
|
||||
|
||||
/* Backwards compatability. If there's no parent, see if this
|
||||
* account is of type ROOT. If not, find or create a ROOT
|
||||
* account and make that the parent. */
|
||||
parent = gnc_account_get_parent(acc);
|
||||
if (parent == NULL) {
|
||||
type = xaccAccountGetType(acc);
|
||||
if (type != ACCT_TYPE_ROOT) {
|
||||
root = gnc_book_get_root_account(book);
|
||||
if (root == NULL) {
|
||||
root = gnc_account_create_root(book);
|
||||
}
|
||||
gnc_account_append_child(root, acc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
xmlFreeNode(tree);
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "gnc-gconf-utils.h"
|
||||
#include "gnc-xml-helper.h"
|
||||
|
||||
#include "sixtp.h"
|
||||
@@ -45,7 +46,6 @@
|
||||
|
||||
#include "sixtp-dom-parsers.h"
|
||||
#include "qof.h"
|
||||
#include "Group.h"
|
||||
|
||||
/* non-static because it's used in io-gncxml-v2.c */
|
||||
const gchar *gnc_v2_book_version_string = "2.0.0";
|
||||
@@ -62,25 +62,24 @@ static QofLogModule log_module = GNC_MOD_IO;
|
||||
#ifdef IMPLEMENT_BOOK_DOM_TREES_LATER
|
||||
|
||||
static void
|
||||
append_group(xmlNodePtr parent, AccountGroup *grp)
|
||||
append_account_tree (xmlNodePtr parent,
|
||||
Account *account,
|
||||
gboolean allow_incompat)
|
||||
{
|
||||
GList *list;
|
||||
GList *node;
|
||||
GList *children, *node;
|
||||
|
||||
list = xaccGroupGetAccountList(grp);
|
||||
|
||||
for (node = list; node; node = node->next) {
|
||||
children = gnc_account_get_children(account);
|
||||
for (node = children; node; node = node->next)
|
||||
{
|
||||
xmlNodePtr accnode;
|
||||
AccountGroup *newgrp;
|
||||
Account *account;
|
||||
|
||||
accnode = gnc_account_dom_tree_create((Account*)(node->data), FALSE);
|
||||
account = node->data;
|
||||
accnode = gnc_account_dom_tree_create(account, FALSE, allow_incompat);
|
||||
xmlAddChild (parent, accnode);
|
||||
|
||||
newgrp = xaccAccountGetChildren((Account*)(node->data));
|
||||
|
||||
if (newgrp)
|
||||
append_group(accnode, newgrp);
|
||||
append_account_tree(accnode, account);
|
||||
}
|
||||
g_list_free(children);
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -101,7 +100,18 @@ traverse_txns (Transaction *txn, gpointer data)
|
||||
xmlNodePtr
|
||||
gnc_book_dom_tree_create(QofBook *book)
|
||||
{
|
||||
xmlNodePtr ret;
|
||||
xmlNodePtr ret, rootAccNode;
|
||||
gboolean allow_incompat;
|
||||
GError *err = NULL;
|
||||
|
||||
allow_incompat = gnc_gconf_get_bool("dev", "allow_file_incompatibility", &err);
|
||||
if (err != NULL)
|
||||
{
|
||||
g_warning("error getting gconf value [%s]", err->message);
|
||||
g_error_free(err);
|
||||
allow_incompat = FALSE;
|
||||
}
|
||||
g_debug("allow_incompatibility: [%s]", allow_incompat ? "true" : "false");
|
||||
|
||||
ret = xmlNewNode(NULL, BAD_CAST gnc_book_string);
|
||||
xmlSetProp(ret, BAD_CAST "version", BAD_CAST gnc_v2_book_version_string);
|
||||
@@ -125,9 +135,14 @@ gnc_book_dom_tree_create(QofBook *book)
|
||||
xmlAddChild(ret, gnc_commodity_dom_tree_create(
|
||||
gnc_book_get_commodity_table(book)));
|
||||
xmlAddChild(ret, gnc_pricedb_dom_tree_create(gnc_book_get_pricedb(book)));
|
||||
append_group(ret, gnc_book_get_group(book));
|
||||
if (allow_incompat) {
|
||||
accnode = gnc_account_dom_tree_create(account, FALSE);
|
||||
xmlAddChild (ret, rootAccNode);
|
||||
}
|
||||
append_account_tree (ret, gnc_book_get_root(book));
|
||||
|
||||
xaccGroupForEachTransaction(gnc_book_get_group(book), traverse_txns, ret);
|
||||
xaccAccountTreeForEachTransaction (gnc_book_get_root_account(book),
|
||||
traverse_txns, ret);
|
||||
|
||||
xmlAddChild(ret, gnc_freqSpec_dom_tree_create (book));
|
||||
|
||||
|
||||
@@ -42,7 +42,6 @@
|
||||
#include "sixtp-dom-parsers.h"
|
||||
#include "AccountP.h"
|
||||
#include "Account.h"
|
||||
#include "Group.h"
|
||||
|
||||
static QofLogModule log_module = GNC_MOD_IO;
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#include <glib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "Group.h"
|
||||
#include "SX-book.h"
|
||||
|
||||
#include "gnc-xml-helper.h"
|
||||
@@ -757,7 +756,7 @@ gnc_schedXaction_end_handler(gpointer data_for_children,
|
||||
/* FIXME: this should be removed somewhere near 1.8 release time. */
|
||||
if ( sx->template_acct == NULL )
|
||||
{
|
||||
AccountGroup *ag = NULL;
|
||||
Account *ra = NULL;
|
||||
const char *id = NULL;
|
||||
Account *acct = NULL;
|
||||
sixtp_gdv2 *sixdata = gdata->parsedata;
|
||||
@@ -768,17 +767,17 @@ gnc_schedXaction_end_handler(gpointer data_for_children,
|
||||
/* We're dealing with a pre-200107<near-end-of-month> rgmerk
|
||||
change re: storing template accounts. */
|
||||
/* Fix: get account with name of our GUID from the template
|
||||
accounts group. Make that our template_acct pointer. */
|
||||
accounts. Make that our template_acct pointer. */
|
||||
/* THREAD-UNSAFE */
|
||||
id = guid_to_string( xaccSchedXactionGetGUID( sx ) );
|
||||
ag = gnc_book_get_template_group(book);
|
||||
if ( ag == NULL )
|
||||
ra = gnc_book_get_template_root(book);
|
||||
if ( ra == NULL )
|
||||
{
|
||||
g_warning( "Error getting template account group from being-parsed Book." );
|
||||
g_warning( "Error getting template root account from being-parsed Book." );
|
||||
xmlFreeNode( tree );
|
||||
return FALSE;
|
||||
}
|
||||
acct = xaccGetAccountFromName(ag, id);
|
||||
acct = gnc_account_lookup_by_name( ra, id );
|
||||
if ( acct == NULL )
|
||||
{
|
||||
g_warning("no template account with name [%s]", id);
|
||||
@@ -892,9 +891,9 @@ gnc_template_transaction_end_handler(gpointer data_for_children,
|
||||
txd.accts = NULL;
|
||||
txd.transactions = NULL;
|
||||
|
||||
/* the DOM tree will have an account tree [the template group
|
||||
and account] and a list of transactions [which will be
|
||||
members of the template account].
|
||||
/* the DOM tree will have an account tree [the template
|
||||
accounts] and a list of transactions [which will be members
|
||||
of the template account].
|
||||
|
||||
we want to parse through the dom trees for each, placing
|
||||
the null-parent account in the book's template-group slot,
|
||||
|
||||
@@ -33,7 +33,8 @@
|
||||
#include "gnc-xml-helper.h"
|
||||
#include "sixtp.h"
|
||||
|
||||
xmlNodePtr gnc_account_dom_tree_create(Account *act, gboolean exporting);
|
||||
xmlNodePtr gnc_account_dom_tree_create(Account *act, gboolean exporting,
|
||||
gboolean allow_incompat);
|
||||
sixtp* gnc_account_sixtp_parser_create(void);
|
||||
|
||||
xmlNodePtr gnc_book_dom_tree_create(QofBook *book);
|
||||
|
||||
@@ -44,7 +44,6 @@
|
||||
#include "sixtp-dom-parsers.h"
|
||||
#include "sixtp-parsers.h"
|
||||
|
||||
#include "Group.h"
|
||||
#include "Scrub.h"
|
||||
#include "TransLog.h"
|
||||
|
||||
@@ -70,11 +69,11 @@ gnc_destroy_example_account(GncExampleAccount *gea)
|
||||
g_free(gea->filename);
|
||||
gea->filename = NULL;
|
||||
}
|
||||
if(gea->group != NULL)
|
||||
if(gea->root != NULL)
|
||||
{
|
||||
xaccAccountGroupBeginEdit (gea->group);
|
||||
xaccAccountGroupDestroy(gea->group);
|
||||
gea->group = NULL;
|
||||
xaccAccountBeginEdit (gea->root);
|
||||
xaccAccountDestroy(gea->root);
|
||||
gea->root = NULL;
|
||||
}
|
||||
if(gea->short_description != NULL)
|
||||
{
|
||||
@@ -86,6 +85,11 @@ gnc_destroy_example_account(GncExampleAccount *gea)
|
||||
g_free(gea->long_description);
|
||||
gea->long_description = NULL;
|
||||
}
|
||||
if(gea->book != NULL)
|
||||
{
|
||||
qof_book_destroy(gea->book);
|
||||
gea->book = NULL;
|
||||
}
|
||||
g_free(gea);
|
||||
}
|
||||
|
||||
@@ -139,9 +143,13 @@ add_account_local(GncExampleAccount *gea, Account *act)
|
||||
|
||||
xaccAccountScrubCommodity (act);
|
||||
|
||||
if (!xaccAccountGetParent(act))
|
||||
if (xaccAccountGetType(act) == ACCT_TYPE_ROOT)
|
||||
{
|
||||
xaccGroupInsertAccount(gea->group, act);
|
||||
gea->root = act;
|
||||
}
|
||||
else if (!gnc_account_get_parent(act))
|
||||
{
|
||||
gnc_account_append_child(gea->root, act);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,19 +298,18 @@ gnc_titse_sixtp_parser_create(void)
|
||||
|
||||
|
||||
GncExampleAccount*
|
||||
gnc_read_example_account(QofBook *book, const gchar *filename)
|
||||
gnc_read_example_account(const gchar *filename)
|
||||
{
|
||||
GncExampleAccount *gea;
|
||||
sixtp *top_parser;
|
||||
sixtp *main_parser;
|
||||
|
||||
g_return_val_if_fail (book != NULL, NULL);
|
||||
g_return_val_if_fail (filename != NULL, NULL);
|
||||
|
||||
gea = g_new0(GncExampleAccount, 1);
|
||||
|
||||
gea->book = book;
|
||||
gea->book = qof_book_new();
|
||||
gea->filename = g_strdup(filename);
|
||||
gea->group = xaccMallocAccountGroup(book);
|
||||
|
||||
top_parser = sixtp_new();
|
||||
main_parser = sixtp_new();
|
||||
@@ -329,16 +336,13 @@ gnc_read_example_account(QofBook *book, const gchar *filename)
|
||||
}
|
||||
|
||||
if(!gnc_xml_parse_file(top_parser, filename,
|
||||
generic_callback, gea, book))
|
||||
generic_callback, gea, gea->book))
|
||||
{
|
||||
sixtp_destroy(top_parser);
|
||||
xaccLogEnable ();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
xaccGroupMarkSaved(gea->group);
|
||||
xaccAccountGroupCommitEdit(gea->group);
|
||||
|
||||
return gea;
|
||||
}
|
||||
|
||||
@@ -372,6 +376,7 @@ gboolean
|
||||
gnc_write_example_account(GncExampleAccount *gea, const gchar *filename)
|
||||
{
|
||||
FILE *out;
|
||||
sixtp_gdv2 data = { 0 };;
|
||||
|
||||
out = g_fopen(filename, "w");
|
||||
if (out == NULL)
|
||||
@@ -390,7 +395,7 @@ gnc_write_example_account(GncExampleAccount *gea, const gchar *filename)
|
||||
|
||||
write_bool_part(out, GNC_ACCOUNT_EXCLUDEP, gea->exclude_from_select_all);
|
||||
|
||||
write_account_group(out, gea->group, NULL);
|
||||
write_account_tree(out, gea->root, &data);
|
||||
|
||||
fprintf(out, "</" GNC_ACCOUNT_STRING ">\n\n");
|
||||
|
||||
@@ -425,7 +430,7 @@ gnc_free_example_account_list(GSList *list)
|
||||
}
|
||||
|
||||
GSList*
|
||||
gnc_load_example_account_list(QofBook *book, const char *dirname)
|
||||
gnc_load_example_account_list(const char *dirname)
|
||||
{
|
||||
GSList *ret;
|
||||
GDir *dir;
|
||||
@@ -449,7 +454,7 @@ gnc_load_example_account_list(QofBook *book, const char *dirname)
|
||||
|
||||
if(!g_file_test(filename, G_FILE_TEST_IS_DIR))
|
||||
{
|
||||
gea = gnc_read_example_account(book, filename);
|
||||
gea = gnc_read_example_account(filename);
|
||||
|
||||
if(gea == NULL)
|
||||
{
|
||||
|
||||
@@ -35,7 +35,7 @@ struct GncExampleAccount_struct
|
||||
gchar *title;
|
||||
gchar *filename;
|
||||
QofBook *book;
|
||||
AccountGroup *group;
|
||||
Account *root;
|
||||
gchar *short_description;
|
||||
gchar *long_description;
|
||||
gboolean exclude_from_select_all;
|
||||
@@ -47,13 +47,11 @@ void gnc_destroy_example_account(GncExampleAccount *gea);
|
||||
|
||||
gboolean gnc_write_example_account(GncExampleAccount *gea,
|
||||
const gchar *filename);
|
||||
GncExampleAccount *gnc_read_example_account(QofBook *book,
|
||||
const gchar *filename);
|
||||
GncExampleAccount *gnc_read_example_account(const gchar *filename);
|
||||
|
||||
|
||||
void gnc_free_example_account_list(GSList *list);
|
||||
GSList* gnc_load_example_account_list(QofBook *book,
|
||||
const char *dirname);
|
||||
GSList* gnc_load_example_account_list(const char *dirname);
|
||||
|
||||
gboolean gnc_is_example_account_xml(const gchar *name);
|
||||
|
||||
|
||||
@@ -35,8 +35,6 @@
|
||||
#include "gnc-xml-helper.h"
|
||||
#include "Account.h"
|
||||
#include "AccountP.h"
|
||||
#include "Group.h"
|
||||
#include "GroupP.h"
|
||||
#include "Query.h"
|
||||
#include "QueryP.h"
|
||||
#include "Scrub.h"
|
||||
@@ -95,8 +93,8 @@ typedef struct {
|
||||
/* The book */
|
||||
QofBook *book;
|
||||
|
||||
/* The account group */
|
||||
AccountGroup *account_group;
|
||||
/* The root account */
|
||||
Account *root_account;
|
||||
|
||||
/* The pricedb */
|
||||
GNCPriceDB *pricedb;
|
||||
@@ -222,7 +220,7 @@ gnc_version_parser_new(void)
|
||||
-----------
|
||||
start: NA
|
||||
before-child: make sure we don't get two ledger-data's (not allowed ATM).
|
||||
after-child: if a ledger-data child, parse_data->account_group = *result.
|
||||
after-child: if a ledger-data child, parse_data->root_account = *result.
|
||||
characters: allow_and_ignore_only_whitespace
|
||||
|
||||
Similarly, only one query is allowed ...
|
||||
@@ -252,7 +250,7 @@ gnc_parser_before_child_handler(gpointer data_for_children,
|
||||
g_return_val_if_fail(pstatus, FALSE);
|
||||
|
||||
if(strcmp(child_tag, "ledger-data") == 0) {
|
||||
if(pstatus->account_group) {
|
||||
if(pstatus->root_account) {
|
||||
return(FALSE);
|
||||
}
|
||||
}
|
||||
@@ -283,7 +281,7 @@ gnc_parser_after_child_handler(gpointer data_for_children,
|
||||
{
|
||||
g_return_val_if_fail(child_result, FALSE);
|
||||
g_return_val_if_fail(child_result->data, FALSE);
|
||||
pstatus->account_group = (AccountGroup *) child_result->data;
|
||||
pstatus->root_account = (Account *) child_result->data;
|
||||
child_result->should_cleanup = FALSE;
|
||||
}
|
||||
|
||||
@@ -345,7 +343,7 @@ gncxml_setup_for_read (GNCParseStatus *global_parse_status)
|
||||
|
||||
global_parse_status->seen_version = FALSE;
|
||||
global_parse_status->gnc_parser = gnc_pr;
|
||||
global_parse_status->account_group = NULL;
|
||||
global_parse_status->root_account = NULL;
|
||||
global_parse_status->pricedb = NULL;
|
||||
// global_parse_status->query = NULL;
|
||||
global_parse_status->error = GNC_PARSE_ERR_NONE;
|
||||
@@ -362,6 +360,7 @@ qof_session_load_from_xml_file(QofBook *book, const char *filename)
|
||||
gpointer parse_result = NULL;
|
||||
sixtp *top_level_pr;
|
||||
GNCParseStatus global_parse_status;
|
||||
Account *root;
|
||||
|
||||
global_parse_status.book = book;
|
||||
g_return_val_if_fail(book, FALSE);
|
||||
@@ -382,15 +381,16 @@ qof_session_load_from_xml_file(QofBook *book, const char *filename)
|
||||
|
||||
if(parse_ok)
|
||||
{
|
||||
if(!global_parse_status.account_group) return FALSE;
|
||||
if(!global_parse_status.root_account) return FALSE;
|
||||
|
||||
xaccSetAccountGroup(book, global_parse_status.account_group);
|
||||
root = global_parse_status.root_account;
|
||||
gnc_book_set_root_account(book, root);
|
||||
|
||||
/* Fix account and transaction commodities */
|
||||
xaccGroupScrubCommodities (gnc_book_get_group(book));
|
||||
xaccAccountTreeScrubCommodities (root);
|
||||
|
||||
/* Fix split amount/value */
|
||||
xaccGroupScrubSplits (gnc_book_get_group(book));
|
||||
xaccAccountTreeScrubSplits (root);
|
||||
|
||||
return(TRUE);
|
||||
} else {
|
||||
@@ -1079,18 +1079,18 @@ kvp_frame_parser_new(void)
|
||||
/****************************************************************************/
|
||||
/* <ledger-data> (parent <gnc-data>)
|
||||
|
||||
On failure or on normal cleanup, the account group will be killed,
|
||||
On failure or on normal cleanup, the root account will be killed,
|
||||
so if you want it, you better set should_cleanup to false
|
||||
|
||||
input: NA
|
||||
to-children-via-*result: new AccountGroup*
|
||||
returns: an AccountGroup*
|
||||
start: creates the account group and puts it into *result
|
||||
to-children-via-*result: new root Account*
|
||||
returns: an Account*
|
||||
start: creates the root account and puts it into *result
|
||||
characters: NA
|
||||
end: finishes up the account group and leaves it in result.
|
||||
cleanup-result: deletes the account group (use should_cleanup to avoid).
|
||||
end: finishes up the root account and leaves it in result.
|
||||
cleanup-result: deletes the root account (use should_cleanup to avoid).
|
||||
cleanup-chars: NA
|
||||
fail: deletes the account group in *result.
|
||||
fail: deletes the root account in *result.
|
||||
result-fail: same as cleanup-result.
|
||||
chars-fail: NA
|
||||
|
||||
@@ -1103,16 +1103,16 @@ ledger_data_start_handler(GSList* sibling_data, gpointer parent_data,
|
||||
gpointer *result, const gchar *tag, gchar **attrs)
|
||||
{
|
||||
GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
|
||||
AccountGroup *ag;
|
||||
Account *ra;
|
||||
|
||||
/* disable logging during load; otherwise its just a mess */
|
||||
xaccLogDisable();
|
||||
ag = xaccMallocAccountGroup(pstatus->book);
|
||||
ra = xaccMallocAccount(pstatus->book);
|
||||
|
||||
g_return_val_if_fail(ag, FALSE);
|
||||
g_return_val_if_fail(ra, FALSE);
|
||||
|
||||
*data_for_children = ag;
|
||||
return(ag != NULL);
|
||||
*data_for_children = ra;
|
||||
return(ra != NULL);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@@ -1154,23 +1154,21 @@ ledger_data_end_handler(gpointer data_for_children,
|
||||
gpointer *result, const gchar *tag)
|
||||
{
|
||||
|
||||
AccountGroup *ag = (AccountGroup *) data_for_children;
|
||||
Account *ra = (Account *) data_for_children;
|
||||
GList *descendants;
|
||||
|
||||
g_return_val_if_fail(ag, FALSE);
|
||||
g_return_val_if_fail(ra, FALSE);
|
||||
|
||||
/* mark the newly read group as saved, since the act of putting
|
||||
* it together will have caused it to be marked up as not-saved.
|
||||
*/
|
||||
xaccGroupMarkSaved (ag);
|
||||
|
||||
/* commit all groups, this completes the BeginEdit started when the
|
||||
/* commit all accounts, this completes the BeginEdit started when the
|
||||
* account_end_handler finished reading the account.
|
||||
*/
|
||||
xaccAccountGroupCommitEdit (ag);
|
||||
descendants = gnc_account_get_descendants(ra);
|
||||
g_list_foreach(descendants, (GFunc)xaccAccountCommitEdit, NULL);
|
||||
g_list_free(descendants);
|
||||
|
||||
xaccLogEnable();
|
||||
|
||||
*result = ag;
|
||||
*result = ra;
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
@@ -1183,22 +1181,22 @@ ledger_data_fail_handler(gpointer data_for_children,
|
||||
gpointer *result,
|
||||
const gchar *tag)
|
||||
{
|
||||
AccountGroup *ag = (AccountGroup *) data_for_children;
|
||||
if(ag)
|
||||
Account *account = (Account *) data_for_children;
|
||||
if (account)
|
||||
{
|
||||
xaccAccountGroupBeginEdit(ag);
|
||||
xaccAccountGroupDestroy(ag);
|
||||
xaccAccountBeginEdit(account);
|
||||
xaccAccountDestroy(account);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
ledger_data_result_cleanup(sixtp_child_result *cr)
|
||||
{
|
||||
AccountGroup *ag = (AccountGroup *) cr->data;
|
||||
if(ag)
|
||||
Account *account = (Account *) cr->data;
|
||||
if (account)
|
||||
{
|
||||
xaccAccountGroupBeginEdit(ag);
|
||||
xaccAccountGroupDestroy(ag);
|
||||
xaccAccountBeginEdit(account);
|
||||
xaccAccountDestroy(account);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1245,9 +1243,9 @@ ledger_data_parser_new(void)
|
||||
to its children. It generates no data of its own, so it doesn't
|
||||
need any cleanup.
|
||||
|
||||
input: AccountGroup*
|
||||
input: Account*
|
||||
|
||||
to-children-via-*result: AccountGroup*
|
||||
to-children-via-*result: Account*
|
||||
|
||||
returns: NA
|
||||
|
||||
@@ -1291,7 +1289,7 @@ account_start_handler(GSList* sibling_data,
|
||||
if the resultant account is OK, and if so, we add it to the
|
||||
ledger-data's account group.
|
||||
|
||||
input: AccountGroup*
|
||||
input: Account*
|
||||
to-children-via-*result: new Account*
|
||||
returns: NA
|
||||
start: create new Account*, and leave in for children.
|
||||
@@ -1331,20 +1329,18 @@ account_restore_end_handler(gpointer data_for_children,
|
||||
gpointer parent_data, gpointer global_data,
|
||||
gpointer *result, const gchar *tag)
|
||||
{
|
||||
AccountGroup *ag = (AccountGroup *) parent_data;
|
||||
Account *parent = (Account *) parent_data;
|
||||
Account *acc = (Account *) *result;
|
||||
AccountGroup *parent_ag;
|
||||
|
||||
g_return_val_if_fail((ag && acc), FALSE);
|
||||
g_return_val_if_fail((parent && acc), FALSE);
|
||||
|
||||
/* CHECKME: do we need to xaccAccountRecomputeBalance(acc) here? */
|
||||
xaccAccountCommitEdit(acc);
|
||||
|
||||
/* If the account doesn't have a parent yet, just cram it into the
|
||||
top level */
|
||||
parent_ag = xaccAccountGetParent(acc);
|
||||
|
||||
if(!parent_ag) xaccGroupInsertAccount(ag, acc);
|
||||
if (!gnc_account_get_parent(acc))
|
||||
gnc_account_append_child(parent, acc);
|
||||
|
||||
*result = NULL;
|
||||
|
||||
@@ -1713,7 +1709,7 @@ acc_restore_parent_end_handler(gpointer data_for_children,
|
||||
|
||||
g_return_val_if_fail(parent, FALSE);
|
||||
|
||||
xaccAccountInsertSubAccount(parent, acc);
|
||||
gnc_account_append_child(parent, acc);
|
||||
|
||||
return(TRUE);
|
||||
}
|
||||
@@ -2682,9 +2678,9 @@ query_server_parser_new (void)
|
||||
to its children. It generates no data of its own, so it doesn't
|
||||
need any cleanup.
|
||||
|
||||
input: AccountGroup*
|
||||
input: Account*
|
||||
|
||||
to-children-via-*result: AccountGroup*
|
||||
to-children-via-*result: Account*
|
||||
|
||||
returns: NA
|
||||
|
||||
@@ -2724,7 +2720,7 @@ transaction_start_handler(GSList* sibling_data, gpointer parent_data,
|
||||
see if the resultant account is OK, and if so, we add it to the
|
||||
ledger-data's account group.
|
||||
|
||||
from parent: AccountGroup*
|
||||
from parent: Account*
|
||||
|
||||
for children: new Transaction*
|
||||
|
||||
@@ -2772,11 +2768,11 @@ txn_restore_end_handler(gpointer data_for_children,
|
||||
gpointer parent_data, gpointer global_data,
|
||||
gpointer *result, const gchar *tag)
|
||||
{
|
||||
AccountGroup *ag = (AccountGroup *) parent_data;
|
||||
Account *parent = (Account *) parent_data;
|
||||
Transaction *trans = (Transaction *) data_for_children;
|
||||
|
||||
g_return_val_if_fail(trans, FALSE);
|
||||
if(!ag) {
|
||||
if (!parent) {
|
||||
xaccTransDestroy(trans);
|
||||
xaccTransCommitEdit(trans);
|
||||
return(FALSE);
|
||||
|
||||
@@ -34,8 +34,6 @@
|
||||
|
||||
#include "gnc-engine.h"
|
||||
#include "gnc-pricedb-p.h"
|
||||
#include "Group.h"
|
||||
#include "GroupP.h"
|
||||
#include "Scrub.h"
|
||||
#include "SX-book.h"
|
||||
#include "SX-book-p.h"
|
||||
@@ -163,6 +161,8 @@ static gboolean
|
||||
add_account_local(sixtp_gdv2 *data, Account *act)
|
||||
{
|
||||
gnc_commodity_table *table;
|
||||
Account *parent, *root;
|
||||
int type;
|
||||
|
||||
table = gnc_book_get_commodity_table (data->book);
|
||||
|
||||
@@ -180,10 +180,20 @@ add_account_local(sixtp_gdv2 *data, Account *act)
|
||||
xaccAccountScrubCommodity (act);
|
||||
xaccAccountScrubKvp (act);
|
||||
|
||||
if(!xaccAccountGetParent(act))
|
||||
{
|
||||
xaccGroupInsertAccount(gnc_book_get_group(data->book), act);
|
||||
/* Backwards compatability. If there's no parent, see if this
|
||||
* account is of type ROOT. If not, find or create a ROOT
|
||||
* account and make that the parent. */
|
||||
type = xaccAccountGetType(act);
|
||||
if (type == ACCT_TYPE_ROOT) {
|
||||
gnc_book_set_root_account(data->book, act);
|
||||
} else {
|
||||
parent = gnc_account_get_parent(act);
|
||||
if (parent == NULL) {
|
||||
root = gnc_book_get_root_account(data->book);
|
||||
gnc_account_append_child(root, act);
|
||||
}
|
||||
}
|
||||
|
||||
data->counter.accounts_loaded++;
|
||||
run_callback(data, "account");
|
||||
|
||||
@@ -251,7 +261,7 @@ add_template_transaction_local( sixtp_gdv2 *data,
|
||||
{
|
||||
GList *n;
|
||||
Account *tmpAcct;
|
||||
AccountGroup *acctGroup = NULL;
|
||||
Account *acctRoot = NULL;
|
||||
QofBook *book;
|
||||
|
||||
book = data->book;
|
||||
@@ -260,22 +270,20 @@ add_template_transaction_local( sixtp_gdv2 *data,
|
||||
/* . template accounts. */
|
||||
/* . transactions in those accounts. */
|
||||
for ( n = txd->accts; n; n = n->next ) {
|
||||
if ( xaccAccountGetParent( (Account*)n->data ) == NULL ) {
|
||||
if ( gnc_account_get_parent( (Account*)n->data ) == NULL ) {
|
||||
/* remove the gnc_book_init-created account of the same name */
|
||||
acctGroup =
|
||||
gnc_book_get_template_group(book);
|
||||
tmpAcct =
|
||||
xaccGetAccountFromName( acctGroup,
|
||||
acctRoot = gnc_book_get_template_root(book);
|
||||
tmpAcct = gnc_account_lookup_by_name( acctRoot,
|
||||
xaccAccountGetName( (Account*)n->data ) );
|
||||
if ( tmpAcct != NULL ) {
|
||||
/* XXX hack alert FIXME .... Should this be 'Remove', or 'Destroy'?
|
||||
* If we just remove, then this seems to be a memory leak to me, since
|
||||
* it is never reparented. Shouldn't it be a Destroy ???
|
||||
*/
|
||||
xaccGroupRemoveAccount( acctGroup, tmpAcct );
|
||||
gnc_account_remove_child( acctRoot, tmpAcct );
|
||||
}
|
||||
|
||||
xaccGroupInsertAccount( acctGroup, (Account*)n->data );
|
||||
gnc_account_append_child( acctRoot, (Account*)n->data );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -285,8 +293,6 @@ add_template_transaction_local( sixtp_gdv2 *data,
|
||||
add_transaction_local( data, (Transaction*)n->data );
|
||||
}
|
||||
|
||||
xaccAccountGroupCommitEdit (acctGroup);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -638,7 +644,7 @@ qof_session_load_from_xml_file_v2_full(
|
||||
FileBackend *fbe, QofBook *book,
|
||||
sixtp_push_handler push_handler, gpointer push_user_data)
|
||||
{
|
||||
AccountGroup *grp;
|
||||
Account *root;
|
||||
QofBackend *be = &fbe->be;
|
||||
sixtp_gdv2 *gd;
|
||||
sixtp *top_parser;
|
||||
@@ -745,19 +751,21 @@ qof_session_load_from_xml_file_v2_full(
|
||||
qof_object_foreach_backend (GNC_FILE_BACKEND, scrub_cb, &be_data);
|
||||
|
||||
/* fix price quote sources */
|
||||
grp = gnc_book_get_group(book);
|
||||
xaccGroupScrubQuoteSources (grp, gnc_book_get_commodity_table(book));
|
||||
root = gnc_book_get_root_account(book);
|
||||
xaccAccountTreeScrubQuoteSources (root, gnc_book_get_commodity_table(book));
|
||||
|
||||
/* Fix account and transaction commodities */
|
||||
xaccGroupScrubCommodities (grp);
|
||||
xaccAccountTreeScrubCommodities (root);
|
||||
|
||||
/* Fix split amount/value */
|
||||
xaccGroupScrubSplits (grp);
|
||||
xaccAccountTreeScrubSplits (root);
|
||||
|
||||
/* commit all groups, this completes the BeginEdit started when the
|
||||
* account_end_handler finished reading the account.
|
||||
*/
|
||||
xaccAccountGroupCommitEdit (grp);
|
||||
gnc_account_foreach_descendant(root,
|
||||
(AccountCb) xaccAccountCommitEdit,
|
||||
NULL);
|
||||
|
||||
/* start logging again */
|
||||
xaccLogEnable ();
|
||||
@@ -924,7 +932,7 @@ write_book(FILE *out, QofBook *book, sixtp_gdv2 *gd)
|
||||
gnc_commodity_table_get_size(
|
||||
gnc_book_get_commodity_table(book)),
|
||||
"account",
|
||||
1 + xaccGroupGetNumSubAccounts(gnc_book_get_group(book)),
|
||||
1 + gnc_account_n_descendants(gnc_book_get_root_account(book)),
|
||||
"transaction",
|
||||
gnc_book_count_transactions(book),
|
||||
"schedxaction",
|
||||
@@ -1036,7 +1044,7 @@ write_transactions(FILE *out, QofBook *book, sixtp_gdv2 *gd)
|
||||
|
||||
be_data.out = out;
|
||||
be_data.gd = gd;
|
||||
xaccGroupForEachTransaction(gnc_book_get_group(book),
|
||||
xaccAccountTreeForEachTransaction(gnc_book_get_root_account(book),
|
||||
xml_add_trn_data,
|
||||
(gpointer) &be_data);
|
||||
}
|
||||
@@ -1044,18 +1052,18 @@ write_transactions(FILE *out, QofBook *book, sixtp_gdv2 *gd)
|
||||
static void
|
||||
write_template_transaction_data( FILE *out, QofBook *book, sixtp_gdv2 *gd )
|
||||
{
|
||||
AccountGroup *ag;
|
||||
Account *ra;
|
||||
struct file_backend be_data;
|
||||
|
||||
be_data.out = out;
|
||||
be_data.gd = gd;
|
||||
|
||||
ag = gnc_book_get_template_group(book);
|
||||
if ( xaccGroupGetNumSubAccounts(ag) > 0 )
|
||||
ra = gnc_book_get_template_root(book);
|
||||
if ( gnc_account_n_descendants(ra) > 0 )
|
||||
{
|
||||
fprintf( out, "<%s>\n", TEMPLATE_TRANSACTION_TAG );
|
||||
write_account_group( out, ag, gd );
|
||||
xaccGroupForEachTransaction( ag, xml_add_trn_data, (gpointer)&be_data );
|
||||
write_account_tree( out, ra, gd );
|
||||
xaccAccountTreeForEachTransaction( ra, xml_add_trn_data, (gpointer)&be_data );
|
||||
fprintf( out, "</%s>\n", TEMPLATE_TRANSACTION_TAG );
|
||||
}
|
||||
}
|
||||
@@ -1167,7 +1175,7 @@ gnc_book_write_to_xml_filehandle_v2(QofBook *book, FILE *out)
|
||||
gd->counter.commodities_total =
|
||||
gnc_commodity_table_get_size(gnc_book_get_commodity_table(book));
|
||||
gd->counter.accounts_total = 1 +
|
||||
xaccGroupGetNumSubAccounts(gnc_book_get_group(book));
|
||||
gnc_account_n_descendants(gnc_book_get_root_account(book));
|
||||
gd->counter.transactions_total = gnc_book_count_transactions(book);
|
||||
gd->counter.schedXactions_total =
|
||||
g_list_length(gnc_book_get_schedxactions(book)->sx_list);
|
||||
@@ -1189,14 +1197,14 @@ gboolean
|
||||
gnc_book_write_accounts_to_xml_filehandle_v2(QofBackend *be, QofBook *book, FILE *out)
|
||||
{
|
||||
gnc_commodity_table *table;
|
||||
AccountGroup *grp;
|
||||
Account *root;
|
||||
int ncom, nacc;
|
||||
sixtp_gdv2 *gd;
|
||||
|
||||
if (!out) return FALSE;
|
||||
|
||||
grp = gnc_book_get_group(book);
|
||||
nacc = 1 + xaccGroupGetNumSubAccounts(grp);
|
||||
root = gnc_book_get_root_account(book);
|
||||
nacc = 1 + gnc_account_n_descendants(root);
|
||||
|
||||
table = gnc_book_get_commodity_table(book);
|
||||
ncom = gnc_commodity_table_get_size(table);
|
||||
|
||||
@@ -28,10 +28,10 @@
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "Group.h"
|
||||
#include "gnc-xml.h"
|
||||
#include "gnc-xml.h"
|
||||
#include "io-utils.h"
|
||||
#include "gnc-gconf-utils.h"
|
||||
|
||||
/*
|
||||
<!-- Local variables: -->
|
||||
@@ -51,21 +51,16 @@ write_emacs_trailer(FILE *out)
|
||||
fprintf(out, emacs_trailer);
|
||||
}
|
||||
|
||||
void
|
||||
write_account_group(FILE *out, AccountGroup *grp, sixtp_gdv2 *gd)
|
||||
{
|
||||
GList *list;
|
||||
GList *node;
|
||||
|
||||
list = xaccGroupGetAccountList(grp);
|
||||
|
||||
for (node = list; node; node = node->next)
|
||||
static void
|
||||
write_one_account(FILE *out,
|
||||
Account *account,
|
||||
sixtp_gdv2 *gd,
|
||||
gboolean allow_incompat)
|
||||
{
|
||||
xmlNodePtr accnode;
|
||||
AccountGroup *newgrp;
|
||||
|
||||
accnode = gnc_account_dom_tree_create((Account*)(node->data),
|
||||
gd && gd->exporting);
|
||||
accnode =
|
||||
gnc_account_dom_tree_create(account, gd && gd->exporting, allow_incompat);
|
||||
|
||||
xmlElemDump(out, NULL, accnode);
|
||||
fprintf(out, "\n");
|
||||
@@ -73,18 +68,35 @@ write_account_group(FILE *out, AccountGroup *grp, sixtp_gdv2 *gd)
|
||||
xmlFreeNode(accnode);
|
||||
gd->counter.accounts_loaded++;
|
||||
run_callback(gd, "account");
|
||||
}
|
||||
|
||||
newgrp = xaccAccountGetChildren((Account*)(node->data));
|
||||
|
||||
if (newgrp)
|
||||
void
|
||||
write_account_tree(FILE *out, Account *root, sixtp_gdv2 *gd)
|
||||
{
|
||||
write_account_group(out, newgrp, gd);
|
||||
}
|
||||
GList *descendants, *node;
|
||||
gboolean allow_incompat = FALSE;
|
||||
GError *err = NULL;
|
||||
|
||||
allow_incompat = gnc_gconf_get_bool("dev", "allow_file_incompatibility", &err);
|
||||
if (err != NULL)
|
||||
{
|
||||
g_warning("error getting gconf value [%s]", err->message);
|
||||
g_error_free(err);
|
||||
allow_incompat = FALSE;
|
||||
}
|
||||
g_debug("allow_incompatibility: [%s]", allow_incompat ? "true" : "false");
|
||||
|
||||
if (allow_incompat)
|
||||
write_one_account(out, root, gd, allow_incompat);
|
||||
|
||||
descendants = gnc_account_get_descendants(root);
|
||||
for (node = descendants; node; node = g_list_next(node))
|
||||
write_one_account(out, node->data, gd, allow_incompat);
|
||||
g_list_free(descendants);
|
||||
}
|
||||
|
||||
void
|
||||
write_accounts(FILE *out, QofBook *book, sixtp_gdv2 *gd)
|
||||
{
|
||||
write_account_group(out, gnc_book_get_group(book), gd);
|
||||
write_account_tree(out, gnc_book_get_root_account(book), gd);
|
||||
}
|
||||
|
||||
@@ -27,11 +27,10 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "Group.h"
|
||||
#include "io-gncxml-v2.h"
|
||||
#include "qof.h"
|
||||
|
||||
void write_account_group(FILE *out, AccountGroup *grp, sixtp_gdv2 *gd);
|
||||
void write_account_tree(FILE *out, Account *root, sixtp_gdv2 *gd);
|
||||
void write_accounts(FILE *out, QofBook *book, sixtp_gdv2 *gd);
|
||||
void write_book_parts(FILE *out, QofBook *book);
|
||||
void write_commodities(FILE *out, QofBook *book, sixtp_gdv2 *gd);
|
||||
|
||||
@@ -45,11 +45,11 @@
|
||||
static const gchar *da_ending = ".gnucash-xea";
|
||||
|
||||
static void
|
||||
test_load_file(QofBook *book, const char *filename)
|
||||
test_load_file(const char *filename)
|
||||
{
|
||||
GncExampleAccount *gea;
|
||||
|
||||
gea = gnc_read_example_account(book, filename);
|
||||
gea = gnc_read_example_account(filename);
|
||||
|
||||
if(gea != NULL)
|
||||
{
|
||||
@@ -69,7 +69,6 @@ guile_main (void *closure, int argc, char **argv)
|
||||
const char *location = g_getenv("GNC_ACCOUNT_PATH");
|
||||
GSList *list = NULL;
|
||||
GDir *ea_dir;
|
||||
QofBook *book;
|
||||
|
||||
if (!location)
|
||||
{
|
||||
@@ -79,8 +78,6 @@ guile_main (void *closure, int argc, char **argv)
|
||||
gnc_module_system_init();
|
||||
gnc_module_load("gnucash/engine", 0);
|
||||
|
||||
book = qof_book_new ();
|
||||
|
||||
if((ea_dir = g_dir_open(location, 0, NULL)) == NULL)
|
||||
{
|
||||
failure("unable to open ea directory");
|
||||
@@ -96,7 +93,7 @@ guile_main (void *closure, int argc, char **argv)
|
||||
gchar *to_open = g_build_filename(location, entry, (gchar*)NULL);
|
||||
if (!g_file_test(to_open, G_FILE_TEST_IS_DIR))
|
||||
{
|
||||
test_load_file(book, to_open);
|
||||
test_load_file(to_open);
|
||||
}
|
||||
g_free(to_open);
|
||||
}
|
||||
@@ -105,7 +102,7 @@ guile_main (void *closure, int argc, char **argv)
|
||||
g_dir_close(ea_dir);
|
||||
|
||||
{
|
||||
list = gnc_load_example_account_list(book, location);
|
||||
list = gnc_load_example_account_list(location);
|
||||
|
||||
do_test(list != NULL, "gnc_load_example_account_list");
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@
|
||||
#include <glib/gstdio.h>
|
||||
|
||||
#include "cashobjects.h"
|
||||
#include "Group.h"
|
||||
#include "TransLog.h"
|
||||
#include "gnc-engine.h"
|
||||
#include "gnc-backend-file.h"
|
||||
@@ -78,7 +77,7 @@ test_load_file(const char *filename)
|
||||
{
|
||||
QofSession *session;
|
||||
QofBook *book;
|
||||
AccountGroup *grp;
|
||||
Account *root;
|
||||
gboolean ignore_lock;
|
||||
|
||||
session = qof_session_new();
|
||||
@@ -91,9 +90,9 @@ test_load_file(const char *filename)
|
||||
qof_session_load(session, NULL);
|
||||
book = qof_session_get_book (session);
|
||||
|
||||
grp = xaccGetAccountGroup(book);
|
||||
do_test (xaccGroupGetBook (grp) == book,
|
||||
"book and group don't match");
|
||||
root = gnc_book_get_root_account(book);
|
||||
do_test (gnc_account_get_book (root) == book,
|
||||
"book and root account don't match");
|
||||
|
||||
do_test_args(qof_session_get_error(session) == ERR_BACKEND_NO_ERR,
|
||||
"session load xml2", __FILE__, __LINE__,
|
||||
|
||||
@@ -41,7 +41,6 @@
|
||||
#include "test-file-stuff.h"
|
||||
|
||||
#include "Account.h"
|
||||
#include "Group.h"
|
||||
#include "Scrub.h"
|
||||
|
||||
static QofBook *sixbook;
|
||||
@@ -114,7 +113,8 @@ node_and_account_equal(xmlNodePtr node, Account *act)
|
||||
else if(safe_strcmp((char*)mark->name, "act:commodity") == 0)
|
||||
{
|
||||
if(!equals_node_val_vs_commodity(
|
||||
mark, xaccAccountGetCommodity(act), xaccAccountGetBook(act)))
|
||||
mark, xaccAccountGetCommodity(act),
|
||||
gnc_account_get_book(act)))
|
||||
{
|
||||
return g_strdup("commodities differ");
|
||||
}
|
||||
@@ -146,8 +146,7 @@ node_and_account_equal(xmlNodePtr node, Account *act)
|
||||
else if(safe_strcmp((char*)mark->name, "act:parent") == 0)
|
||||
{
|
||||
if(!equals_node_val_vs_guid(
|
||||
mark, xaccAccountGetGUID(xaccGroupGetParentAccount(
|
||||
xaccAccountGetParent(act)))))
|
||||
mark, xaccAccountGetGUID(gnc_account_get_parent(act))))
|
||||
{
|
||||
return g_strdup("parent ids differ");
|
||||
}
|
||||
@@ -221,7 +220,7 @@ test_account(int i, Account *test_act)
|
||||
gchar *compare_msg;
|
||||
int fd;
|
||||
|
||||
test_node = gnc_account_dom_tree_create(test_act, FALSE);
|
||||
test_node = gnc_account_dom_tree_create(test_act, FALSE, TRUE);
|
||||
|
||||
if(!test_node)
|
||||
{
|
||||
@@ -317,7 +316,7 @@ test_generation()
|
||||
/* act1 = get_random_account(); */
|
||||
/* act2 = get_random_account(); */
|
||||
|
||||
/* xaccAccountInsertSubAccount(act1, act2); */
|
||||
/* gnc_account_append_child(act1, act2); */
|
||||
|
||||
/* test_account(-1, act2); */
|
||||
/* test_account(-1, act1); */
|
||||
@@ -334,9 +333,9 @@ test_real_account(const char *tag, gpointer global_data, gpointer data)
|
||||
char *msg;
|
||||
Account *act = (Account*)data;
|
||||
|
||||
if(!xaccAccountGetParent(act))
|
||||
if(!gnc_account_get_parent(act))
|
||||
{
|
||||
xaccGroupInsertAccount(xaccGetAccountGroup(sixbook), act);
|
||||
gnc_account_append_child(gnc_book_get_root_account(sixbook), act);
|
||||
}
|
||||
|
||||
msg = node_and_account_equal((xmlNodePtr)global_data, act);
|
||||
|
||||
@@ -365,14 +365,16 @@ test_transaction(void)
|
||||
for(i = 0; i < 50; i++)
|
||||
{
|
||||
Transaction *ran_trn;
|
||||
AccountGroup *grp;
|
||||
Account *root;
|
||||
xmlNodePtr test_node;
|
||||
gnc_commodity *com;
|
||||
gchar *compare_msg;
|
||||
gchar *filename1;
|
||||
int fd;
|
||||
|
||||
grp = get_random_group(book);
|
||||
/* The next line exists for its side effect of creating the
|
||||
* account tree. */
|
||||
root = get_random_account_tree(book);
|
||||
ran_trn = get_random_transaction(book);
|
||||
if(!ran_trn)
|
||||
{
|
||||
|
||||
@@ -38,8 +38,6 @@
|
||||
#include <libpq-fe.h>
|
||||
|
||||
#include "AccountP.h"
|
||||
#include "Group.h"
|
||||
#include "GroupP.h"
|
||||
#include "gnc-commodity.h"
|
||||
#include "gnc-engine.h"
|
||||
#include "gnc-pricedb.h"
|
||||
@@ -713,7 +711,7 @@ pgendRunQuery (QofBackend *bend, gpointer q_p)
|
||||
PGBackend *be = (PGBackend *)bend;
|
||||
Query *q = (Query*) q_p;
|
||||
const char * sql_query_string;
|
||||
AccountGroup *topgroup;
|
||||
Account *root;
|
||||
sqlQuery *sq;
|
||||
|
||||
ENTER ("be=%p, qry=%p", be, q);
|
||||
@@ -728,10 +726,10 @@ pgendRunQuery (QofBackend *bend, gpointer q_p)
|
||||
sq = sqlQuery_new();
|
||||
sql_query_string = sqlQuery_build (sq, q);
|
||||
|
||||
topgroup = gnc_book_get_group (pgendGetBook(be));
|
||||
root = gnc_book_get_root_account(pgendGetBook(be));
|
||||
|
||||
/* stage transactions, save some postgres overhead */
|
||||
xaccGroupBeginStagedTransactionTraversals (topgroup);
|
||||
gnc_account_tree_begin_staged_transaction_traversals (root);
|
||||
|
||||
/* We will be doing a bulk insertion of transactions below.
|
||||
* We can gain a tremendous performance improvement,
|
||||
@@ -746,17 +744,13 @@ pgendRunQuery (QofBackend *bend, gpointer q_p)
|
||||
* by not very much.
|
||||
*/
|
||||
ncalls = 0;
|
||||
xaccAccountGroupBeginEdit(topgroup);
|
||||
xaccAccountBeginEdit(root);
|
||||
pgendFillOutToCheckpoint (be, sql_query_string);
|
||||
xaccAccountGroupCommitEdit(topgroup);
|
||||
xaccAccountCommitEdit(root);
|
||||
PINFO ("number of calls to fill out=%d", ncalls);
|
||||
|
||||
sql_Query_destroy(sq);
|
||||
|
||||
/* the fill-out will dirty a lot of data. That's irrelevent,
|
||||
* mark it all as having been saved. */
|
||||
xaccGroupMarkSaved (topgroup);
|
||||
|
||||
pgendEnable(be);
|
||||
qof_event_resume();
|
||||
|
||||
@@ -793,7 +787,7 @@ get_all_trans_cb (PGBackend *be, PGresult *result, int j, gpointer data)
|
||||
|
||||
|
||||
static void
|
||||
pgendGetAllTransactions (PGBackend *be, AccountGroup *grp)
|
||||
pgendGetAllTransactions (PGBackend *be, Account *root)
|
||||
{
|
||||
GList *node, *xaction_list = NULL;
|
||||
|
||||
@@ -804,14 +798,14 @@ pgendGetAllTransactions (PGBackend *be, AccountGroup *grp)
|
||||
xaction_list = pgendGetResults (be, get_all_trans_cb, xaction_list);
|
||||
|
||||
/* restore the transactions */
|
||||
xaccAccountGroupBeginEdit (grp);
|
||||
xaccAccountBeginEdit (root);
|
||||
for (node=xaction_list; node; node=node->next)
|
||||
{
|
||||
xxxpgendCopyTransactionToEngine (be, (GUID *)node->data);
|
||||
guid_free (node->data);
|
||||
}
|
||||
g_list_free(xaction_list);
|
||||
xaccAccountGroupCommitEdit (grp);
|
||||
xaccAccountCommitEdit (root);
|
||||
|
||||
pgendEnable(be);
|
||||
qof_event_resume();
|
||||
@@ -871,9 +865,9 @@ static void
|
||||
pgendSync (QofBackend *bend, QofBook *book)
|
||||
{
|
||||
PGBackend *be = (PGBackend *)bend;
|
||||
AccountGroup *grp = gnc_book_get_group (book);
|
||||
Account *root = gnc_book_get_root_account(book);
|
||||
|
||||
ENTER ("be=%p, grp=%p", be, grp);
|
||||
ENTER ("be=%p, root=%p", be, root);
|
||||
|
||||
pgend_set_book (be, book);
|
||||
be->version_check = (guint32) time(0);
|
||||
@@ -894,8 +888,8 @@ pgendSync (QofBackend *bend, QofBook *book)
|
||||
pgendStoreBook (be, book);
|
||||
|
||||
/* store the account group hierarchy, and then all transactions */
|
||||
pgendStoreGroup (be, grp);
|
||||
pgendStoreAllTransactions (be, grp);
|
||||
pgendStoreAccountTree (be, root);
|
||||
pgendStoreAllTransactions (be, root);
|
||||
|
||||
/* don't send events to GUI, don't accept callbacks to backend */
|
||||
qof_event_suspend();
|
||||
@@ -907,7 +901,7 @@ pgendSync (QofBackend *bend, QofBook *book)
|
||||
(MODE_SINGLE_UPDATE != be->session_mode))
|
||||
{
|
||||
Timespec ts = gnc_iso8601_to_timespec_gmt (CK_BEFORE_LAST_DATE);
|
||||
pgendGroupGetAllBalances (be, grp, ts);
|
||||
pgendAccountTreeGetAllBalances (be, root, ts);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -958,9 +952,9 @@ pgendSyncSingleFile (QofBackend *bend, QofBook *book)
|
||||
char buff[4000];
|
||||
char *p;
|
||||
PGBackend *be = (PGBackend *)bend;
|
||||
AccountGroup *grp = gnc_book_get_group (book);
|
||||
Account *root = gnc_book_get_root_account(book);
|
||||
|
||||
ENTER ("be=%p, grp=%p", be, grp);
|
||||
ENTER ("be=%p, root=%p", be, root);
|
||||
|
||||
pgend_set_book (be, book);
|
||||
|
||||
@@ -1017,14 +1011,14 @@ pgendSyncSingleFile (QofBackend *bend, QofBook *book)
|
||||
pgendStoreBookNoLock (be, book, TRUE);
|
||||
|
||||
/* Store accounts and commodities */
|
||||
xaccClearMarkDownGr (grp, 0);
|
||||
pgendStoreGroupNoLock (be, grp, TRUE, TRUE);
|
||||
xaccClearMarkDownGr (grp, 0);
|
||||
xaccClearMarkDown (root, 0);
|
||||
pgendStoreAccountTreeNoLock (be, root, TRUE, TRUE);
|
||||
xaccClearMarkDown (root, 0);
|
||||
|
||||
/* Recursively walk transactions. Start by reseting the write
|
||||
* flags. We use this to avoid infinite recursion */
|
||||
xaccGroupBeginStagedTransactionTraversals(grp);
|
||||
xaccGroupStagedTransactionTraversal (grp, 1, trans_traverse_cb, be);
|
||||
gnc_account_tree_begin_staged_transaction_traversals(root);
|
||||
gnc_account_tree_staged_transaction_traversal (root, 1, trans_traverse_cb, be);
|
||||
|
||||
/* hack alert -- In some deranged theory, we should be
|
||||
* syncing prices here, as well as syncing any/all other
|
||||
@@ -1424,7 +1418,7 @@ pgend_session_end (QofBackend *bend)
|
||||
* it might be opened in multi-user mode next time. Thus, update
|
||||
* the account balance checkpoints just in case.
|
||||
*/
|
||||
/* pgendGroupRecomputeAllCheckpoints (be, be->topgroup); */
|
||||
/* pgendAccountTreeRecomputeAllCheckpoints (be, be->root); */
|
||||
break;
|
||||
|
||||
case MODE_POLL:
|
||||
@@ -1481,7 +1475,7 @@ static void
|
||||
pgend_book_load_poll (QofBackend *bend, QofBook *book)
|
||||
{
|
||||
Timespec ts = gnc_iso8601_to_timespec_gmt (CK_BEFORE_LAST_DATE);
|
||||
AccountGroup *grp;
|
||||
Account *root;
|
||||
PGBackend *be = (PGBackend *)bend;
|
||||
|
||||
if (!be) return;
|
||||
@@ -1508,10 +1502,10 @@ pgend_book_load_poll (QofBackend *bend, QofBook *book)
|
||||
|
||||
pgendGetAllAccountsInBook (be, book);
|
||||
|
||||
grp = gnc_book_get_group (book);
|
||||
xaccAccountGroupBeginEdit (grp);
|
||||
pgendGroupGetAllBalances (be, grp, ts);
|
||||
xaccAccountGroupCommitEdit (grp);
|
||||
root = gnc_book_get_root_account (book);
|
||||
xaccAccountBeginEdit (root);
|
||||
pgendAccountTreeGetAllBalances (be, root, ts);
|
||||
xaccAccountCommitEdit (root);
|
||||
|
||||
/* re-enable events */
|
||||
pgendEnable(be);
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
#include <gmodule.h>
|
||||
#include <libpq-fe.h>
|
||||
|
||||
#include "Group.h"
|
||||
#include "qof.h"
|
||||
#include "Transaction.h"
|
||||
|
||||
|
||||
@@ -30,8 +30,6 @@
|
||||
|
||||
#include "AccountP.h"
|
||||
#include "qof.h"
|
||||
#include "Group.h"
|
||||
#include "GroupP.h"
|
||||
#include "gnc-commodity.h"
|
||||
#include "gnc-pricedb.h"
|
||||
|
||||
@@ -48,7 +46,7 @@ static QofLogModule log_module = GNC_MOD_BACKEND;
|
||||
|
||||
/* ============================================================= */
|
||||
/* ============================================================= */
|
||||
/* ACCOUNT AND GROUP STUFF */
|
||||
/* ACCOUNT STUFF */
|
||||
/* (UTILITIES FIRST, THEN SETTERS, THEN GETTERS) */
|
||||
/* ============================================================= */
|
||||
/* ============================================================= */
|
||||
@@ -136,8 +134,8 @@ pgendStoreAccountNoLock (PGBackend *be, Account *acct,
|
||||
}
|
||||
|
||||
/* ============================================================= */
|
||||
/* The pgendStoreGroup() routine stores the account hierarchy to
|
||||
* the sql database. That is, it stores not oonly the top-level
|
||||
/* The pgendStoreAccountTree() routine stores the account hierarchy
|
||||
* to the sql database. That is, it stores not oonly the top-level
|
||||
* accounts, but all of thier children too. It also stores the
|
||||
* commodities associated with the accounts. It does *not* store
|
||||
* any of the transactions.
|
||||
@@ -150,38 +148,30 @@ pgendStoreAccountNoLock (PGBackend *be, Account *acct,
|
||||
*/
|
||||
|
||||
void
|
||||
pgendStoreGroupNoLock (PGBackend *be, AccountGroup *grp,
|
||||
pgendStoreAccountTreeNoLock (PGBackend *be, Account *root,
|
||||
gboolean do_mark, gboolean do_check_version)
|
||||
{
|
||||
GList *start, *node;
|
||||
GList *descendants, *node;
|
||||
|
||||
if (!be || !grp) return;
|
||||
ENTER("grp=%p mark=%d", grp, do_mark);
|
||||
if (!be || !root) return;
|
||||
ENTER("root=%p mark=%d", root, do_mark);
|
||||
|
||||
/* walk the account tree, and store subaccounts */
|
||||
start = xaccGroupGetAccountList (grp);
|
||||
for (node=start; node; node=node->next)
|
||||
{
|
||||
AccountGroup *subgrp;
|
||||
Account *acc = node->data;
|
||||
|
||||
pgendStoreAccountNoLock (be, acc, do_mark, do_check_version);
|
||||
|
||||
/* recursively walk to child accounts */
|
||||
subgrp = xaccAccountGetChildren (acc);
|
||||
if (subgrp) pgendStoreGroupNoLock(be, subgrp, do_mark,
|
||||
do_check_version);
|
||||
}
|
||||
pgendStoreAccountNoLock (be, root, do_mark, do_check_version);
|
||||
descendants = gnc_account_get_descendants (root);
|
||||
for (node=descendants; node; node=node->next)
|
||||
pgendStoreAccountNoLock (be, node->data, do_mark, do_check_version);
|
||||
g_list_free(descendants);
|
||||
LEAVE(" ");
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
pgendStoreGroup (PGBackend *be, AccountGroup *grp)
|
||||
pgendStoreAccountTree (PGBackend *be, Account *root)
|
||||
{
|
||||
char *p;
|
||||
ENTER ("be=%p, grp=%p", be, grp);
|
||||
if (!be || !grp) return;
|
||||
ENTER ("be=%p, root=%p", be, root);
|
||||
if (!be || !root) return;
|
||||
|
||||
/* lock it up so that we store atomically */
|
||||
p = "BEGIN;\n"
|
||||
@@ -192,12 +182,12 @@ pgendStoreGroup (PGBackend *be, AccountGroup *grp)
|
||||
|
||||
/* Clear the account marks; this is used to avoid visiting
|
||||
* the same account more than once. */
|
||||
xaccClearMarkDownGr (grp, 0);
|
||||
xaccClearMarkDown (root, 0);
|
||||
|
||||
pgendStoreGroupNoLock (be, grp, TRUE, TRUE);
|
||||
pgendStoreAccountTreeNoLock (be, root, TRUE, TRUE);
|
||||
|
||||
/* reset the write flags again */
|
||||
xaccClearMarkDownGr (grp, 0);
|
||||
xaccClearMarkDown (root, 0);
|
||||
|
||||
p = "COMMIT;\n"
|
||||
"NOTIFY gncAccount;";
|
||||
@@ -211,23 +201,23 @@ pgendStoreGroup (PGBackend *be, AccountGroup *grp)
|
||||
/* ============================================================= */
|
||||
|
||||
/* ============================================================= */
|
||||
/* This routine walks the account group, gets all KVP values */
|
||||
/* This routine walks the account tree, gets all KVP values */
|
||||
|
||||
static gpointer
|
||||
static void
|
||||
restore_cb (Account *acc, void * cb_data)
|
||||
{
|
||||
PGBackend *be = (PGBackend *) cb_data;
|
||||
if (0 == acc->idata) return NULL;
|
||||
if (0 == acc->idata) return;
|
||||
acc->inst.kvp_data = pgendKVPFetch (be, acc->idata, acc->inst.kvp_data);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
pgendGetAllAccountKVP (PGBackend *be, AccountGroup *grp)
|
||||
pgendGetAllAccountKVP (PGBackend *be, Account *root)
|
||||
{
|
||||
if (!grp) return;
|
||||
if (!root) return;
|
||||
|
||||
xaccGroupForEachAccount (grp, restore_cb, be, TRUE);
|
||||
restore_cb(root, NULL);
|
||||
gnc_account_foreach_descendant(root, restore_cb, be);
|
||||
}
|
||||
|
||||
/* ============================================================= */
|
||||
@@ -319,8 +309,8 @@ get_account_cb (PGBackend *be, PGresult *result, int j, gpointer data)
|
||||
if (guid_equal(guid_null(), &acct_guid))
|
||||
{
|
||||
/* if the parent guid is null, then this
|
||||
* account belongs in the top group */
|
||||
xaccGroupInsertAccount (gnc_book_get_group(book), acc);
|
||||
* account belongs in the top level */
|
||||
gnc_account_append_child (gnc_book_get_root_account(book), acc);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -338,7 +328,7 @@ get_account_cb (PGBackend *be, PGresult *result, int j, gpointer data)
|
||||
else
|
||||
{
|
||||
xaccAccountBeginEdit(parent);
|
||||
xaccAccountInsertSubAccount(parent, acc);
|
||||
gnc_account_append_child(parent, acc);
|
||||
xaccAccountCommitEdit(parent);
|
||||
}
|
||||
}
|
||||
@@ -375,7 +365,7 @@ pgendGetAccounts (PGBackend *be, QofBook *book)
|
||||
|
||||
pgendGetCommodity (be, ri->commodity_string);
|
||||
commodity = gnc_string_to_commodity (ri->commodity_string,
|
||||
xaccAccountGetBook (ri->account));
|
||||
gnc_account_get_book(ri->account));
|
||||
|
||||
if (commodity)
|
||||
{
|
||||
@@ -403,7 +393,7 @@ pgendGetAccounts (PGBackend *be, QofBook *book)
|
||||
if (parent)
|
||||
{
|
||||
xaccAccountBeginEdit(parent);
|
||||
xaccAccountInsertSubAccount(parent, ri->account);
|
||||
gnc_account_append_child(parent, ri->account);
|
||||
xaccAccountCommitEdit(parent);
|
||||
}
|
||||
else
|
||||
@@ -441,13 +431,8 @@ pgendGetAllAccounts (PGBackend *be)
|
||||
for (node=be->blist; node; node=node->next)
|
||||
{
|
||||
QofBook *book = node->data;
|
||||
AccountGroup *topgrp = gnc_book_get_group (book);
|
||||
pgendGetAllAccountKVP (be, topgrp);
|
||||
|
||||
/* Mark the newly read group as saved, since the act of putting
|
||||
* it together will have caused it to be marked up as not-saved.
|
||||
*/
|
||||
xaccGroupMarkSaved (topgrp);
|
||||
Account *root = gnc_book_get_root_account(book);
|
||||
pgendGetAllAccountKVP (be, root);
|
||||
}
|
||||
|
||||
LEAVE (" ");
|
||||
@@ -457,7 +442,7 @@ void
|
||||
pgendGetAllAccountsInBook (PGBackend *be, QofBook *book)
|
||||
{
|
||||
char *p, buff[400];
|
||||
AccountGroup *topgrp;
|
||||
Account *root;
|
||||
|
||||
ENTER ("be=%p", be);
|
||||
if (!be || !book) return;
|
||||
@@ -474,13 +459,8 @@ pgendGetAllAccountsInBook (PGBackend *be, QofBook *book)
|
||||
SEND_QUERY (be, buff, );
|
||||
pgendGetAccounts (be, book);
|
||||
|
||||
topgrp = gnc_book_get_group (book);
|
||||
pgendGetAllAccountKVP (be, topgrp);
|
||||
|
||||
/* Mark the newly read group as saved, since the act of putting
|
||||
* it together will have caused it to be marked up as not-saved.
|
||||
*/
|
||||
xaccGroupMarkSaved (topgrp);
|
||||
root = gnc_book_get_root_account(book);
|
||||
pgendGetAllAccountKVP (be, root);
|
||||
|
||||
LEAVE (" ");
|
||||
}
|
||||
@@ -568,7 +548,6 @@ void
|
||||
pgend_account_commit_edit (QofBackend * bend,
|
||||
Account * acct)
|
||||
{
|
||||
AccountGroup *parent;
|
||||
char *p;
|
||||
QofBackendError err;
|
||||
PGBackend *be = (PGBackend *)bend;
|
||||
@@ -578,8 +557,6 @@ pgend_account_commit_edit (QofBackend * bend,
|
||||
|
||||
if (FALSE == acct->inst.dirty)
|
||||
{
|
||||
parent = xaccAccountGetParent(acct);
|
||||
if (parent) parent->saved = 1;
|
||||
LEAVE ("account not written because not dirty");
|
||||
return;
|
||||
}
|
||||
@@ -641,13 +618,6 @@ pgend_account_commit_edit (QofBackend * bend,
|
||||
SEND_QUERY (be,p,);
|
||||
FINISH_QUERY(be->connection);
|
||||
|
||||
/* Mark this up so that we don't get that annoying gui dialog
|
||||
* about having to save to file. unfortunately,however, this
|
||||
* is too liberal, and could screw up synchronization if we've lost
|
||||
* contact with the back end at some point. So hack alert -- fix
|
||||
* this. */
|
||||
parent = xaccAccountGetParent(acct);
|
||||
if (parent) parent->saved = 1;
|
||||
LEAVE ("commited");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#ifndef POSTGRES_ACCOUNT_H
|
||||
#define POSTGRES_ACCOUNT_H
|
||||
|
||||
#include "Group.h"
|
||||
#include "Account.h"
|
||||
#include "qof.h"
|
||||
|
||||
#include "PostgresBackend.h"
|
||||
@@ -33,8 +33,8 @@ void pgendGetAllAccountsInBook (PGBackend *be, QofBook *);
|
||||
|
||||
void pgendGetAllAccounts (PGBackend *be);
|
||||
|
||||
void pgendStoreGroup (PGBackend *be, AccountGroup *grp);
|
||||
void pgendStoreGroupNoLock (PGBackend *be, AccountGroup *grp,
|
||||
void pgendStoreAccountTree (PGBackend *be, Account *root);
|
||||
void pgendStoreAccountTreeNoLock (PGBackend *be, Account *root,
|
||||
gboolean do_mark, gboolean do_check_version);
|
||||
Account * pgendCopyAccountToEngine (PGBackend *be, const GUID *acct_guid);
|
||||
|
||||
|
||||
@@ -45,7 +45,6 @@
|
||||
#include "Account.h"
|
||||
#include "AccountP.h"
|
||||
#include "qof.h"
|
||||
#include "Group.h"
|
||||
#include "gnc-commodity.h"
|
||||
|
||||
#include "builder.h"
|
||||
@@ -235,11 +234,13 @@ done:
|
||||
/* recompute fresh balance checkpoints for every account */
|
||||
|
||||
void
|
||||
pgendGroupRecomputeAllCheckpoints (PGBackend *be, AccountGroup *grp)
|
||||
pgendAccountTreeRecomputeAllCheckpoints (PGBackend *be, Account *parent)
|
||||
{
|
||||
GList *acclist, *node;
|
||||
|
||||
acclist = xaccGroupGetSubAccounts(grp);
|
||||
pgendAccountRecomputeAllCheckpoints (be, xaccAccountGetGUID(parent));
|
||||
|
||||
acclist = gnc_account_get_descendants(parent);
|
||||
for (node = acclist; node; node=node->next)
|
||||
{
|
||||
Account *acc = (Account *) node->data;
|
||||
@@ -510,16 +511,16 @@ pgendAccountGetBalance (PGBackend *be, Account *acc, Timespec as_of_date)
|
||||
/* get checkpoint value for all accounts */
|
||||
|
||||
void
|
||||
pgendGroupGetAllBalances (PGBackend *be, AccountGroup *grp,
|
||||
pgendAccountTreeGetAllBalances (PGBackend *be, Account *root,
|
||||
Timespec as_of_date)
|
||||
{
|
||||
GList *acclist, *node;
|
||||
|
||||
if (!be || !grp) return;
|
||||
if (!be || !root) return;
|
||||
ENTER("be=%p", be);
|
||||
|
||||
/* loop over all accounts */
|
||||
acclist = xaccGroupGetSubAccounts (grp);
|
||||
acclist = gnc_account_get_descendants (root);
|
||||
for (node=acclist; node; node=node->next)
|
||||
{
|
||||
Account *acc = (Account *) node->data;
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
#define CHECKPOINT_H
|
||||
|
||||
#include "Account.h"
|
||||
#include "Group.h"
|
||||
#include "qof.h"
|
||||
#include "Transaction.h"
|
||||
|
||||
@@ -79,8 +78,8 @@ typedef struct _checkpoint {
|
||||
|
||||
void pgendTransactionRecomputeCheckpoints (PGBackend *be, Transaction *trans);
|
||||
void pgendAccountRecomputeOneCheckpoint (PGBackend *be, Account *acc, Timespec ts);
|
||||
void pgendGroupRecomputeAllCheckpoints (PGBackend *, AccountGroup *);
|
||||
void pgendGroupGetAllBalances (PGBackend *, AccountGroup *, Timespec as_of_date);
|
||||
void pgendAccountTreeRecomputeAllCheckpoints (PGBackend *, Account *);
|
||||
void pgendAccountTreeGetAllBalances (PGBackend *, Account *, Timespec as_of_date);
|
||||
|
||||
/* The pgendAccountGetBalance() routine goes to the sql database and finds the
|
||||
* balance as of the 'as_of_date' argument. It sets the starting balance for
|
||||
|
||||
@@ -290,16 +290,13 @@ pgendProcessEvents (QofBackend *bend)
|
||||
|
||||
/* if the remote user created an account, mirror it here */
|
||||
acc = pgendCopyAccountToEngine (be, &(ev->guid));
|
||||
xaccGroupMarkSaved (xaccAccountGetRoot(acc));
|
||||
ent = (QofEntity*)acc;
|
||||
break;
|
||||
}
|
||||
case QOF_EVENT_DESTROY: {
|
||||
Account * acc = pgendAccountLookup (be, &(ev->guid));
|
||||
AccountGroup *topgrp = xaccAccountGetRoot(acc);
|
||||
xaccAccountBeginEdit (acc);
|
||||
xaccAccountDestroy (acc);
|
||||
xaccGroupMarkSaved (topgrp);
|
||||
ent = (QofEntity*)acc;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -13,8 +13,8 @@ define(`account', `gncAccount, Account, Account, a,
|
||||
commodity, , char *, gnc_commodity_get_unique_name(xaccAccountGetCommodity(ptr)),
|
||||
version, , int32, xaccAccountGetVersion(ptr),
|
||||
iguid, , int32, ptr->idata,
|
||||
bookGUID, , GUID *, qof_entity_get_guid((QofEntity*)xaccAccountGetBook(ptr)),
|
||||
parentGUID, , GUID *, xaccAccountGetGUID(xaccAccountGetParentAccount(ptr)),
|
||||
bookGUID, , GUID *, qof_entity_get_guid((QofEntity*)gnc_account_get_book(ptr)),
|
||||
parentGUID, , GUID *, xaccAccountGetGUID(gnc_account_get_parent(ptr)),
|
||||
accountGUID, KEY, GUID *, xaccAccountGetGUID(ptr),
|
||||
')
|
||||
|
||||
|
||||
@@ -251,14 +251,12 @@ test_access(DbInfo *dbinfo, gboolean multi_user)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gpointer
|
||||
static void
|
||||
mark_account_commodities(Account * a, gpointer data)
|
||||
{
|
||||
GHashTable *hash = data;
|
||||
|
||||
g_hash_table_insert(hash, xaccAccountGetCommodity(a), hash);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -311,10 +309,10 @@ remove_unneeded_commodities(QofSession * session)
|
||||
|
||||
book = qof_session_get_book(session);
|
||||
|
||||
xaccGroupForEachAccount(gnc_book_get_group(book),
|
||||
mark_account_commodities, cdi.hash, TRUE);
|
||||
gnc_account_foreach_descendant(gnc_book_get_root_account(book),
|
||||
mark_account_commodities, cdi.hash);
|
||||
|
||||
xaccGroupForEachTransaction(gnc_book_get_group(book),
|
||||
xaccAccountTreeForEachTransaction(gnc_book_get_root_account(book),
|
||||
mark_transaction_commodities, cdi.hash);
|
||||
|
||||
gnc_pricedb_foreach_price(gnc_book_get_pricedb(book),
|
||||
@@ -473,16 +471,16 @@ num_trans_helper(Transaction * trans, gpointer data)
|
||||
static int
|
||||
session_num_trans(QofSession * session)
|
||||
{
|
||||
AccountGroup *group;
|
||||
Account *root;
|
||||
QofBook *book;
|
||||
int num = 0;
|
||||
|
||||
g_return_val_if_fail(session, 0);
|
||||
|
||||
book = qof_session_get_book(session);
|
||||
group = gnc_book_get_group(book);
|
||||
root = gnc_book_get_root_account(book);
|
||||
|
||||
xaccGroupForEachTransaction(group, num_trans_helper, &num);
|
||||
xaccAccountTreeForEachTransaction(root, num_trans_helper, &num);
|
||||
|
||||
return num;
|
||||
}
|
||||
@@ -626,7 +624,7 @@ compare_balances(QofSession * session_1, QofSession * session_2)
|
||||
|
||||
ok = TRUE;
|
||||
|
||||
list = xaccGroupGetSubAccounts(gnc_book_get_group(book_1));
|
||||
list = gnc_account_get_descendants(gnc_book_get_root_account(book_1));
|
||||
for (node = list; node; node = node->next) {
|
||||
Account *account_1 = node->data;
|
||||
Account *account_2;
|
||||
@@ -677,21 +675,21 @@ static gboolean
|
||||
test_queries(QofSession * session_base, DbInfo *dbinfo)
|
||||
{
|
||||
QueryTestData qtd;
|
||||
AccountGroup *group;
|
||||
Account *root;
|
||||
QofBook *book;
|
||||
gboolean ok;
|
||||
|
||||
g_return_val_if_fail(dbinfo->dbname && dbinfo->mode, FALSE);
|
||||
|
||||
book = qof_session_get_book(session_base);
|
||||
group = gnc_book_get_group(book);
|
||||
root = gnc_book_get_root_account(book);
|
||||
|
||||
qtd.session_base = session_base;
|
||||
qtd.dbinfo = dbinfo;
|
||||
qtd.loaded = 0;
|
||||
qtd.total = 0;
|
||||
|
||||
ok = xaccGroupForEachTransaction(group, test_trans_query, &qtd);
|
||||
ok = xaccAccountTreeForEachTransaction(root, test_trans_query, &qtd);
|
||||
|
||||
#if 0
|
||||
g_warning("average percentage loaded = %3.2f%%",
|
||||
@@ -708,8 +706,8 @@ typedef struct {
|
||||
QofBook *book_1;
|
||||
QofBook *book_2;
|
||||
|
||||
AccountGroup *group_1;
|
||||
AccountGroup *group_2;
|
||||
Account *root_1;
|
||||
Account *root_2;
|
||||
|
||||
GList *accounts_1;
|
||||
GList *accounts_2;
|
||||
@@ -834,8 +832,8 @@ test_updates_2(QofSession * session_base, DbInfo *dbinfo)
|
||||
|
||||
td.session_1 = session_base;
|
||||
td.book_1 = qof_session_get_book(session_base);
|
||||
td.group_1 = gnc_book_get_group(td.book_1);
|
||||
td.accounts_1 = xaccGroupGetSubAccounts(td.group_1);
|
||||
td.root_1 = gnc_book_get_root_account(td.book_1);
|
||||
td.accounts_1 = gnc_account_get_descendants(td.root_1);
|
||||
|
||||
td.session_2 = qof_session_new();
|
||||
|
||||
@@ -845,12 +843,12 @@ test_updates_2(QofSession * session_base, DbInfo *dbinfo)
|
||||
multi_user_get_everything(td.session_2, NULL);
|
||||
|
||||
td.book_2 = qof_session_get_book(td.session_2);
|
||||
td.group_2 = gnc_book_get_group(td.book_2);
|
||||
td.accounts_2 = xaccGroupGetSubAccounts(td.group_2);
|
||||
td.root_2 = gnc_book_get_root_account(td.book_2);
|
||||
td.accounts_2 = gnc_account_get_descendants(td.root_2);
|
||||
|
||||
ok = TRUE;
|
||||
transes = NULL;
|
||||
xaccGroupForEachTransaction(td.group_1, add_trans_helper, &transes);
|
||||
xaccAccountTreeForEachTransaction(td.root_1, add_trans_helper, &transes);
|
||||
for (node = transes; node; node = node->next) {
|
||||
ok = test_trans_update(node->data, &td);
|
||||
if (!ok)
|
||||
@@ -891,8 +889,8 @@ test_updates_2(QofSession * session_base, DbInfo *dbinfo)
|
||||
|
||||
xaccAccountBeginEdit(account);
|
||||
xaccAccountBeginEdit(child);
|
||||
xaccGroupInsertAccount(td.group_1, account);
|
||||
xaccAccountInsertSubAccount(account, child);
|
||||
gnc_account_append_child(td.root_1, account);
|
||||
gnc_account_append_child(account, child);
|
||||
xaccAccountCommitEdit(child);
|
||||
xaccAccountCommitEdit(account);
|
||||
|
||||
@@ -1128,8 +1126,8 @@ main (int argc, char **argv)
|
||||
set_max_kvp_depth(3);
|
||||
set_max_kvp_frame_elements(3);
|
||||
|
||||
set_max_group_depth(3);
|
||||
set_max_group_accounts(3);
|
||||
set_max_account_tree_depth(3);
|
||||
set_max_accounts_per_level(3);
|
||||
|
||||
random_timespec_zero_nsec(TRUE);
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
#include <time.h>
|
||||
|
||||
#include "Account.h"
|
||||
#include "Group.h"
|
||||
#include "Period.h"
|
||||
#include "qof.h"
|
||||
#include "test-stuff.h"
|
||||
@@ -43,9 +42,8 @@ run_test (void)
|
||||
QofBackendError io_err;
|
||||
QofSession *session;
|
||||
QofBook *openbook, *closedbook;
|
||||
AccountGroup *grp;
|
||||
AccountList *acclist, *anode;
|
||||
Account * acc = NULL;
|
||||
GList *acclist, *anode;
|
||||
Account *root, *acc = NULL;
|
||||
SplitList *splist;
|
||||
Split *sfirst, *slast;
|
||||
Transaction *tfirst, *tlast;
|
||||
@@ -72,9 +70,9 @@ run_test (void)
|
||||
|
||||
add_random_transactions_to_book (openbook, 12);
|
||||
|
||||
grp = gnc_book_get_group (openbook);
|
||||
root = gnc_book_get_root_account(openbook);
|
||||
|
||||
acclist = xaccGroupGetSubAccounts (grp);
|
||||
acclist = gnc_account_get_descendants (root);
|
||||
for (anode=acclist; anode; anode=anode->next)
|
||||
{
|
||||
int ns;
|
||||
@@ -83,6 +81,7 @@ run_test (void)
|
||||
if (2 <= ns) break;
|
||||
acc = NULL;
|
||||
}
|
||||
g_list_free(acclist);
|
||||
|
||||
if(!acc)
|
||||
{
|
||||
|
||||
@@ -31,8 +31,6 @@
|
||||
|
||||
#include "Account.h"
|
||||
#include "AccountP.h"
|
||||
#include "Group.h"
|
||||
#include "GroupP.h"
|
||||
#include "gnc-commodity.h"
|
||||
#include "gnc-engine.h"
|
||||
#include "gnc-pricedb.h"
|
||||
@@ -350,11 +348,11 @@ trans_traverse_cb (Transaction *trans, void *cb_data)
|
||||
|
||||
|
||||
void
|
||||
pgendStoreAllTransactions (PGBackend *be, AccountGroup *grp)
|
||||
pgendStoreAllTransactions (PGBackend *be, Account *root)
|
||||
{
|
||||
char *p;
|
||||
ENTER ("be=%p, grp=%p", be, grp);
|
||||
if (!be || !grp) return;
|
||||
ENTER ("be=%p, root=%p", be, root);
|
||||
if (!be || !root) return;
|
||||
|
||||
/* lock it up so that we store atomically */
|
||||
p = "BEGIN;\n"
|
||||
@@ -365,8 +363,8 @@ pgendStoreAllTransactions (PGBackend *be, AccountGroup *grp)
|
||||
|
||||
/* Recursively walk transactions. Start by reseting the write
|
||||
* flags. We use this to avoid infinite recursion */
|
||||
xaccGroupBeginStagedTransactionTraversals(grp);
|
||||
xaccGroupStagedTransactionTraversal (grp, 1, trans_traverse_cb, be);
|
||||
gnc_account_tree_begin_staged_transaction_traversals(root);
|
||||
gnc_account_tree_staged_transaction_traversal (root, 1, trans_traverse_cb, be);
|
||||
|
||||
p = "COMMIT;\n"
|
||||
"NOTIFY gncTransaction;";
|
||||
@@ -378,7 +376,7 @@ pgendStoreAllTransactions (PGBackend *be, AccountGroup *grp)
|
||||
if ((MODE_POLL == be->session_mode) ||
|
||||
(MODE_EVENT == be->session_mode))
|
||||
{
|
||||
pgendGroupRecomputeAllCheckpoints(be, grp);
|
||||
pgendAccountTreeRecomputeAllCheckpoints(be, root);
|
||||
}
|
||||
LEAVE(" ");
|
||||
}
|
||||
@@ -503,8 +501,6 @@ pgendCopySplitsToEngine (PGBackend *be, Transaction *trans)
|
||||
|
||||
if (acc)
|
||||
{
|
||||
int save_state;
|
||||
|
||||
if (acc != previous_acc)
|
||||
{
|
||||
xaccAccountCommitEdit (previous_acc);
|
||||
@@ -512,15 +508,7 @@ pgendCopySplitsToEngine (PGBackend *be, Transaction *trans)
|
||||
previous_acc = acc;
|
||||
}
|
||||
|
||||
if (acc->parent)
|
||||
save_state = acc->parent->saved;
|
||||
else
|
||||
save_state = 1;
|
||||
|
||||
xaccAccountInsertSplit(acc, s);
|
||||
|
||||
if (acc->parent)
|
||||
acc->parent->saved = save_state;
|
||||
}
|
||||
|
||||
/* It's ok to set value without an account, since
|
||||
@@ -570,21 +558,12 @@ pgendCopySplitsToEngine (PGBackend *be, Transaction *trans)
|
||||
if (account)
|
||||
{
|
||||
gnc_numeric amount;
|
||||
int save_state;
|
||||
int acct_frac;
|
||||
|
||||
if (account->parent)
|
||||
save_state = account->parent->saved;
|
||||
else
|
||||
save_state = 1;
|
||||
|
||||
xaccAccountBeginEdit (account);
|
||||
xaccAccountInsertSplit (account, sri->split);
|
||||
xaccAccountCommitEdit (account);
|
||||
|
||||
if (account->parent)
|
||||
account->parent->saved = save_state;
|
||||
|
||||
acct_frac = xaccAccountGetCommoditySCU (account);
|
||||
amount = gnc_numeric_create (sri->amount, acct_frac);
|
||||
xaccSplitSetAmount (sri->split, amount);
|
||||
@@ -1053,19 +1032,6 @@ pgend_trans_commit_edit (QofBackend * bend,
|
||||
pgendTransactionRecomputeCheckpoints (be, trans);
|
||||
}
|
||||
|
||||
/* hack alert -- the following code will get rid of that annoying
|
||||
* message from the GUI about saving one's data. However, it doesn't
|
||||
* do the right thing if the connection to the backend was ever lost.
|
||||
* what should happen is the user should get a chance to
|
||||
* resynchronize their data with the backend, before quiting out.
|
||||
*/
|
||||
{
|
||||
Split * s = xaccTransGetSplit (trans, 0);
|
||||
Account *acc = xaccSplitGetAccount (s);
|
||||
AccountGroup *top = xaccAccountGetRoot (acc);
|
||||
xaccGroupMarkSaved (top);
|
||||
}
|
||||
|
||||
LEAVE ("commited");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "Group.h"
|
||||
#include "qof.h"
|
||||
#include "Transaction.h"
|
||||
|
||||
@@ -45,7 +44,7 @@
|
||||
int pgendCopyTransactionToEngine (PGBackend *be, const GUID *trans_guid);
|
||||
void pgendCopySplitsToEngine (PGBackend *be, Transaction *trans);
|
||||
|
||||
void pgendStoreAllTransactions (PGBackend *be, AccountGroup *grp);
|
||||
void pgendStoreAllTransactions (PGBackend *be, Account *root);
|
||||
void pgendStoreTransactionNoLock (PGBackend *be, Transaction *trans, gboolean do_check_version);
|
||||
|
||||
void pgend_trans_commit_edit (QofBackend * bend, Transaction * trans, Transaction * oldtrans);
|
||||
|
||||
@@ -31,8 +31,6 @@
|
||||
|
||||
#include "Account.h"
|
||||
#include "AccountP.h"
|
||||
#include "Group.h"
|
||||
#include "GroupP.h"
|
||||
#include "gnc-commodity.h"
|
||||
#include "gnc-engine.h"
|
||||
#include "Transaction.h"
|
||||
@@ -215,7 +213,7 @@ pgendGetMassTransactions (PGBackend *be, QofBook *book)
|
||||
{
|
||||
char *p, buff[900];
|
||||
GList *node, *xaction_list = NULL;
|
||||
AccountGroup *grp;
|
||||
Account *root;
|
||||
|
||||
qof_event_suspend();
|
||||
pgendDisable(be);
|
||||
@@ -233,8 +231,8 @@ pgendGetMassTransactions (PGBackend *be, QofBook *book)
|
||||
SEND_QUERY (be, buff, );
|
||||
|
||||
/* restore the transactions */
|
||||
grp = gnc_book_get_group (book);
|
||||
xaccAccountGroupBeginEdit (grp);
|
||||
root = gnc_book_get_root_account (book);
|
||||
xaccAccountBeginEdit (root);
|
||||
|
||||
be->tmp_return = NULL;
|
||||
pgendGetResults (be, get_mass_trans_cb, book);
|
||||
@@ -280,7 +278,7 @@ pgendGetMassTransactions (PGBackend *be, QofBook *book)
|
||||
}
|
||||
g_list_free(xaction_list);
|
||||
|
||||
xaccAccountGroupCommitEdit (grp);
|
||||
xaccAccountCommitEdit (root);
|
||||
|
||||
pgendEnable(be);
|
||||
qof_event_resume();
|
||||
|
||||
@@ -1262,7 +1262,7 @@ gncOwnerApplyPayment (GncOwner *owner, GncInvoice* invoice,
|
||||
g_return_val_if_fail (owner->owner.undefined != NULL, NULL);
|
||||
|
||||
/* Compute the ancillary data */
|
||||
book = xaccAccountGetBook (posted_acc);
|
||||
book = gnc_account_get_book (posted_acc);
|
||||
name = gncOwnerGetName (gncOwnerGetEndOwner (owner));
|
||||
commodity = gncOwnerGetCurrency (owner);
|
||||
reverse = (gncOwnerGetType (owner) == GNC_OWNER_CUSTOMER);
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
#include <gtk/gtk.h>
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
#include "Group.h"
|
||||
#include "Account.h"
|
||||
#include "gnc-ui-util.h"
|
||||
#include "qof.h"
|
||||
@@ -318,7 +317,7 @@ gnc_fill_account_select_combo (GtkWidget *combo, GNCBook *book,
|
||||
/* Figure out if anything is set in the combo */
|
||||
text = gtk_combo_box_get_active_text(GTK_COMBO_BOX(combo));
|
||||
|
||||
list = xaccGroupGetSubAccounts (gnc_book_get_group (book));
|
||||
list = gnc_account_get_descendants (gnc_book_get_root_account (book));
|
||||
|
||||
/* Clear the existing list */
|
||||
entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(combo)));
|
||||
|
||||
@@ -255,7 +255,7 @@ gnc_payment_ok_cb (GtkWidget *widget, gpointer data)
|
||||
return;
|
||||
}
|
||||
|
||||
post = xaccGetAccountFromFullName (gnc_book_get_group (pw->book), text);
|
||||
post = gnc_account_lookup_by_full_name (gnc_book_get_root_account (pw->book), text);
|
||||
|
||||
if (!post) {
|
||||
char *msg = g_strdup_printf (
|
||||
|
||||
@@ -886,7 +886,7 @@ gnc_plugin_business_cmd_test_init_data (GtkAction *action,
|
||||
GncInvoice *invoice = gncInvoiceCreate(book);
|
||||
GncOwner *owner = gncOwnerCreate();
|
||||
GncJob *job = gncJobCreate(book);
|
||||
AccountGroup *group = xaccGetAccountGroup(book);
|
||||
Account *root = gnc_book_get_root_account(book);
|
||||
Account *inc_acct = xaccMallocAccount(book);
|
||||
Account *bank_acct = xaccMallocAccount(book);
|
||||
Account *tax_acct = xaccMallocAccount(book);
|
||||
@@ -925,25 +925,25 @@ gnc_plugin_business_cmd_test_init_data (GtkAction *action,
|
||||
xaccAccountSetType(ar_acct, ACCT_TYPE_RECEIVABLE);
|
||||
xaccAccountSetName(ar_acct, "A/R");
|
||||
xaccAccountSetCommodity(ar_acct, gnc_default_currency());
|
||||
xaccGroupInsertAccount(group, ar_acct);
|
||||
gnc_account_append_child(root, ar_acct);
|
||||
|
||||
// Create the Income account
|
||||
xaccAccountSetType(inc_acct, ACCT_TYPE_INCOME);
|
||||
xaccAccountSetName(inc_acct, "Income");
|
||||
xaccAccountSetCommodity(inc_acct, gnc_default_currency());
|
||||
xaccGroupInsertAccount(group, inc_acct);
|
||||
gnc_account_append_child(root, inc_acct);
|
||||
|
||||
// Create the Bank account
|
||||
xaccAccountSetType(bank_acct, ACCT_TYPE_BANK);
|
||||
xaccAccountSetName(bank_acct, "Bank");
|
||||
xaccAccountSetCommodity(bank_acct, gnc_default_currency());
|
||||
xaccGroupInsertAccount(group, bank_acct);
|
||||
gnc_account_append_child(root, bank_acct);
|
||||
|
||||
// Create the Tax account
|
||||
xaccAccountSetType(tax_acct, ACCT_TYPE_LIABILITY);
|
||||
xaccAccountSetName(tax_acct, "Tax-Holding");
|
||||
xaccAccountSetCommodity(tax_acct, gnc_default_currency());
|
||||
xaccGroupInsertAccount(group, tax_acct);
|
||||
gnc_account_append_child(root, tax_acct);
|
||||
|
||||
// Launch the invoice editor
|
||||
gnc_ui_invoice_edit(invoice);
|
||||
|
||||
@@ -542,7 +542,7 @@ gnc_plugin_page_invoice_cmd_new_account (GtkAction *action,
|
||||
g_return_if_fail(GNC_IS_PLUGIN_PAGE_INVOICE(plugin_page));
|
||||
|
||||
ENTER("(action %p, plugin_page %p)", action, plugin_page);
|
||||
gnc_ui_new_account_window (NULL);
|
||||
gnc_ui_new_account_window (gnc_get_current_book(), NULL);
|
||||
LEAVE(" ");
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ gnc_entry_ledger_get_account_by_name (GncEntryLedger *ledger, BasicCell * bcell,
|
||||
Account *account;
|
||||
|
||||
/* Find the account */
|
||||
account = xaccGetAccountFromFullName (gnc_get_current_group (), name);
|
||||
account = gnc_account_lookup_by_full_name (gnc_get_current_root_account (), name);
|
||||
|
||||
if (!account) {
|
||||
/* Ask if they want to create a new one. */
|
||||
|
||||
@@ -180,13 +180,13 @@ skip_income_acct_cb (Account *account, gpointer user_data)
|
||||
static void
|
||||
load_xfer_type_cells (GncEntryLedger *ledger)
|
||||
{
|
||||
AccountGroup *group;
|
||||
Account *root;
|
||||
ComboCell *cell;
|
||||
QuickFill *qf=NULL;
|
||||
GtkListStore *store = NULL;
|
||||
|
||||
group = gnc_book_get_group (ledger->book);
|
||||
if (group == NULL) return;
|
||||
root = gnc_book_get_root_account (ledger->book);
|
||||
if (root == NULL) return;
|
||||
|
||||
/* Use a common, shared quickfill. For the ORDER or INVOICE,
|
||||
* ledgers, we don't want expense-type accounts in the menu.
|
||||
@@ -198,9 +198,9 @@ load_xfer_type_cells (GncEntryLedger *ledger)
|
||||
case GNCENTRY_ORDER_VIEWER:
|
||||
case GNCENTRY_INVOICE_ENTRY:
|
||||
case GNCENTRY_INVOICE_VIEWER:
|
||||
qf = gnc_get_shared_account_name_quickfill (group, IKEY,
|
||||
qf = gnc_get_shared_account_name_quickfill (root, IKEY,
|
||||
skip_expense_acct_cb, NULL);
|
||||
store = gnc_get_shared_account_name_list_store (group, IKEY,
|
||||
store = gnc_get_shared_account_name_list_store (root, IKEY,
|
||||
skip_expense_acct_cb, NULL);
|
||||
break;
|
||||
|
||||
@@ -209,9 +209,9 @@ load_xfer_type_cells (GncEntryLedger *ledger)
|
||||
case GNCENTRY_EXPVOUCHER_ENTRY:
|
||||
case GNCENTRY_EXPVOUCHER_VIEWER:
|
||||
case GNCENTRY_NUM_REGISTER_TYPES:
|
||||
qf = gnc_get_shared_account_name_quickfill (group, EKEY,
|
||||
qf = gnc_get_shared_account_name_quickfill (root, EKEY,
|
||||
skip_income_acct_cb, NULL);
|
||||
store = gnc_get_shared_account_name_list_store (group, EKEY,
|
||||
store = gnc_get_shared_account_name_list_store (root, EKEY,
|
||||
skip_income_acct_cb, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -626,20 +626,19 @@
|
||||
document))
|
||||
|
||||
(define (find-first-account type)
|
||||
(define (find-first group num index)
|
||||
(define (find-first account num index)
|
||||
(if (>= index num)
|
||||
'()
|
||||
(let* ((this-account (xaccGroupGetAccount group index))
|
||||
(account-type (xaccAccountGetType this-account)))
|
||||
(let* ((this-child (gnc-account-nth-child account index))
|
||||
(account-type (xaccAccountGetType this-child)))
|
||||
(if (eq? account-type type)
|
||||
this-account
|
||||
(find-first group num (+ index 1))))))
|
||||
this-child
|
||||
(find-first account num (+ index 1))))))
|
||||
|
||||
(let* ((current-group (gnc-get-current-group))
|
||||
(num-accounts (xaccGroupGetNumAccounts
|
||||
current-group)))
|
||||
(let* ((current-root (gnc-get-current-root-account))
|
||||
(num-accounts (gnc-account-n-children current-root)))
|
||||
(if (> num-accounts 0)
|
||||
(find-first current-group num-accounts 0)
|
||||
(find-first current-root num-accounts 0)
|
||||
'())))
|
||||
|
||||
(define (find-first-account-for-owner owner)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -32,8 +32,7 @@
|
||||
(e.g. "IBM", "McDonald's"), a currency (e.g. "USD", "GBP"), or
|
||||
anything added to the commodity table.
|
||||
|
||||
Accounts can be arranged in a hierarchical tree. The nodes of the tree
|
||||
are called "Account Groups" (@pxref{Account Groups}). By accounting
|
||||
Accounts can be arranged in a hierarchical tree. By accounting
|
||||
convention, the value of an Account is equal to the value of all of its
|
||||
Splits plus the value of all of its sub-Accounts.
|
||||
@{ */
|
||||
@@ -57,6 +56,9 @@ typedef gnc_numeric (*xaccGetBalanceInCurrencyFn) (
|
||||
typedef gnc_numeric (*xaccGetBalanceAsOfDateFn) (
|
||||
Account *account, time_t date);
|
||||
|
||||
typedef void (*AccountCb)(Account *a, gpointer data);
|
||||
typedef gpointer (*AccountCb2)(Account *a, gpointer data);
|
||||
|
||||
#define GNC_IS_ACCOUNT(obj) (QOF_CHECK_TYPE((obj), GNC_ID_ACCOUNT))
|
||||
#define GNC_ACCOUNT(obj) (QOF_CHECK_CAST((obj), GNC_ID_ACCOUNT, Account))
|
||||
|
||||
@@ -121,17 +123,19 @@ typedef enum
|
||||
|
||||
ACCT_TYPE_PAYABLE = 12, /**< A/P account type */
|
||||
|
||||
NUM_ACCOUNT_TYPES = 13, /**< stop here; the following types
|
||||
ACCT_TYPE_ROOT = 13, /**< The hidden root account of an account tree. */
|
||||
|
||||
NUM_ACCOUNT_TYPES = 14, /**< stop here; the following types
|
||||
* just aren't ready for prime time */
|
||||
|
||||
/* bank account types */
|
||||
ACCT_TYPE_CHECKING = 13, /**< bank account type -- don't use this
|
||||
ACCT_TYPE_CHECKING = 14, /**< bank account type -- don't use this
|
||||
* for now, see NUM_ACCOUNT_TYPES */
|
||||
ACCT_TYPE_SAVINGS = 14, /**< bank account type -- don't use this for
|
||||
ACCT_TYPE_SAVINGS = 15, /**< bank account type -- don't use this for
|
||||
* now, see NUM_ACCOUNT_TYPES */
|
||||
ACCT_TYPE_MONEYMRKT = 15, /**< bank account type -- don't use this
|
||||
ACCT_TYPE_MONEYMRKT = 16, /**< bank account type -- don't use this
|
||||
* for now, see NUM_ACCOUNT_TYPES */
|
||||
ACCT_TYPE_CREDITLINE = 16, /**< line of credit -- don't use this for
|
||||
ACCT_TYPE_CREDITLINE = 17, /**< line of credit -- don't use this for
|
||||
* now, see NUM_ACCOUNT_TYPES */
|
||||
} GNCAccountType;
|
||||
|
||||
@@ -143,6 +147,9 @@ typedef enum
|
||||
/** Constructor */
|
||||
Account * xaccMallocAccount (QofBook *book);
|
||||
|
||||
/** Create a new root level account. */
|
||||
Account * gnc_account_create_root (QofBook *book);
|
||||
|
||||
/** The xaccCloneAccount() does the same as xaccCloneAccountSimple(),
|
||||
* except that it also also places a pair of GUID-pointers
|
||||
* of each account to the other, in the other's kvp slot.
|
||||
@@ -205,8 +212,10 @@ const gchar *gnc_get_account_separator_string (void);
|
||||
gunichar gnc_get_account_separator (void);
|
||||
void gnc_set_account_separator (const gchar *separator);
|
||||
|
||||
Account *gnc_book_get_root_account(QofBook *book);
|
||||
void gnc_book_set_root_account(QofBook *book, Account *root);
|
||||
|
||||
/** @deprecated */
|
||||
#define xaccAccountGetBook(X) qof_instance_get_book(QOF_INSTANCE(X))
|
||||
#define xaccAccountGetGUID(X) qof_entity_get_guid(QOF_ENTITY(X))
|
||||
#define xaccAccountReturnGUID(X) (X ? *(qof_entity_get_guid(QOF_ENTITY(X))) : *(guid_null()))
|
||||
|
||||
@@ -223,6 +232,7 @@ Account * xaccAccountLookup (const GUID *guid, QofBook *book);
|
||||
/** @name Account general setters/getters
|
||||
@{ */
|
||||
|
||||
QofBook *gnc_account_get_book(const Account *account);
|
||||
/** Set the account's type */
|
||||
void xaccAccountSetType (Account *account, GNCAccountType);
|
||||
/** Set the account's name */
|
||||
@@ -445,32 +455,278 @@ gnc_numeric xaccAccountGetBalanceChangeForPeriod (
|
||||
@{
|
||||
*/
|
||||
|
||||
/** This routine returns the group holding the set of subaccounts
|
||||
* for this account. */
|
||||
AccountGroup * xaccAccountGetChildren (const Account *account);
|
||||
|
||||
/** This routine returns the group which contains this account.
|
||||
*/
|
||||
AccountGroup * xaccAccountGetParent (const Account *account);
|
||||
|
||||
/** This routine returns the parent of the group that is the parent
|
||||
* of this account. It is equivalent to the nested call
|
||||
* xaccGroupGetParentAccount (xaccAccountGetParent ())
|
||||
* Note that if the account is in the root group node, then its
|
||||
* parent will be NULL.
|
||||
*/
|
||||
Account * xaccAccountGetParentAccount (const Account *account);
|
||||
|
||||
/** This routine returns a flat list of all of the accounts
|
||||
* that are descendents of this account. This includes not
|
||||
* only the the children, but the children of the children, etc.
|
||||
* This routine is equivalent to the nested calls
|
||||
* xaccGroupGetSubAccounts (xaccAccountGetChildren())
|
||||
/** This function will remove from the child account any pre-existing
|
||||
* parent relationship, and will then add the account as a child of
|
||||
* the new parent. The exception to this is when the old and new
|
||||
* parent accounts are the same, in which case this function does
|
||||
* nothing.
|
||||
*
|
||||
* The returned list should be freed with g_list_free() when
|
||||
* no longer needed.
|
||||
* If the child account belongs to a different book than the
|
||||
* specified new parent account, the child will be removed from the
|
||||
* other book (and thus, the other book's entity tables, generating a
|
||||
* destroy event), and will be added to the new book (generating a
|
||||
* create event).
|
||||
*
|
||||
* @param new_parent The new parent account to which the child should
|
||||
* be attached.
|
||||
*
|
||||
* @param child The account to attach.
|
||||
*/
|
||||
GList * xaccAccountGetDescendants (const Account *account);
|
||||
void gnc_account_append_child (Account *new_parent, Account *child);
|
||||
|
||||
/** This function will remove the speified child account from the
|
||||
* specified parent account. It will NOT free the associated memory
|
||||
* or otherwise alter the account: the account can now be reparented
|
||||
* to a new location. Note, however, that it will mark the old
|
||||
* parents as having been modified.
|
||||
*
|
||||
* @param parent The parent account from which the child should be
|
||||
* removed.
|
||||
*
|
||||
* @param child The child account to remove. */
|
||||
void gnc_account_remove_child (Account *parent, Account *child);
|
||||
|
||||
/** This routine returns a pointer to the parent of the specified
|
||||
* account. If the account has no parent, i.e it is either the root
|
||||
* node or is a disconnected account, then its parent will be NULL.
|
||||
*
|
||||
* @param account A pointer to any exiting account.
|
||||
*
|
||||
* @return A pointer to the parent account node, or NULL if there is
|
||||
* no parent account. */
|
||||
Account * gnc_account_get_parent (const Account *account);
|
||||
|
||||
/** This routine returns the root account of the account tree that the
|
||||
* specified account belongs to. It is the equivalent of repeatedly
|
||||
* calling the gnc_account_get_parent() routine until that routine
|
||||
* returns NULL.
|
||||
*
|
||||
* @param account A pointer to any existing account.
|
||||
*
|
||||
* @return The root node of the account tree to which this account
|
||||
* belongs. NULL if the account is not part of any account tree. */
|
||||
Account * gnc_account_get_root (Account *account);
|
||||
|
||||
/** This routine indicates whether the spcified account is the root
|
||||
* node of an account tree.
|
||||
*
|
||||
* @param account A pointer to any account.
|
||||
*
|
||||
* @return TRUE if this account is of type ROOT. FALSE otherwise. */
|
||||
gboolean gnc_account_is_root (const Account *account);
|
||||
|
||||
/** This routine returns a GList of all children of the specified
|
||||
* account. This function only returns the immediate children of the
|
||||
* specified account. For a list of all descendant accounts, use the
|
||||
* gnc_account_get_descendants() function.
|
||||
*
|
||||
* @param account The account whose children should be returned.
|
||||
*
|
||||
* @return A GList of account pointers, or NULL if there are no
|
||||
* children. It is the callers responsibility to free any returned
|
||||
* list with the g_list_free() function. */
|
||||
GList *gnc_account_get_children (const Account *account);
|
||||
GList *gnc_account_get_children_sorted (const Account *account);
|
||||
|
||||
/** Return the number of children of the specified account. The
|
||||
* returned number does not include the account itself.
|
||||
*
|
||||
* @param account The account to query.
|
||||
*
|
||||
* @return The number of children of the specified account. */
|
||||
gint gnc_account_n_children (const Account *account);
|
||||
|
||||
/** Return the index of the specified child within the list of the
|
||||
* parent's children. The first child index is 0. This function
|
||||
* returns -1 if the parent account is NULL of if the specified child
|
||||
* does not belong to the parent account.
|
||||
*
|
||||
* @param parent The parent account to check.
|
||||
*
|
||||
* @param child The child account to find.
|
||||
*
|
||||
* @return The index of the child account within the specified
|
||||
* parent, or -1. */
|
||||
gint gnc_account_child_index (const Account *parent, const Account *child);
|
||||
|
||||
/** Return the n'th child account of the specified parent account. If
|
||||
* the parent account is not specified or the child index number is
|
||||
* invalid, this function returns NULL.
|
||||
*
|
||||
* @param parent The parent account to check.
|
||||
*
|
||||
* @param num The index number of the child account that should be
|
||||
* returned.
|
||||
*
|
||||
* @return A pointer to the specified child account, or NULL */
|
||||
Account *gnc_account_nth_child (const Account *parent, gint num);
|
||||
|
||||
/** This routine returns a flat list of all of the accounts that are
|
||||
* descendants of the specified account. This includes not only the
|
||||
* the children, but the children of the children, etc. For a list of
|
||||
* only the immediate child accounts, use the
|
||||
* gnc_account_get_children() function. Within each set of child
|
||||
* accounts, the accounts returned by this function are unordered.
|
||||
* For a list of descendants where each set of children is sorted via
|
||||
* the standard account sort function, use the
|
||||
* gnc_account_get_descendants_sorted() function.
|
||||
*
|
||||
* @param account The account whose descendants should be returned.
|
||||
*
|
||||
* @return A GList of account pointers, or NULL if there are no
|
||||
* descendants. It is the callers responsibility to free any returned
|
||||
* list with the g_list_free() function. */
|
||||
GList * gnc_account_get_descendants (const Account *account);
|
||||
|
||||
/** This function returns a GList containing all the descendants of
|
||||
* the specified account, sorted at each level. This includes not
|
||||
* only the the children, but the children of the children, etc.
|
||||
* Within each set of child accounts, the accounts returned by this
|
||||
* function are ordered via the standard account sort function. For
|
||||
* a list of descendants where each set of children is unordered, use
|
||||
* the gnc_account_get_descendants() function.
|
||||
*
|
||||
* Note: Use this function where the results are intended for display
|
||||
* to the user. If the results are internal to GnuCash or will be
|
||||
* resorted at som later point in time you should use the
|
||||
* gnc_account_get_descendants() function.
|
||||
*
|
||||
* @param account The account whose descendants should be returned.
|
||||
*
|
||||
* @return A GList of account pointers, or NULL if there are no
|
||||
* descendants. It is the callers responsibility to free any returned
|
||||
* list with the g_list_free() function. */
|
||||
GList *gnc_account_get_descendants_sorted (const Account *account);
|
||||
|
||||
/** Return the number of descendants of the specified account. The
|
||||
* returned number does not include the account itself.
|
||||
*
|
||||
* @param account The account to query.
|
||||
*
|
||||
* @return The number of descendants of the specified account. */
|
||||
gint gnc_account_n_descendants (const Account *account);
|
||||
|
||||
/** Return the number of levels of this account below the root
|
||||
* account.
|
||||
*
|
||||
* @param account The account to query.
|
||||
*
|
||||
* @return The number of levels below the root. */
|
||||
gint gnc_account_get_current_depth (const Account *account);
|
||||
|
||||
/** Return the number of levels of descendants accounts below the
|
||||
* specified account. The returned number does not include the
|
||||
* specifed account itself.
|
||||
*
|
||||
* @param account The account to query.
|
||||
*
|
||||
* @return The number of levels of descendants. */
|
||||
gint gnc_account_get_tree_depth (const Account *account);
|
||||
|
||||
/** @name ForEach
|
||||
@{
|
||||
*/
|
||||
|
||||
/** This method will traverse the immediate children of this accounts,
|
||||
* calling 'func' on each account. This function traverses all
|
||||
* children nodes. To traverse only a subset of the child nodes use
|
||||
* the gnc_account_foreach_child_until() function.
|
||||
*
|
||||
* @param account A pointer to the account on whose children the
|
||||
* function should be called.
|
||||
*
|
||||
* @param func A function taking two arguments, an Account and a
|
||||
* gpointer.
|
||||
*
|
||||
* @param user_data This data will be passed to each call of func. */
|
||||
void gnc_account_foreach_child (const Account *account,
|
||||
AccountCb func, gpointer user_data);
|
||||
|
||||
/** This method will traverse the immediate children of this accounts,
|
||||
* calling 'func' on each account. Traversal will stop when func
|
||||
* returns a non-null value, and the routine will return with that
|
||||
* value. Therefore, this function will return null iff func returns
|
||||
* null for every account. For a simpler function that always
|
||||
* traverses all children nodes, use the gnc_account_foreach_child()
|
||||
* function.
|
||||
*
|
||||
* @param account A pointer to the account on whose children the
|
||||
* function should be called.
|
||||
*
|
||||
* @param func A function taking two arguments, an Account and a
|
||||
* gpointer.
|
||||
*
|
||||
* @param user_data This data will be passed to each call of func. */
|
||||
gpointer gnc_account_foreach_child_until (const Account *account,
|
||||
AccountCb2 func, gpointer user_data);
|
||||
|
||||
|
||||
/** This method will traverse all children of this accounts and their
|
||||
* descendants, calling 'func' on each account. This function
|
||||
* traverses all descendant nodes. To traverse only a subset of the
|
||||
* descendant nodes use the gnc_account_foreach_descendant_until()
|
||||
* function.
|
||||
*
|
||||
* @param account A pointer to the account on whose descendants the
|
||||
* function should be called.
|
||||
*
|
||||
* @param func A function taking two arguments, an Account and a
|
||||
* gpointer.
|
||||
*
|
||||
* @param user_data This data will be passed to each call of func. */
|
||||
void gnc_account_foreach_descendant (const Account *account,
|
||||
AccountCb func, gpointer user_data);
|
||||
|
||||
/** This method will traverse all children of this accounts and their
|
||||
* descendants, calling 'func' on each account. Traversal will stop
|
||||
* when func returns a non-null value, and the routine will return
|
||||
* with that value. Therefore, this function will return null iff
|
||||
* func returns null for every account. For a simpler function that
|
||||
* always traverses all children nodes, use the
|
||||
* gnc_account_foreach_descendant() function.
|
||||
*
|
||||
* @param account A pointer to the account on whose descendants the
|
||||
* function should be called.
|
||||
*
|
||||
* @param func A function taking two arguments, an Account and a
|
||||
* gpointer.
|
||||
*
|
||||
* @param user_data This data will be passed to each call of func. */
|
||||
gpointer gnc_account_foreach_descendant_until (const Account *account,
|
||||
AccountCb2 func, gpointer user_data);
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
/** @name Concatenation, Merging
|
||||
@{
|
||||
*/
|
||||
|
||||
/** The gnc_account_join_children() subroutine will move (reparent)
|
||||
* all child accounts from the from_parent account to the to_parent
|
||||
* account, preserving the account heirarchy. It will also take care
|
||||
* that the moved accounts will have the to_parent's book parent
|
||||
* as well.
|
||||
*/
|
||||
void gnc_account_join_children (Account *to_parent, Account *from_parent);
|
||||
|
||||
/** The gnc_account_copy_children() subroutine will copy all child
|
||||
* accounts from the "src" account to the "dest" account, preserving
|
||||
* the account heirarchy. It will also take care that the moved
|
||||
* accounts will have the "dest" account's book parent as well. This
|
||||
* routine will *NOT* copy any splits/transactions. It will copy the
|
||||
* KVP trees in each account.
|
||||
*/
|
||||
void gnc_account_copy_children (Account *dest, Account *src);
|
||||
|
||||
/** The gnc_account_merge_children() subroutine will go through an
|
||||
* account, merging all child accounts that have the same name and
|
||||
* description. This function is useful when importing Quicken(TM)
|
||||
* files.
|
||||
*/
|
||||
void gnc_account_merge_children (Account *parent);
|
||||
|
||||
/** @} */
|
||||
|
||||
/** DOCUMENT ME! */
|
||||
void xaccAccountSetReconcileChildrenStatus(Account *account, gboolean status);
|
||||
@@ -489,6 +745,28 @@ gboolean xaccAccountHasAncestor(const Account *acc, const Account *ancestor);
|
||||
|
||||
/** @} */
|
||||
|
||||
/** @name Getting Accounts and Subaccounts by Name
|
||||
@{
|
||||
*/
|
||||
/** The gnc_account_lookup_by_name() subroutine fetches the account by
|
||||
* name from the descendants of the specified account. The immediate
|
||||
* children are searched first. If there is no match,, then a
|
||||
* recursive search of all descendants is performed looking for a
|
||||
* match.
|
||||
*
|
||||
* @return A pointer to the account with the specified name, or NULL
|
||||
* if the account was not found.
|
||||
*/
|
||||
Account *gnc_account_lookup_by_name (const Account *parent, const char *name);
|
||||
|
||||
/** The gnc_account_lookup_full_name() subroutine works like
|
||||
* gnc_account_lookup_by_name, but uses fully-qualified names using the
|
||||
* given separator.
|
||||
*/
|
||||
Account *gnc_account_lookup_by_full_name (const Account *any_account,
|
||||
const gchar *name);
|
||||
|
||||
/** @} */
|
||||
|
||||
/* ------------------ */
|
||||
|
||||
@@ -694,7 +972,7 @@ typedef enum
|
||||
/** Get the "placeholder" flag for an account. If this flag is set
|
||||
* then the account may not be modified by the user.
|
||||
*
|
||||
* @param acc The account whose flag should be retrieved.
|
||||
* @param account The account whose flag should be retrieved.
|
||||
*
|
||||
* @return The current state of the account's "placeholder" flag. */
|
||||
gboolean xaccAccountGetPlaceholder (const Account *account);
|
||||
@@ -702,13 +980,13 @@ gboolean xaccAccountGetPlaceholder (const Account *account);
|
||||
/** Set the "placeholder" flag for an account. If this flag is set
|
||||
* then the account may not be modified by the user.
|
||||
*
|
||||
* @param acc The account whose flag should be retrieved.
|
||||
* @param account The account whose flag should be retrieved.
|
||||
*
|
||||
* @param val The new state for the account's "placeholder" flag. */
|
||||
void xaccAccountSetPlaceholder (Account *account, gboolean option);
|
||||
void xaccAccountSetPlaceholder (Account *account, gboolean val);
|
||||
|
||||
/** Returns PLACEHOLDER_NONE if account is NULL or neither account nor
|
||||
* any descendent of account is a placeholder. If account is a
|
||||
* any descendant of account is a placeholder. If account is a
|
||||
* placeholder, returns PLACEHOLDER_THIS. Otherwise, if any
|
||||
* descendant of account is a placeholder, return PLACEHOLDER_CHILD.
|
||||
*/
|
||||
@@ -782,15 +1060,149 @@ void xaccAccountSetMark (Account *account, short mark);
|
||||
/** Get the mark set by xaccAccountSetMark */
|
||||
short xaccAccountGetMark (const Account *account);
|
||||
|
||||
/** The xaccClearMark will find the topmost group, and clear the mark in
|
||||
* the entire group tree. */
|
||||
/** The xaccClearMark will find the root account, and clear the mark in
|
||||
* the entire account tree. */
|
||||
void xaccClearMark (Account *account, short val);
|
||||
|
||||
/** The xaccClearMarkDown will clear the mark only in this and in
|
||||
* sub-accounts.*/
|
||||
void xaccClearMarkDown (Account *account, short val);
|
||||
/** Will clear the mark for all the accounts of the AccountGroup .*/
|
||||
void xaccClearMarkDownGr (AccountGroup *group, short val);
|
||||
/** @} */
|
||||
|
||||
/** @name Staged Traversal
|
||||
|
||||
* The following functions provide support for "staged traversals"
|
||||
* over all of the transactions in an account or group. The idea
|
||||
* is to be able to perform a sequence of traversals ("stages"),
|
||||
* and perform an operation on each transaction exactly once
|
||||
* for that stage.
|
||||
*
|
||||
* Only transactions whose current "stage" is less than the
|
||||
* stage of the current traversal will be affected, and they will
|
||||
* be "brought up" to the current stage when they are processed.
|
||||
*
|
||||
* For example, you could perform a stage 1 traversal of all the
|
||||
* transactions in an account, and then perform a stage 1 traversal of
|
||||
* the transactions in a second account. Presuming the traversal of
|
||||
* the first account didn't abort prematurely, any transactions shared
|
||||
* by both accounts would be ignored during the traversal of the
|
||||
* second account since they had been processed while traversing the
|
||||
* first account.
|
||||
*
|
||||
* However, if you had traversed the second account using a stage
|
||||
* of 2, then all the transactions in the second account would have
|
||||
* been processed.
|
||||
*
|
||||
* Traversal can be aborted by having the callback function return
|
||||
* a non-zero value. The traversal is aborted immediately, and the
|
||||
* non-zero value is returned. Note that an aborted traversal can
|
||||
* be restarted; no information is lost due to an abort.
|
||||
*
|
||||
* The initial impetus for this particular approach came from
|
||||
* generalizing a mark/sweep practice that was already being
|
||||
* used in FileIO.c.
|
||||
*
|
||||
* Note that currently, there is a hard limit of 256 stages, which
|
||||
* can be changed by enlarging "marker" in the transaction struct.
|
||||
*
|
||||
@{
|
||||
*/
|
||||
/** gnc_account_tree_begin_staged_transaction_traversals()
|
||||
* resets the traversal marker inside every transactions of every
|
||||
* account in the account tree originating with the specified node.
|
||||
* This is done so that a new sequence of staged traversals can
|
||||
* begin.
|
||||
*/
|
||||
void gnc_account_tree_begin_staged_transaction_traversals(Account *acc);
|
||||
|
||||
/** xaccSplitsBeginStagedTransactionTraversals() resets the traversal
|
||||
* marker for each transaction which is a parent of one of the
|
||||
* splits in the list.
|
||||
*/
|
||||
void xaccSplitsBeginStagedTransactionTraversals(SplitList *splits);
|
||||
|
||||
/** xaccAccountBeginStagedTransactionTraversals() resets the traversal
|
||||
* marker for each transaction which is a parent of one of the
|
||||
* splits in the account.
|
||||
*/
|
||||
void xaccAccountBeginStagedTransactionTraversals(const Account *account);
|
||||
|
||||
/** xaccTransactionTraverse() checks the stage of the given transaction.
|
||||
* If the transaction hasn't reached the given stage, the transaction
|
||||
* is updated to that stage and the function returns TRUE. Otherwise
|
||||
* no change is made and the function returns FALSE.
|
||||
*/
|
||||
gboolean xaccTransactionTraverse(Transaction *trans, int stage);
|
||||
|
||||
/** xaccSplitTransactionTraverse() behaves as above using the parent of
|
||||
* the given split.
|
||||
*/
|
||||
gboolean xaccSplitTransactionTraverse(Split *split, int stage);
|
||||
|
||||
/** xaccAccountStagedTransactionTraversal() calls thunk on each
|
||||
* transaction in the account whose current marker is less than the
|
||||
* given `stage' and updates each transaction's marker to be `stage'.
|
||||
* The traversal will stop if thunk() returns a non-zero value.
|
||||
* xaccAccountStagedTransactionTraversal() function will return zero
|
||||
* or the non-zero value returned by thunk().
|
||||
* This API does not handle handle recursive traversals.
|
||||
*
|
||||
* Currently the result of adding or removing transactions during
|
||||
* a traversal is undefined, so don't do that.
|
||||
*/
|
||||
|
||||
int xaccAccountStagedTransactionTraversal(const Account *a,
|
||||
unsigned int stage,
|
||||
TransactionCallback thunk,
|
||||
void *data);
|
||||
|
||||
/** gnc_account_tree_staged_transaction_traversal() calls thunk on each
|
||||
* transaction in the group whose current marker is less than the
|
||||
* given `stage' and updates each transaction's marker to be `stage'.
|
||||
* The traversal will stop if thunk() returns a non-zero value.
|
||||
* gnc_account_tree_staged_transaction_traversal() function will return zero
|
||||
* or the non-zero value returned by thunk(). This
|
||||
* API does not handle handle recursive traversals.
|
||||
*
|
||||
* Currently the result of adding or removing transactions during
|
||||
* a traversal is undefined, so don't do that.
|
||||
*/
|
||||
|
||||
int gnc_account_tree_staged_transaction_traversal(const Account *account,
|
||||
unsigned int stage,
|
||||
TransactionCallback thunk,
|
||||
void *data);
|
||||
|
||||
/** Traverse all of the transactions in the given account group.
|
||||
Continue processing IFF proc returns 0. This function
|
||||
will descend recursively to traverse transactions in the
|
||||
children of the accounts in the group.
|
||||
|
||||
Proc will be called exactly once for each transaction that is
|
||||
pointed to by at least one split in any account in the hierarchy
|
||||
topped by the root Account acc.
|
||||
|
||||
The result of this function will be 0 IFF every relevant
|
||||
transaction was traversed exactly once; otherwise, the return
|
||||
value is the last non-zero value returned by the callback.
|
||||
|
||||
Note that the traversal occurs only over the transactions that
|
||||
are locally cached in the local gnucash engine. If the gnucash
|
||||
engine is attached to a remote database, the database may contain
|
||||
(many) transactions that are not mirrored in the local cache.
|
||||
This routine will not cause an SQL database query to be performed;
|
||||
it will not traverse transactions present only in the remote
|
||||
database.
|
||||
|
||||
Note that this routine is just a trivial wrapper for
|
||||
|
||||
gnc_account_tree_begin_staged_transaction_traversals(g);
|
||||
gnc_account_tree_staged_transaction_traversal(g, 42, proc, data);
|
||||
*/
|
||||
|
||||
int xaccAccountTreeForEachTransaction(Account *acc,
|
||||
TransactionCallback proc, void *data);
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
|
||||
@@ -98,8 +98,8 @@ struct account_s
|
||||
/* The parent and children pointers are used to implement an account
|
||||
* hierarchy, of accounts that have sub-accounts ("detail accounts").
|
||||
*/
|
||||
AccountGroup *parent; /* back-pointer to parent */
|
||||
AccountGroup *children; /* pointer to sub-accounts */
|
||||
Account *parent; /* back-pointer to parent */
|
||||
GList *children; /* list of sub-accounts */
|
||||
|
||||
/* protected data, cached parameters */
|
||||
gnc_numeric starting_balance;
|
||||
|
||||
1319
src/engine/Group.c
1319
src/engine/Group.c
File diff suppressed because it is too large
Load Diff
@@ -1,439 +0,0 @@
|
||||
/********************************************************************\
|
||||
* Group.h -- chart of accounts (hierarchical tree of accounts) *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
* *
|
||||
\********************************************************************/
|
||||
/** @addtogroup Engine
|
||||
@{ */
|
||||
/** @addtogroup Group Account Heirarchy Tree
|
||||
Accounts are organized into a heirarchical tree. The account
|
||||
group is the parent node that holds accounts.
|
||||
@{ */
|
||||
/** @file Group.h
|
||||
@brief Account handling public routines
|
||||
@author Copyright (C) 1997 Robin D. Clark
|
||||
@author Copyright (C) 1997-2000,2003 Linas Vepstas <linas@linas.org>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef XACC_ACCOUNT_GROUP_H
|
||||
#define XACC_ACCOUNT_GROUP_H
|
||||
|
||||
#include <glib.h>
|
||||
#include "qof.h"
|
||||
#include "Account.h"
|
||||
|
||||
/* PROTOTYPES ******************************************************/
|
||||
/** @name Constructors, Destructors
|
||||
@{
|
||||
*/
|
||||
/**
|
||||
* The xaccMallocAccountGroup() routine will create a new account group.
|
||||
* This is an internal-use function, you almost certainly want to
|
||||
* be using the xaccGetAccountGroup() routine instead.
|
||||
*/
|
||||
AccountGroup *xaccMallocAccountGroup (QofBook *book);
|
||||
|
||||
/**
|
||||
* The xaccGetAccountGroup() routine will return the top-most
|
||||
* account group associated with the indicated book.
|
||||
*/
|
||||
AccountGroup * xaccGetAccountGroup (QofBook *book);
|
||||
|
||||
/**
|
||||
* The xaccCollAccountGroup() routine will return the top-most
|
||||
* account group associated with the indicated collection.
|
||||
*/
|
||||
AccountGroup * xaccCollGetAccountGroup (const QofCollection *col);
|
||||
|
||||
/** The xaccAccountDestroy() routine will destroy and free all
|
||||
* the data associated with this account group. The group
|
||||
* must have been opened for editing with
|
||||
* xaccAccountGroupBeginEdit() first, before the Destroy is called.
|
||||
*/
|
||||
void xaccAccountGroupDestroy (AccountGroup *grp);
|
||||
|
||||
/* @deprecated XXX backwards-compat define, remove at later convenience */
|
||||
#define gnc_book_get_group xaccGetAccountGroup
|
||||
|
||||
/** Return the book to which this account belongs */
|
||||
QofBook * xaccGroupGetBook (const AccountGroup *group);
|
||||
|
||||
/** Compare two account groups
|
||||
|
||||
warns if one is NULL, if one has no accounts or if the two
|
||||
groups have different numbers of accounts.
|
||||
|
||||
@return TRUE if the two account groups are equal, FALSE otherwise.
|
||||
*/
|
||||
gboolean xaccGroupEqual(const AccountGroup *a, const AccountGroup *b,
|
||||
gboolean check_guids);
|
||||
|
||||
/** @} */
|
||||
|
||||
/** @name Editing
|
||||
@{
|
||||
*/
|
||||
/** Start of begine/commit sequence. All changes to an account
|
||||
* group should be bracketed by calls to begin-edit/commit-edit
|
||||
*/
|
||||
void xaccAccountGroupBeginEdit (AccountGroup *grp);
|
||||
|
||||
/** End of begine/commit sequence. All changes to an account
|
||||
* group should be bracketed by calls to begin-edit/commit-edit
|
||||
*/
|
||||
void xaccAccountGroupCommitEdit (AccountGroup *grp);
|
||||
|
||||
/** The xaccGroupNotSaved() subroutine will return TRUE
|
||||
* if any account in the group or in any subgroup
|
||||
* hasn't been saved.
|
||||
XXX this should be moved to private header file, this is not a public routine!
|
||||
*/
|
||||
gboolean xaccGroupNotSaved (const AccountGroup *grp);
|
||||
|
||||
/** The xaccGroupMarkSaved() subroutine will mark
|
||||
* the entire group as having been saved, including
|
||||
* all of the child accounts.
|
||||
|
||||
XXX this should be moved to private header file, this is not a public routine!
|
||||
*/
|
||||
void xaccGroupMarkSaved (AccountGroup *grp);
|
||||
|
||||
/** The xaccGroupMarkNotSaved() subroutine will mark
|
||||
* the given group as not having been saved.
|
||||
XXX this should be moved to private header file, this is not a public routine!
|
||||
*/
|
||||
void xaccGroupMarkNotSaved (AccountGroup *grp);
|
||||
/** @} */
|
||||
|
||||
/** @name Concatenation, Merging
|
||||
@{
|
||||
*/
|
||||
/**
|
||||
* The xaccGroupConcatGroup() subroutine will move (reparent)
|
||||
* all accounts from the "src" group to the "dest" group,
|
||||
* preserving the account heirarchy. It will also take care
|
||||
* that the moved accounts will have the "dest" group's book
|
||||
* parent as well.
|
||||
*/
|
||||
void xaccGroupConcatGroup (AccountGroup *dest, AccountGroup *src);
|
||||
|
||||
/** The xaccGroupCopyGroup() subroutine will copy all accounts
|
||||
* from the "src" group to the "dest" group, preserving the
|
||||
* account heirarchy. It will also take care that the moved
|
||||
* accounts will have the "dest" group's book parent as well.
|
||||
* This routine will *NOT* copy any splits/transactions.
|
||||
* It will copy the KVP trees in each account.
|
||||
*/
|
||||
void xaccGroupCopyGroup (AccountGroup *dest, AccountGroup *src);
|
||||
|
||||
/** The xaccGroupMergeAccounts() subroutine will go through a group,
|
||||
* merging all accounts that have the same name and description.
|
||||
* This function is useful when importing Quicken(TM) files.
|
||||
*/
|
||||
void xaccGroupMergeAccounts (AccountGroup *grp);
|
||||
|
||||
/** The xaccGroupInsertAccount() subroutine will insert the indicated
|
||||
* account into the indicated group. If it already is the child
|
||||
* of another group, it will be removed there first. If the
|
||||
* account belongs to a different book than the the group, it
|
||||
* will be removed from the other book (and thus, the other book's
|
||||
* entity tables, generating destroy & create events). If the
|
||||
* account is removed from and inserted into the same group, the
|
||||
* overall account sort order will be recomputed.
|
||||
*/
|
||||
void xaccGroupInsertAccount (AccountGroup *grp, Account *acc);
|
||||
|
||||
/** The xaccAccountInsertSubAccount() does the same, except that
|
||||
* the parent is specified as an account.
|
||||
*/
|
||||
void xaccAccountInsertSubAccount (Account *parent, Account *child);
|
||||
/** @} */
|
||||
|
||||
/** @name Counting the Size and Depth of the Account Tree
|
||||
@{
|
||||
*/
|
||||
/** The xaccGroupGetNumSubAccounts() subroutine returns the number
|
||||
* of accounts, including subaccounts, in the account group
|
||||
*/
|
||||
int xaccGroupGetNumSubAccounts (const AccountGroup *grp);
|
||||
|
||||
/** The xaccGroupGetNumAccounts() subroutine returns the number
|
||||
* of accounts in the indicated group only (children not counted).
|
||||
*/
|
||||
int xaccGroupGetNumAccounts (const AccountGroup *grp);
|
||||
|
||||
/** The xaccGroupGetDepth() subroutine returns the length of the
|
||||
* longest tree branch. Each link between an account and its
|
||||
* (non-null) children counts as one unit of length.
|
||||
*/
|
||||
int xaccGroupGetDepth (const AccountGroup *grp);
|
||||
/** @} */
|
||||
|
||||
/** @name Getting Accounts and Subaccounts
|
||||
@{
|
||||
*/
|
||||
/** DOCUMENT ME! is this routine deprecated? XXX using index is weird! */
|
||||
Account * xaccGroupGetAccount (const AccountGroup *group, int index);
|
||||
|
||||
/** The xaccGroupGetSubAccounts() subroutine returns an list of the accounts,
|
||||
* including subaccounts, in the account group. The returned list
|
||||
* should be freed with g_list_free() when no longer needed.
|
||||
*/
|
||||
AccountList * xaccGroupGetSubAccounts (const AccountGroup *grp);
|
||||
|
||||
/** The xaccGroupGetSubAccounts() subroutine returns a sorted list of
|
||||
* the accounts, including subaccounts, in the account group. The
|
||||
* returned list should be freed with g_list_free() when no longer
|
||||
* needed.
|
||||
*/
|
||||
AccountList * xaccGroupGetSubAccountsSorted (const AccountGroup *grp);
|
||||
|
||||
/** The xaccGroupGetAccountList() subroutines returns only the immediate
|
||||
* children of the account group. The returned list should *not*
|
||||
* be freed by the caller.
|
||||
*/
|
||||
AccountList * xaccGroupGetAccountList (const AccountGroup *grp);
|
||||
|
||||
/** The xaccGroupGetAccountList() subroutines returns only the
|
||||
* immediate children of the account group. The returned list
|
||||
* should be freed with g_list_free() when no longer needed.
|
||||
*/
|
||||
AccountList * xaccGroupGetAccountListSorted (const AccountGroup *grp);
|
||||
|
||||
/** The xaccGroupGetRoot() subroutine will find the topmost
|
||||
* (root) group to which this group belongs.
|
||||
*/
|
||||
AccountGroup * xaccGroupGetRoot (const AccountGroup *grp);
|
||||
|
||||
/** The xaccGetAccountRoot() subroutine will find the topmost
|
||||
* (root) group to which this account belongs.
|
||||
*/
|
||||
AccountGroup * xaccAccountGetRoot (const Account *account);
|
||||
|
||||
/** The xaccGroupGetParentAccount() subroutine returns the parent
|
||||
* account of the group, or NULL.
|
||||
*/
|
||||
Account * xaccGroupGetParentAccount (const AccountGroup *group);
|
||||
|
||||
/** @} */
|
||||
|
||||
/** @name Getting Accounts and Subaccounts by Name
|
||||
@{
|
||||
*/
|
||||
/** The xaccGetAccountFromName() subroutine fetches the
|
||||
* account by name from the collection of accounts
|
||||
* in the indicated AccountGroup group. It returns NULL if the
|
||||
* account was not found.
|
||||
*/
|
||||
Account *xaccGetAccountFromName (const AccountGroup *group, const char *name);
|
||||
|
||||
/** The xaccGetAccountFromFullName() subroutine works like
|
||||
* xaccGetAccountFromName, but uses fully-qualified names
|
||||
* using the given separator.
|
||||
*/
|
||||
Account *xaccGetAccountFromFullName (const AccountGroup *group,
|
||||
const char *name);
|
||||
|
||||
/** The xaccGetPeerAccountFromName() subroutine fetches the
|
||||
* account by name from the collection of accounts
|
||||
* in the same AccountGroup anchor group. It returns NULL if the
|
||||
* account was not found.
|
||||
*/
|
||||
Account *xaccGetPeerAccountFromName (const Account *account, const char *name);
|
||||
|
||||
/** The xaccGetPeerAccountFromFullName() subroutine works like
|
||||
* xaccGetPeerAccountFromName, but uses fully-qualified
|
||||
* names using the given separator.
|
||||
*/
|
||||
Account *xaccGetPeerAccountFromFullName (const Account *acc,
|
||||
const char * name);
|
||||
|
||||
/** @} */
|
||||
|
||||
/** @name Traversal, ForEach
|
||||
@{
|
||||
*/
|
||||
|
||||
typedef gpointer (*AccountCallback) (Account *a, gpointer data);
|
||||
|
||||
/** The xaccGroupMapAccounts() routine will traverse the account
|
||||
group, returning a list of accounts. If the callback
|
||||
returns null for a given item, it won't show up in
|
||||
the result list. You should free the returned list when
|
||||
you are done with it.
|
||||
*/
|
||||
AccountList *xaccGroupMapAccounts(AccountGroup *grp,
|
||||
AccountCallback func,
|
||||
gpointer data);
|
||||
|
||||
/** The xaccGroupForEachAccount() method will traverse the AccountGroup
|
||||
* tree, calling 'func' on each account. Traversal will stop when
|
||||
* func returns a non-null value, and the routine will return with that
|
||||
* value. Therefore, this function will return null iff func returns
|
||||
* null for every account.
|
||||
*
|
||||
* If 'deeply' is FALSE, then only the immediate children of
|
||||
* the account will be traversed. If TRUE, then the whole tree will
|
||||
* be traversed.
|
||||
*/
|
||||
|
||||
gpointer xaccGroupForEachAccount (AccountGroup *grp,
|
||||
AccountCallback func,
|
||||
gpointer data,
|
||||
gboolean deeply);
|
||||
|
||||
/** @} */
|
||||
|
||||
/** @name Staged Traversal
|
||||
|
||||
* The following functions provide support for "staged traversals"
|
||||
* over all of the transactions in an account or group. The idea
|
||||
* is to be able to perform a sequence of traversals ("stages"),
|
||||
* and perform an operation on each transaction exactly once
|
||||
* for that stage.
|
||||
*
|
||||
* Only transactions whose current "stage" is less than the
|
||||
* stage of the current traversal will be affected, and they will
|
||||
* be "brought up" to the current stage when they are processed.
|
||||
*
|
||||
* For example, you could perform a stage 1 traversal of all the
|
||||
* transactions in an account, and then perform a stage 1 traversal of
|
||||
* the transactions in a second account. Presuming the traversal of
|
||||
* the first account didn't abort prematurely, any transactions shared
|
||||
* by both accounts would be ignored during the traversal of the
|
||||
* second account since they had been processed while traversing the
|
||||
* first account.
|
||||
*
|
||||
* However, if you had traversed the second account using a stage
|
||||
* of 2, then all the transactions in the second account would have
|
||||
* been processed.
|
||||
*
|
||||
* Traversal can be aborted by having the callback function return
|
||||
* a non-zero value. The traversal is aborted immediately, and the
|
||||
* non-zero value is returned. Note that an aborted traversal can
|
||||
* be restarted; no information is lost due to an abort.
|
||||
*
|
||||
* The initial impetus for this particular approach came from
|
||||
* generalizing a mark/sweep practice that was already being
|
||||
* used in FileIO.c.
|
||||
*
|
||||
* Note that currently, there is a hard limit of 256 stages, which
|
||||
* can be changed by enlarging "marker" in the transaction struct.
|
||||
*
|
||||
@{
|
||||
*/
|
||||
/** xaccGroupBeginStagedTransactionTraversals() resets the traversal
|
||||
* marker inside each of all the transactions in the group so that
|
||||
* a new sequence of staged traversals can begin.
|
||||
*/
|
||||
void xaccGroupBeginStagedTransactionTraversals(AccountGroup *grp);
|
||||
|
||||
/** xaccSplitsBeginStagedTransactionTraversals() resets the traversal
|
||||
* marker for each transaction which is a parent of one of the
|
||||
* splits in the list.
|
||||
*/
|
||||
void xaccSplitsBeginStagedTransactionTraversals(SplitList *splits);
|
||||
|
||||
/** xaccAccountBeginStagedTransactionTraversals() resets the traversal
|
||||
* marker for each transaction which is a parent of one of the
|
||||
* splits in the account.
|
||||
*/
|
||||
void xaccAccountBeginStagedTransactionTraversals(const Account *account);
|
||||
|
||||
/** xaccTransactionTraverse() checks the stage of the given transaction.
|
||||
* If the transaction hasn't reached the given stage, the transaction
|
||||
* is updated to that stage and the function returns TRUE. Otherwise
|
||||
* no change is made and the function returns FALSE.
|
||||
*/
|
||||
gboolean xaccTransactionTraverse(Transaction *trans, int stage);
|
||||
|
||||
/** xaccSplitTransactionTraverse() behaves as above using the parent of
|
||||
* the given split.
|
||||
*/
|
||||
gboolean xaccSplitTransactionTraverse(Split *split, int stage);
|
||||
|
||||
/** xaccGroupStagedTransactionTraversal() calls thunk on each
|
||||
* transaction in the group whose current marker is less than the
|
||||
* given `stage' and updates each transaction's marker to be `stage'.
|
||||
* The traversal will stop if thunk() returns a non-zero value.
|
||||
* xaccGroupStagedTransactionTraversal() function will return zero
|
||||
* or the non-zero value returned by thunk(). This
|
||||
* API does not handle handle recursive traversals.
|
||||
*
|
||||
* Currently the result of adding or removing transactions during
|
||||
* a traversal is undefined, so don't do that.
|
||||
*/
|
||||
|
||||
int xaccGroupStagedTransactionTraversal(AccountGroup *grp,
|
||||
unsigned int stage,
|
||||
TransactionCallback,
|
||||
void *data);
|
||||
|
||||
/** xaccAccountStagedTransactionTraversal() calls thunk on each
|
||||
* transaction in the account whose current marker is less than the
|
||||
* given `stage' and updates each transaction's marker to be `stage'.
|
||||
* The traversal will stop if thunk() returns a non-zero value.
|
||||
* xaccAccountStagedTransactionTraversal() function will return zero
|
||||
* or the non-zero value returned by thunk().
|
||||
* This API does not handle handle recursive traversals.
|
||||
*
|
||||
* Currently the result of adding or removing transactions during
|
||||
* a traversal is undefined, so don't do that.
|
||||
*/
|
||||
|
||||
int xaccAccountStagedTransactionTraversal(const Account *a,
|
||||
unsigned int stage,
|
||||
TransactionCallback thunk,
|
||||
void *data);
|
||||
|
||||
/** Traverse all of the transactions in the given account group.
|
||||
Continue processing IFF proc returns 0. This function
|
||||
will descend recursively to traverse transactions in the
|
||||
children of the accounts in the group.
|
||||
|
||||
Proc will be called exactly once for each transaction that is
|
||||
pointed to by at least one split in any account in the hierarchy
|
||||
topped by AccountGroup g.
|
||||
|
||||
The result of this function will be 0 IFF every relevant
|
||||
transaction was traversed exactly once; otherwise, the return
|
||||
value is the last non-zero value returned by the callback.
|
||||
|
||||
Note that the traversal occurs only over the transactions that
|
||||
are locally cached in the local gnucash engine. If the gnucash
|
||||
engine is attached to a remote database, the database may contain
|
||||
(many) transactions that are not mirrored in the local cache.
|
||||
This routine will not cause an SQL database query to be performed;
|
||||
it will not traverse transactions present only in the remote
|
||||
database.
|
||||
|
||||
Note that this routine is just a trivial wrapper for
|
||||
|
||||
xaccGroupBeginStagedTransactionTraversals(g);
|
||||
xaccGroupStagedTransactionTraversal(g, 42, proc, data);
|
||||
*/
|
||||
|
||||
int xaccGroupForEachTransaction(AccountGroup *g,
|
||||
TransactionCallback proc, void *data);
|
||||
|
||||
/** @} */
|
||||
#endif /* XACC_ACCOUNT_GROUP_H */
|
||||
/** @} */
|
||||
/** @} */
|
||||
@@ -1,102 +0,0 @@
|
||||
/********************************************************************\
|
||||
* GroupP.h -- private header file for chart of accounts *
|
||||
* Copyright (C) 1997 Robin D. Clark *
|
||||
* Copyright (C) 1997, 1998, 1999, 2000 Linas Vepstas *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
/*
|
||||
* FILE:
|
||||
* GroupP.h
|
||||
*
|
||||
* FUNCTION:
|
||||
* This is the *private* account group structure.
|
||||
* This header should *not* be included by any code outside of the
|
||||
* engine.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef XACC_GROUP_P_H
|
||||
#define XACC_GROUP_P_H
|
||||
|
||||
#include "Group.h"
|
||||
#include "Transaction.h"
|
||||
|
||||
/** STRUCTS *********************************************************/
|
||||
struct account_group_s
|
||||
{
|
||||
/* The flags: */
|
||||
unsigned int saved : 1;
|
||||
|
||||
Account *parent; /* back-pointer to parent */
|
||||
|
||||
AccountList *accounts; /* list of account pointers */
|
||||
|
||||
QofBook *book; /* The book which this group belongs to */
|
||||
|
||||
/* keep track of nesting level of begin/end edit calls */
|
||||
gint32 editlevel;
|
||||
};
|
||||
|
||||
/*
|
||||
* The xaccAccountRemoveGroup() subroutine will remove the indicated
|
||||
* account group from its parent account. It will NOT free the
|
||||
* associated memory or otherwise alter the account group: the
|
||||
* account group can now be reparented to a new location.
|
||||
* Note, however, that it will mark the old parents as having
|
||||
* been modified.
|
||||
*
|
||||
* The xaccGroupRemoveAccount() subroutine will remove the indicated
|
||||
* account from its parent account group. It will NOT free the
|
||||
* associated memory or otherwise alter the account: the account
|
||||
* can now be reparented to a new location.
|
||||
* Note, however, that it will mark the old parents as having
|
||||
* been modified.
|
||||
*
|
||||
* Both of the above routines are private routines, since they are slightly
|
||||
* dangerous: If the removed group/account is not immediately reparented,
|
||||
* it can be lost, i.e. turn into a memory leak. If the GUI or other engine
|
||||
* user needs to move an account or group from here to there, it should use
|
||||
* the 'Insert' routines, such as xaccGroupInsertAccount(), to make the move.
|
||||
* The 'Insert' routines will automatically remove the account from its
|
||||
* previous location.
|
||||
*/
|
||||
|
||||
void xaccAccountRemoveGroup (Account *acc);
|
||||
void xaccGroupRemoveAccount (AccountGroup *grp, Account *account);
|
||||
|
||||
/*
|
||||
* The xaccFreeAccountGroup() subroutine will ...
|
||||
*/
|
||||
void xaccFreeAccountGroup (AccountGroup *account_group);
|
||||
|
||||
/* Set the top-level group in the book */
|
||||
void xaccSetAccountGroup (QofBook *book, AccountGroup *grp);
|
||||
void xaccCollSetAccountGroup (QofCollection *col, AccountGroup *grp);
|
||||
|
||||
/*
|
||||
* The xaccGroupGetBackend() subroutine will find the
|
||||
* persistent-data storage backend associated with this account group.
|
||||
*/
|
||||
QofBackend * xaccGroupGetBackend (const AccountGroup *group);
|
||||
|
||||
gboolean xaccGroupRegister (void);
|
||||
|
||||
#endif
|
||||
@@ -15,7 +15,6 @@ libgncmod_engine_la_SOURCES = \
|
||||
Account.c \
|
||||
FreqSpec.c \
|
||||
Recurrence.c \
|
||||
Group.c \
|
||||
Period.c \
|
||||
Query.c \
|
||||
SchedXaction.c \
|
||||
@@ -56,7 +55,6 @@ gncinclude_HEADERS = \
|
||||
FreqSpec.h \
|
||||
Recurrence.h \
|
||||
GNCId.h \
|
||||
Group.h \
|
||||
Period.h \
|
||||
SchedXaction.h \
|
||||
SX-book.h \
|
||||
@@ -95,7 +93,6 @@ gncinclude_HEADERS = \
|
||||
noinst_HEADERS = \
|
||||
AccountP.h \
|
||||
FreqSpecP.h \
|
||||
GroupP.h \
|
||||
QueryP.h \
|
||||
ScrubP.h \
|
||||
SplitP.h \
|
||||
|
||||
@@ -40,9 +40,8 @@
|
||||
#include "gnc-lot-p.h"
|
||||
#include "gnc-pricedb.h"
|
||||
#include "gnc-pricedb-p.h"
|
||||
#include "Group.h"
|
||||
#include "GroupP.h"
|
||||
#include "Period.h"
|
||||
#include "Transaction.h"
|
||||
#include "TransactionP.h"
|
||||
|
||||
/* This static indicates the debugging module that this .o belongs to. */
|
||||
@@ -432,22 +431,13 @@ trans_list_preen_open_lots (TransList *trans_list)
|
||||
/* clear the markers for the above routines */
|
||||
|
||||
static void
|
||||
clear_markers (AccountGroup *grp)
|
||||
clear_markers (Account *account, gpointer dummy)
|
||||
{
|
||||
GList *node;
|
||||
|
||||
if (!grp) return;
|
||||
|
||||
for (node = grp->accounts; node; node = node->next)
|
||||
{
|
||||
Account *account = node->data;
|
||||
GList *lp;
|
||||
|
||||
/* recursively do sub-accounts */
|
||||
clear_markers (account->children);
|
||||
if (!account) return;
|
||||
|
||||
for (lp = account->splits; lp; lp = lp->next)
|
||||
{
|
||||
for (lp = xaccAccountGetSplitList(account); lp; lp = lp->next) {
|
||||
Split *s = lp->data;
|
||||
Transaction *trans = s->parent;
|
||||
GNCLot *lot = s->lot;
|
||||
@@ -455,7 +445,6 @@ clear_markers (AccountGroup *grp)
|
||||
if (lot) lot->marker = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================ */
|
||||
/* Return a unique list of lots that are involved with the listed
|
||||
@@ -526,7 +515,7 @@ void
|
||||
gnc_book_partition_txn (QofBook *dest_book, QofBook *src_book, QofQuery *query)
|
||||
{
|
||||
gnc_commodity_table *src_tbl, *dst_tbl;
|
||||
AccountGroup *src_grp, *dst_grp;
|
||||
Account *src_root, *dst_root;
|
||||
time_t now;
|
||||
TransList *trans_list, *tnode;
|
||||
LotList *lot_list, *lnode;
|
||||
@@ -552,18 +541,18 @@ gnc_book_partition_txn (QofBook *dest_book, QofBook *src_book, QofQuery *query)
|
||||
/* hack alert -- FIXME -- this should really be a merge, not a
|
||||
* clobber copy, but I am too lazy to write an account-group merge
|
||||
* routine, and it is not needed for the current usage. */
|
||||
src_grp = xaccGetAccountGroup (src_book);
|
||||
dst_grp = xaccGetAccountGroup (dest_book);
|
||||
xaccGroupCopyGroup (dst_grp, src_grp);
|
||||
src_root = gnc_book_get_root_account (src_book);
|
||||
dst_root = gnc_book_get_root_account (dest_book);
|
||||
gnc_account_copy_children (dst_root, src_root);
|
||||
|
||||
/* Next, run the query */
|
||||
xaccAccountGroupBeginEdit (dst_grp);
|
||||
xaccAccountGroupBeginEdit (src_grp);
|
||||
xaccAccountBeginEdit (dst_root);
|
||||
xaccAccountBeginEdit (src_root);
|
||||
qof_query_set_book (query, src_book);
|
||||
trans_list = qof_query_run (query);
|
||||
|
||||
/* Preen: remove open lots/ open trnasactions */
|
||||
clear_markers (src_grp);
|
||||
gnc_account_foreach_descendant(src_root, clear_markers, NULL);
|
||||
trans_list = trans_list_preen_open_lots (trans_list);
|
||||
lot_list = create_lot_list_from_trans_list (trans_list);
|
||||
lot_list = lot_list_preen_open_lots (lot_list);
|
||||
@@ -583,8 +572,8 @@ gnc_book_partition_txn (QofBook *dest_book, QofBook *src_book, QofQuery *query)
|
||||
gnc_book_insert_trans (dest_book, trans);
|
||||
}
|
||||
|
||||
xaccAccountGroupCommitEdit (src_grp);
|
||||
xaccAccountGroupCommitEdit (dst_grp);
|
||||
xaccAccountCommitEdit (src_root);
|
||||
xaccAccountCommitEdit (dst_root);
|
||||
|
||||
/* Make note of the sibling books */
|
||||
now = time(0);
|
||||
@@ -603,41 +592,37 @@ gnc_book_partition_txn (QofBook *dest_book, QofBook *src_book, QofQuery *query)
|
||||
static Account *
|
||||
find_nearest_equity_acct (Account *acc)
|
||||
{
|
||||
AccountList *acc_list, *node;
|
||||
AccountGroup *parent;
|
||||
Account *next_up, *candidate;
|
||||
QofBook *book;
|
||||
GList *acc_list, *node;
|
||||
Account *parent, *root, *candidate;
|
||||
|
||||
/* See if we can find an equity account that is peered to this account */
|
||||
parent = xaccAccountGetParent (acc);
|
||||
parent = gnc_account_get_parent (acc);
|
||||
g_return_val_if_fail (parent, NULL);
|
||||
|
||||
acc_list = xaccGroupGetAccountList (parent);
|
||||
for (node=acc_list; node; node=node->next)
|
||||
{
|
||||
/* See if we can find an equity account that is peered to this
|
||||
* account. If not, check succssively higher levels. */
|
||||
while (parent != NULL) {
|
||||
acc_list = gnc_account_get_children(parent);
|
||||
for (node=acc_list; node; node=node->next) {
|
||||
candidate = (Account *) node->data;
|
||||
if ((ACCT_TYPE_EQUITY == xaccAccountGetType (candidate)) &&
|
||||
gnc_commodity_equiv(xaccAccountGetCommodity(acc),
|
||||
xaccAccountGetCommodity(candidate)))
|
||||
{
|
||||
xaccAccountGetCommodity(candidate))) {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
|
||||
/* If we got to here, we did not find a peer equity account.
|
||||
* So go up one layer, and look there */
|
||||
next_up = xaccGroupGetParentAccount (parent);
|
||||
if (next_up)
|
||||
{
|
||||
candidate = find_nearest_equity_acct (next_up);
|
||||
if (candidate) return candidate;
|
||||
g_list_free(acc_list);
|
||||
parent = gnc_account_get_parent (parent);
|
||||
}
|
||||
|
||||
/* If we got to here, then we are at the top group, and there is no
|
||||
/* If we got to here, then we are at the root account, and there is no
|
||||
* equity account to be found. So we need to create one. */
|
||||
|
||||
candidate = xaccMallocAccount (xaccGroupGetBook(parent));
|
||||
book = gnc_account_get_book(acc);
|
||||
root = gnc_book_get_root_account(book);
|
||||
candidate = xaccMallocAccount (book);
|
||||
xaccAccountBeginEdit (candidate);
|
||||
xaccGroupInsertAccount (parent, candidate);
|
||||
gnc_account_append_child (root, candidate);
|
||||
xaccAccountSetType (candidate, ACCT_TYPE_EQUITY);
|
||||
xaccAccountSetName (candidate, xaccAccountGetTypeStr(ACCT_TYPE_EQUITY));
|
||||
xaccAccountSetCommodity (candidate, xaccAccountGetCommodity(acc));
|
||||
@@ -650,28 +635,27 @@ find_nearest_equity_acct (Account *acc)
|
||||
/* Traverse all accounts, get account balances */
|
||||
|
||||
static void
|
||||
add_closing_balances (AccountGroup *closed_grp,
|
||||
add_closing_balances (Account *parent,
|
||||
QofBook *open_book,
|
||||
QofBook *closed_book,
|
||||
Account *equity_account,
|
||||
Timespec *post_date, Timespec *date_entered,
|
||||
const char *desc)
|
||||
{
|
||||
AccountList *acc_list, *node;
|
||||
GList *acc_list, *node;
|
||||
|
||||
if (!closed_grp) return;
|
||||
if (!parent) return;
|
||||
|
||||
ENTER (" enter=%s post=%s desc=%s", gnc_print_date(*date_entered),
|
||||
gnc_print_date (*post_date), desc);
|
||||
xaccAccountBeginEdit (equity_account);
|
||||
|
||||
/* Walk accounts in closed book */
|
||||
acc_list = xaccGroupGetAccountList (closed_grp);
|
||||
acc_list = gnc_account_get_children(parent);
|
||||
for (node=acc_list; node; node=node->next)
|
||||
{
|
||||
KvpFrame *cwd;
|
||||
Account *twin;
|
||||
AccountGroup *childs;
|
||||
Account * candidate = (Account *) node->data;
|
||||
GNCAccountType tip = xaccAccountGetType (candidate);
|
||||
|
||||
@@ -774,16 +758,16 @@ add_closing_balances (AccountGroup *closed_grp,
|
||||
xaccAccountCommitEdit (twin);
|
||||
|
||||
/* Recurse down to the children */
|
||||
childs = xaccAccountGetChildren(candidate);
|
||||
if (childs)
|
||||
if (gnc_account_n_children(candidate) > 0)
|
||||
{
|
||||
PINFO ("add closing baln to subaccts of %s",
|
||||
candidate->description);
|
||||
add_closing_balances (childs, open_book, closed_book,
|
||||
add_closing_balances (candidate, open_book, closed_book,
|
||||
equity_account,
|
||||
post_date, date_entered, desc);
|
||||
}
|
||||
}
|
||||
g_list_free(acc_list);
|
||||
xaccAccountCommitEdit (equity_account);
|
||||
LEAVE (" ");
|
||||
}
|
||||
@@ -884,7 +868,7 @@ gnc_book_close_period (QofBook *existing_book, Timespec calve_date,
|
||||
|
||||
/* add in transactions to equity accounts that will
|
||||
* hold the colsing balances */
|
||||
add_closing_balances (xaccGetAccountGroup(closing_book),
|
||||
add_closing_balances (gnc_book_get_root_account(closing_book),
|
||||
existing_book, closing_book,
|
||||
equity_account,
|
||||
&calve_date, &ts, memo);
|
||||
|
||||
@@ -41,9 +41,8 @@
|
||||
|
||||
SchedXactions* gnc_collection_get_schedxactions(const QofCollection *col);
|
||||
|
||||
/* Associate the given template group with a book */
|
||||
void gnc_book_set_template_group (QofBook *book, AccountGroup *templateGroup);
|
||||
void gnc_collection_set_template_group (QofCollection *col, AccountGroup *templateGroup);
|
||||
/* Associate the given template root account with a book */
|
||||
void gnc_book_set_template_root (QofBook *book, Account *templateRoot);
|
||||
|
||||
gboolean gnc_sxtt_register (void);
|
||||
|
||||
|
||||
@@ -39,8 +39,8 @@
|
||||
#include <glib.h>
|
||||
|
||||
#include "gnc-engine.h"
|
||||
#include "Group.h"
|
||||
#include "GroupP.h"
|
||||
#include "Account.h"
|
||||
#include "Split.h"
|
||||
#include "SchedXaction.h"
|
||||
#include "SX-book.h"
|
||||
#include "SX-book-p.h"
|
||||
@@ -53,52 +53,54 @@ static QofLogModule log_module = GNC_MOD_SX;
|
||||
|
||||
/* ====================================================================== */
|
||||
|
||||
AccountGroup *
|
||||
gnc_collection_get_template_group( const QofCollection *col )
|
||||
static Account *
|
||||
gnc_collection_get_template_root( const QofCollection *col )
|
||||
{
|
||||
return qof_collection_get_data (col);
|
||||
}
|
||||
|
||||
AccountGroup *
|
||||
gnc_book_get_template_group( QofBook *book )
|
||||
Account *
|
||||
gnc_book_get_template_root( QofBook *book )
|
||||
{
|
||||
QofCollection *col;
|
||||
if (!book) return NULL;
|
||||
col = qof_book_get_collection (book, GNC_ID_SXTG);
|
||||
return gnc_collection_get_template_group (col);
|
||||
return gnc_collection_get_template_root (col);
|
||||
}
|
||||
|
||||
void
|
||||
gnc_collection_set_template_group (QofCollection *col,
|
||||
AccountGroup *templateGroup)
|
||||
static void
|
||||
gnc_collection_set_template_root (QofCollection *col,
|
||||
Account *templateRoot)
|
||||
{
|
||||
AccountGroup *old_grp;
|
||||
Account *old_root;
|
||||
if (!col) return;
|
||||
|
||||
old_grp = gnc_collection_get_template_group (col);
|
||||
if (old_grp == templateGroup) return;
|
||||
old_root = gnc_collection_get_template_root (col);
|
||||
if (old_root == templateRoot) return;
|
||||
|
||||
qof_collection_set_data (col, templateGroup);
|
||||
qof_collection_set_data (col, templateRoot);
|
||||
|
||||
xaccAccountGroupBeginEdit (old_grp);
|
||||
xaccAccountGroupDestroy (old_grp);
|
||||
if (old_root) {
|
||||
xaccAccountBeginEdit (old_root);
|
||||
xaccAccountDestroy (old_root);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
gnc_book_set_template_group (QofBook *book, AccountGroup *templateGroup)
|
||||
gnc_book_set_template_root (QofBook *book, Account *templateRoot)
|
||||
{
|
||||
QofCollection *col;
|
||||
if (!book) return;
|
||||
|
||||
if (templateGroup && templateGroup->book != book)
|
||||
if (templateRoot && gnc_account_get_book(templateRoot) != book)
|
||||
{
|
||||
g_critical("cannot mix and match books freely!");
|
||||
return;
|
||||
}
|
||||
|
||||
col = qof_book_get_collection (book, GNC_ID_SXTG);
|
||||
gnc_collection_set_template_group (col, templateGroup);
|
||||
gnc_collection_set_template_root (col, templateRoot);
|
||||
}
|
||||
|
||||
|
||||
@@ -108,25 +110,53 @@ gnc_book_set_template_group (QofBook *book, AccountGroup *templateGroup)
|
||||
static void
|
||||
sxtg_book_begin (QofBook *book)
|
||||
{
|
||||
gnc_book_set_template_group (book, xaccMallocAccountGroup(book));
|
||||
Account *root;
|
||||
|
||||
root = xaccMallocAccount(book);
|
||||
xaccAccountBeginEdit(root);
|
||||
xaccAccountSetType(root, ACCT_TYPE_ROOT);
|
||||
xaccAccountCommitEdit(root);
|
||||
gnc_book_set_template_root (book, root);
|
||||
}
|
||||
|
||||
static void
|
||||
sxtg_book_end (QofBook *book)
|
||||
{
|
||||
gnc_book_set_template_group (book, NULL);
|
||||
gnc_book_set_template_root (book, NULL);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
sxtg_is_dirty(const QofCollection *col)
|
||||
{
|
||||
return xaccGroupNotSaved(gnc_collection_get_template_group(col));
|
||||
Account *root;
|
||||
GList *descendants, *node;
|
||||
gboolean dirty = FALSE;
|
||||
|
||||
root = gnc_collection_get_template_root(col);
|
||||
descendants = gnc_account_get_descendants(root);
|
||||
for (node = descendants; node; node = g_list_next(node)) {
|
||||
if (qof_instance_is_dirty(node->data)) {
|
||||
dirty = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
g_list_free(descendants);
|
||||
|
||||
return dirty;
|
||||
}
|
||||
|
||||
static void
|
||||
sxtg_mark_clean(QofCollection *col)
|
||||
{
|
||||
xaccGroupMarkSaved(gnc_collection_get_template_group(col));
|
||||
Account *root;
|
||||
GList *descendants;
|
||||
|
||||
root = gnc_collection_get_template_root(col);
|
||||
qof_collection_mark_clean(col);
|
||||
|
||||
descendants = gnc_account_get_descendants(root);
|
||||
g_list_foreach(descendants, (GFunc)qof_instance_mark_clean, NULL);
|
||||
g_list_free(descendants);
|
||||
}
|
||||
|
||||
static QofObject sxtg_object_def =
|
||||
|
||||
@@ -60,8 +60,7 @@ void gnc_sxes_add_sx(SchedXactions* sxes, SchedXaction* sx);
|
||||
void gnc_sxes_del_sx(SchedXactions* sxes, SchedXaction* sx);
|
||||
|
||||
/** Returns the template group from the book. **/
|
||||
AccountGroup* gnc_book_get_template_group(QofBook* book);
|
||||
AccountGroup* gnc_collection_get_template_group(const QofCollection *col);
|
||||
Account *gnc_book_get_template_root(QofBook *book);
|
||||
|
||||
/** @return The list of SXes which reference the given Account. Caller should free this list. **/
|
||||
GList* gnc_sx_get_sxes_referencing_account(QofBook *book, Account *acct);
|
||||
|
||||
@@ -32,8 +32,6 @@
|
||||
#include "FreqSpec.h"
|
||||
#include "Account.h"
|
||||
#include "gnc-book.h"
|
||||
#include "Group.h"
|
||||
#include "GroupP.h"
|
||||
#include "SX-book.h"
|
||||
#include "SX-ttinfo.h"
|
||||
#include "SchedXaction.h"
|
||||
@@ -52,7 +50,7 @@ void sxprivtransactionListMapDelete( gpointer data, gpointer user_data );
|
||||
static void
|
||||
xaccSchedXactionInit(SchedXaction *sx, QofBook *book)
|
||||
{
|
||||
AccountGroup *ag;
|
||||
Account *ra;
|
||||
|
||||
qof_instance_init (&sx->inst, GNC_ID_SCHEDXACTION, book);
|
||||
|
||||
@@ -82,8 +80,8 @@ xaccSchedXactionInit(SchedXaction *sx, QofBook *book)
|
||||
"template", "template",
|
||||
"template", "template", 1 ) );
|
||||
xaccAccountSetType( sx->template_acct, ACCT_TYPE_BANK );
|
||||
ag = gnc_book_get_template_group( book );
|
||||
xaccGroupInsertAccount( ag, sx->template_acct );
|
||||
ra = gnc_book_get_template_root( book );
|
||||
gnc_account_append_child( ra, sx->template_acct );
|
||||
}
|
||||
|
||||
SchedXaction*
|
||||
|
||||
@@ -45,8 +45,6 @@
|
||||
|
||||
#include "Account.h"
|
||||
#include "AccountP.h"
|
||||
#include "Group.h"
|
||||
#include "GroupP.h"
|
||||
#include "Scrub.h"
|
||||
#include "ScrubP.h"
|
||||
#include "Transaction.h"
|
||||
@@ -57,35 +55,18 @@ static QofLogModule log_module = GNC_MOD_SCRUB;
|
||||
|
||||
/* ================================================================ */
|
||||
|
||||
void
|
||||
xaccGroupScrubOrphans (AccountGroup *grp)
|
||||
{
|
||||
GList *list;
|
||||
GList *node;
|
||||
|
||||
if (!grp) return;
|
||||
|
||||
list = xaccGroupGetAccountList (grp);
|
||||
|
||||
for (node = list; node; node = node->next)
|
||||
{
|
||||
Account *account = node->data;
|
||||
|
||||
xaccAccountTreeScrubOrphans (account);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
xaccAccountTreeScrubOrphans (Account *acc)
|
||||
{
|
||||
if (!acc) return;
|
||||
|
||||
xaccGroupScrubOrphans (xaccAccountGetChildren(acc));
|
||||
xaccAccountScrubOrphans (acc);
|
||||
gnc_account_foreach_descendant(acc,
|
||||
(AccountCb)xaccAccountScrubOrphans, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
TransScrubOrphansFast (Transaction *trans, AccountGroup *root)
|
||||
TransScrubOrphansFast (Transaction *trans, Account *root)
|
||||
{
|
||||
GList *node;
|
||||
|
||||
@@ -125,7 +106,7 @@ xaccAccountScrubOrphans (Account *acc)
|
||||
Split *split = node->data;
|
||||
|
||||
TransScrubOrphansFast (xaccSplitGetParent (split),
|
||||
xaccAccountGetRoot (acc));
|
||||
gnc_account_get_root (acc));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,14 +116,14 @@ xaccTransScrubOrphans (Transaction *trans)
|
||||
{
|
||||
SplitList *node;
|
||||
QofBook *book = NULL;
|
||||
AccountGroup *root = NULL;
|
||||
Account *root = NULL;
|
||||
for (node = trans->splits; node; node = node->next)
|
||||
{
|
||||
Split *split = node->data;
|
||||
|
||||
if (split->acc)
|
||||
{
|
||||
TransScrubOrphansFast (trans, xaccAccountGetRoot(split->acc));
|
||||
TransScrubOrphansFast (trans, gnc_account_get_root(split->acc));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -154,35 +135,20 @@ xaccTransScrubOrphans (Transaction *trans)
|
||||
*/
|
||||
PINFO ("Free Floating Transaction!");
|
||||
book = xaccTransGetBook (trans);
|
||||
root = xaccGetAccountGroup (book);
|
||||
root = gnc_book_get_root_account (book);
|
||||
TransScrubOrphansFast (trans, root);
|
||||
}
|
||||
|
||||
/* ================================================================ */
|
||||
|
||||
void
|
||||
xaccGroupScrubSplits (AccountGroup *group)
|
||||
{
|
||||
GList *list;
|
||||
GList *node;
|
||||
|
||||
if (!group) return;
|
||||
|
||||
list = xaccGroupGetAccountList (group);
|
||||
|
||||
for (node = list; node; node = node->next)
|
||||
{
|
||||
Account *account = node->data;
|
||||
|
||||
xaccAccountTreeScrubSplits (account);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
xaccAccountTreeScrubSplits (Account *account)
|
||||
{
|
||||
xaccGroupScrubSplits (xaccAccountGetChildren(account));
|
||||
if (!account) return;
|
||||
|
||||
xaccAccountScrubSplits (account);
|
||||
gnc_account_foreach_descendant(account,
|
||||
(AccountCb)xaccAccountScrubSplits, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -288,29 +254,12 @@ xaccSplitScrub (Split *split)
|
||||
|
||||
/* ================================================================ */
|
||||
|
||||
void
|
||||
xaccGroupScrubImbalance (AccountGroup *grp)
|
||||
{
|
||||
GList *list;
|
||||
GList *node;
|
||||
|
||||
if (!grp) return;
|
||||
|
||||
list = xaccGroupGetAccountList (grp);
|
||||
|
||||
for (node = list; node; node = node->next)
|
||||
{
|
||||
Account *account = node->data;
|
||||
|
||||
xaccAccountTreeScrubImbalance (account);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
xaccAccountTreeScrubImbalance (Account *acc)
|
||||
{
|
||||
xaccGroupScrubImbalance (xaccAccountGetChildren(acc));
|
||||
xaccAccountScrubImbalance (acc);
|
||||
gnc_account_foreach_descendant(acc,
|
||||
(AccountCb)xaccAccountScrubImbalance, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -332,7 +281,7 @@ xaccAccountScrubImbalance (Account *acc)
|
||||
|
||||
xaccTransScrubCurrencyFromSplits(trans);
|
||||
|
||||
xaccTransScrubImbalance (trans, xaccAccountGetRoot (acc), NULL);
|
||||
xaccTransScrubImbalance (trans, gnc_account_get_root (acc), NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -397,7 +346,7 @@ xaccTransScrubCurrencyFromSplits(Transaction *trans)
|
||||
}
|
||||
|
||||
void
|
||||
xaccTransScrubImbalance (Transaction *trans, AccountGroup *root,
|
||||
xaccTransScrubImbalance (Transaction *trans, Account *root,
|
||||
Account *account)
|
||||
{
|
||||
Split *balance_split = NULL;
|
||||
@@ -418,7 +367,7 @@ xaccTransScrubImbalance (Transaction *trans, AccountGroup *root,
|
||||
{
|
||||
if (!root)
|
||||
{
|
||||
root = xaccGetAccountGroup (xaccTransGetBook (trans));
|
||||
root = gnc_book_get_root_account (xaccTransGetBook (trans));
|
||||
if (NULL == root)
|
||||
{
|
||||
/* This can't occur, things should be in books */
|
||||
@@ -711,6 +660,7 @@ xaccAccountScrubCommodity (Account *account)
|
||||
gnc_commodity *commodity;
|
||||
|
||||
if (!account) return;
|
||||
if (xaccAccountGetType(account) == ACCT_TYPE_ROOT) return;
|
||||
|
||||
commodity = xaccAccountGetCommodity (account);
|
||||
if (commodity) return;
|
||||
@@ -754,27 +704,22 @@ scrub_trans_currency_helper (Transaction *t, gpointer data)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static gpointer
|
||||
static void
|
||||
scrub_account_commodity_helper (Account *account, gpointer data)
|
||||
{
|
||||
xaccAccountScrubCommodity (account);
|
||||
xaccAccountDeleteOldData (account);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
xaccGroupScrubCommodities (AccountGroup *group)
|
||||
xaccAccountTreeScrubCommodities (Account *acc)
|
||||
{
|
||||
if (!group) return;
|
||||
if (!acc) return;
|
||||
|
||||
xaccAccountGroupBeginEdit (group);
|
||||
xaccAccountTreeForEachTransaction (acc, scrub_trans_currency_helper, NULL);
|
||||
|
||||
xaccGroupForEachTransaction (group, scrub_trans_currency_helper, NULL);
|
||||
|
||||
xaccGroupForEachAccount (group, scrub_account_commodity_helper,
|
||||
NULL, TRUE);
|
||||
|
||||
xaccAccountGroupCommitEdit (group);
|
||||
scrub_account_commodity_helper (acc, NULL);
|
||||
gnc_account_foreach_descendant (acc, scrub_account_commodity_helper, NULL);
|
||||
}
|
||||
|
||||
/* ================================================================ */
|
||||
@@ -788,7 +733,7 @@ check_quote_source (gnc_commodity *com, gpointer data)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gpointer
|
||||
static void
|
||||
move_quote_source (Account *account, gpointer data)
|
||||
{
|
||||
gnc_commodity *com;
|
||||
@@ -798,12 +743,12 @@ move_quote_source (Account *account, gpointer data)
|
||||
|
||||
com = xaccAccountGetCommodity(account);
|
||||
if (!com)
|
||||
return NULL;
|
||||
return;
|
||||
|
||||
if (!new_style) {
|
||||
source = dxaccAccountGetPriceSrc(account);
|
||||
if (!source || !*source)
|
||||
return NULL;
|
||||
return;
|
||||
tz = dxaccAccountGetQuoteTZ(account);
|
||||
|
||||
PINFO("to %8s from %s", gnc_commodity_get_mnemonic(com),
|
||||
@@ -818,27 +763,26 @@ move_quote_source (Account *account, gpointer data)
|
||||
|
||||
dxaccAccountSetPriceSrc(account, NULL);
|
||||
dxaccAccountSetQuoteTZ(account, NULL);
|
||||
return NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
xaccGroupScrubQuoteSources (AccountGroup *group, gnc_commodity_table *table)
|
||||
xaccAccountTreeScrubQuoteSources (Account *root, gnc_commodity_table *table)
|
||||
{
|
||||
gboolean new_style = FALSE;
|
||||
ENTER(" ");
|
||||
|
||||
if (!group || !table) {
|
||||
if (!root || !table) {
|
||||
LEAVE("Oops");
|
||||
return;
|
||||
}
|
||||
|
||||
gnc_commodity_table_foreach_commodity (table, check_quote_source, &new_style);
|
||||
|
||||
xaccAccountGroupBeginEdit (group);
|
||||
xaccGroupForEachAccount (group, move_quote_source,
|
||||
GINT_TO_POINTER(new_style), TRUE);
|
||||
xaccAccountGroupCommitEdit (group);
|
||||
move_quote_source(root, GINT_TO_POINTER(new_style));
|
||||
gnc_account_foreach_descendant (root, move_quote_source,
|
||||
GINT_TO_POINTER(new_style));
|
||||
LEAVE("Migration done");
|
||||
}
|
||||
|
||||
@@ -874,7 +818,7 @@ xaccAccountScrubKvp (Account *account)
|
||||
/* ================================================================ */
|
||||
|
||||
Account *
|
||||
xaccScrubUtilityGetOrMakeAccount (AccountGroup *root, gnc_commodity * currency,
|
||||
xaccScrubUtilityGetOrMakeAccount (Account *root, gnc_commodity * currency,
|
||||
const char *name_root)
|
||||
{
|
||||
char * accname;
|
||||
@@ -893,19 +837,19 @@ xaccScrubUtilityGetOrMakeAccount (AccountGroup *root, gnc_commodity * currency,
|
||||
gnc_commodity_get_mnemonic (currency), NULL);
|
||||
|
||||
/* See if we've got one of these going already ... */
|
||||
acc = xaccGetAccountFromName (root, accname);
|
||||
acc = gnc_account_lookup_by_name(root, accname);
|
||||
|
||||
if (acc == NULL)
|
||||
{
|
||||
/* Guess not. We'll have to build one. */
|
||||
acc = xaccMallocAccount (root->book);
|
||||
acc = xaccMallocAccount(gnc_account_get_book (root));
|
||||
xaccAccountBeginEdit (acc);
|
||||
xaccAccountSetName (acc, accname);
|
||||
xaccAccountSetCommodity (acc, currency);
|
||||
xaccAccountSetType (acc, ACCT_TYPE_BANK);
|
||||
|
||||
/* Hang the account off the root. */
|
||||
xaccGroupInsertAccount (root, acc);
|
||||
gnc_account_append_child (root, acc);
|
||||
xaccAccountCommitEdit (acc);
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,6 @@
|
||||
#ifndef XACC_SCRUB_H
|
||||
#define XACC_SCRUB_H
|
||||
|
||||
#include "Group.h"
|
||||
#include "gnc-engine.h"
|
||||
|
||||
/** @name Double-Entry Scrubbing
|
||||
@@ -85,11 +84,6 @@ void xaccAccountScrubOrphans (Account *acc);
|
||||
*/
|
||||
void xaccAccountTreeScrubOrphans (Account *acc);
|
||||
|
||||
/** The xaccGroupScrubOrphans() method performs this scrub for the
|
||||
* child accounts of this group.
|
||||
*/
|
||||
void xaccGroupScrubOrphans (AccountGroup *grp);
|
||||
|
||||
/** The xaccSplitScrub method ensures that if this split has the same
|
||||
* commodity and currency, then it will have the same amount and value.
|
||||
* If the commoidty is the currency, the split->amount is set to the
|
||||
@@ -106,18 +100,16 @@ void xaccSplitScrub (Split *split);
|
||||
void xaccTransScrubSplits (Transaction *trans);
|
||||
void xaccAccountScrubSplits (Account *account);
|
||||
void xaccAccountTreeScrubSplits (Account *account);
|
||||
void xaccGroupScrubSplits (AccountGroup *group);
|
||||
|
||||
/** The xaccScrubImbalance() method searches for transactions that do
|
||||
* not balance to zero. If any such transactions are found, a split
|
||||
* is created to offset this amount and is added to an "imbalance"
|
||||
* account.
|
||||
*/
|
||||
void xaccTransScrubImbalance (Transaction *trans, AccountGroup *root,
|
||||
void xaccTransScrubImbalance (Transaction *trans, Account *root,
|
||||
Account *parent);
|
||||
void xaccAccountScrubImbalance (Account *acc);
|
||||
void xaccAccountTreeScrubImbalance (Account *acc);
|
||||
void xaccGroupScrubImbalance (AccountGroup *grp);
|
||||
|
||||
/** The xaccTransScrubCurrency method fixes transactions without a
|
||||
* common_currency by using the old account currency and security
|
||||
@@ -137,9 +129,10 @@ void xaccTransScrubCurrencyFromSplits(Transaction *trans);
|
||||
* a commodity by using the old account currency and security. */
|
||||
void xaccAccountScrubCommodity (Account *account);
|
||||
|
||||
/** The xaccGroupScrubCommodities will scrub the currency/commodity
|
||||
* of all accounts & transactions in the group. */
|
||||
void xaccGroupScrubCommodities (AccountGroup *group);
|
||||
/** The xaccAccountTreeScrubCommodities will scrub the
|
||||
* currency/commodity of all accounts & transactions in the specified
|
||||
* account or any child account. */
|
||||
void xaccAccountTreeScrubCommodities (Account *acc);
|
||||
|
||||
/** This routine will migrate the information about price quote
|
||||
* sources from the account data structures to the commodity data
|
||||
@@ -148,13 +141,13 @@ void xaccGroupScrubCommodities (AccountGroup *group);
|
||||
* out as part of the account. Just in case anyone needs to fall
|
||||
* back from CVS to a production version of code.
|
||||
*
|
||||
* @param group A pointer to the account group containing all
|
||||
* @param acc A pointer to the root account containing all
|
||||
* accounts in the current book.
|
||||
*
|
||||
* @param table A pointer to the commodity table for the current
|
||||
* book.
|
||||
*/
|
||||
void xaccGroupScrubQuoteSources (AccountGroup *group, gnc_commodity_table *table);
|
||||
void xaccAccountTreeScrubQuoteSources (Account *root, gnc_commodity_table *table);
|
||||
|
||||
void xaccAccountScrubKvp (Account *account);
|
||||
|
||||
|
||||
@@ -36,8 +36,6 @@
|
||||
|
||||
#include "Account.h"
|
||||
#include "AccountP.h"
|
||||
#include "Group.h"
|
||||
#include "GroupP.h"
|
||||
#include "Transaction.h"
|
||||
#include "TransactionP.h"
|
||||
#include "Scrub2.h"
|
||||
|
||||
@@ -40,7 +40,6 @@
|
||||
#include "policy-p.h"
|
||||
#include "Account.h"
|
||||
#include "AccountP.h"
|
||||
#include "Group.h"
|
||||
#include "Scrub2.h"
|
||||
#include "Scrub3.h"
|
||||
#include "Transaction.h"
|
||||
@@ -176,19 +175,11 @@ xaccAccountScrubLots (Account *acc)
|
||||
|
||||
/* ============================================================== */
|
||||
|
||||
static gpointer
|
||||
static void
|
||||
lot_scrub_cb (Account *acc, gpointer data)
|
||||
{
|
||||
if (FALSE == xaccAccountHasTrades (acc)) return NULL;
|
||||
if (FALSE == xaccAccountHasTrades (acc)) return;
|
||||
xaccAccountScrubLots (acc);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
xaccGroupScrubLots (AccountGroup *grp)
|
||||
{
|
||||
if (!grp) return;
|
||||
xaccGroupForEachAccount (grp, lot_scrub_cb, NULL, TRUE);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -196,7 +187,7 @@ xaccAccountTreeScrubLots (Account *acc)
|
||||
{
|
||||
if (!acc) return;
|
||||
|
||||
xaccGroupScrubLots (acc->children);
|
||||
gnc_account_foreach_descendant(acc, lot_scrub_cb, NULL);
|
||||
xaccAccountScrubLots (acc);
|
||||
}
|
||||
|
||||
|
||||
@@ -62,16 +62,11 @@ gboolean xaccScrubLot (GNCLot *lot);
|
||||
* lot structure, and the cap-gains for an account are in good
|
||||
* order.
|
||||
*
|
||||
* The xaccGroupScrubLots() routine walks the account tree, and invokes
|
||||
* xaccAccountScrubLots() on all accounts that are trading accounts.
|
||||
* The xaccAccountTreeScrubLots() does the same.
|
||||
*
|
||||
* Most GUI routines will want to use one of these xacc[*]ScrubLots()
|
||||
* routines, instead of the various component routines, since it will
|
||||
* usually makes sense to work only with these high-level routines.
|
||||
*/
|
||||
void xaccAccountScrubLots (Account *acc);
|
||||
void xaccGroupScrubLots (AccountGroup *grp);
|
||||
void xaccAccountTreeScrubLots (Account *acc);
|
||||
|
||||
/** @} */
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
#include "gnc-engine.h"
|
||||
|
||||
/* Utility to make account by name. Not for public use. */
|
||||
Account * xaccScrubUtilityGetOrMakeAccount (AccountGroup *root,
|
||||
Account * xaccScrubUtilityGetOrMakeAccount (Account *root,
|
||||
gnc_commodity * currency, const char *name_root);
|
||||
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@
|
||||
|
||||
#include "Split.h"
|
||||
#include "AccountP.h"
|
||||
#include "Group.h"
|
||||
#include "Scrub.h"
|
||||
#include "Scrub3.h"
|
||||
#include "TransactionP.h"
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "Account.h"
|
||||
#include "AccountP.h"
|
||||
#include "Transaction.h"
|
||||
#include "TransactionP.h"
|
||||
#include "TransLog.h"
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "AccountP.h"
|
||||
#include "Group.h"
|
||||
#include "Scrub.h"
|
||||
#include "Scrub3.h"
|
||||
#include "TransactionP.h"
|
||||
@@ -1665,47 +1664,11 @@ guint
|
||||
gnc_book_count_transactions(QofBook *book)
|
||||
{
|
||||
guint count = 0;
|
||||
xaccGroupForEachTransaction(xaccGetAccountGroup(book),
|
||||
xaccAccountTreeForEachTransaction(gnc_book_get_root_account(book),
|
||||
counter_thunk, (void*)&count);
|
||||
return count;
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
\********************************************************************/
|
||||
/* walk through the splits, looking for any account */
|
||||
static Account *
|
||||
get_any_account(const Transaction *trans)
|
||||
{
|
||||
GList *node;
|
||||
if (!trans) return NULL;
|
||||
for (node = trans->splits; node; node = node->next)
|
||||
if (((Split *)node->data)->acc)
|
||||
return ((Split *)node->data)->acc;
|
||||
return NULL;
|
||||
}
|
||||
Account *
|
||||
xaccGetAccountByName (const Transaction *trans, const char * name)
|
||||
{
|
||||
Account *acc;
|
||||
if (!trans || !name) return NULL;
|
||||
|
||||
acc = get_any_account(trans);
|
||||
return acc ? xaccGetPeerAccountFromName (acc, name) : NULL;
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
\********************************************************************/
|
||||
|
||||
Account *
|
||||
xaccGetAccountByFullName (const Transaction *trans, const char * name)
|
||||
{
|
||||
Account *acc;
|
||||
if (!trans || !name) return NULL;
|
||||
|
||||
acc = get_any_account(trans);
|
||||
return acc ? xaccGetPeerAccountFromFullName (acc, name) : NULL;
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
\********************************************************************/
|
||||
|
||||
|
||||
@@ -452,16 +452,6 @@ void xaccTransGetDateDueTS (const Transaction *trans, Timespec *ts);
|
||||
\********************************************************************/
|
||||
|
||||
|
||||
/** The xaccGetAccountByName() is a convenience routine that
|
||||
* is essentially identical to xaccGetPeerAccountFromName(),
|
||||
* except that it accepts the handy transaction as root.*/
|
||||
Account * xaccGetAccountByName (const Transaction *trans, const char *name);
|
||||
/** The xaccGetAccountByFullName routine is similar to xaccGetAccountByName, but uses
|
||||
* full names using the given separator.*/
|
||||
Account * xaccGetAccountByFullName (const Transaction *trans,
|
||||
const char *name);
|
||||
|
||||
|
||||
/** @name Transaction voiding
|
||||
@{
|
||||
*/
|
||||
|
||||
@@ -58,10 +58,7 @@ ToDo:
|
||||
#include <glib.h>
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
#include "Account.h"
|
||||
#include "AccountP.h"
|
||||
#include "Group.h"
|
||||
#include "GroupP.h"
|
||||
#include "Scrub2.h"
|
||||
#include "Scrub3.h"
|
||||
#include "Transaction.h"
|
||||
@@ -221,7 +218,7 @@ xaccAccountFindLatestOpenLot (Account *acc, gnc_numeric sign,
|
||||
/* Similar to GetOrMakeAccount, but different in important ways */
|
||||
|
||||
static Account *
|
||||
GetOrMakeLotOrphanAccount (AccountGroup *root, gnc_commodity * currency)
|
||||
GetOrMakeLotOrphanAccount (Account *root, gnc_commodity * currency)
|
||||
{
|
||||
char * accname;
|
||||
Account * acc;
|
||||
@@ -239,12 +236,12 @@ GetOrMakeLotOrphanAccount (AccountGroup *root, gnc_commodity * currency)
|
||||
gnc_commodity_get_mnemonic (currency), NULL);
|
||||
|
||||
/* See if we've got one of these going already ... */
|
||||
acc = xaccGetAccountFromName (root, accname);
|
||||
acc = gnc_account_lookup_by_name(root, accname);
|
||||
|
||||
if (acc == NULL)
|
||||
{
|
||||
/* Guess not. We'll have to build one. */
|
||||
acc = xaccMallocAccount (root->book);
|
||||
acc = xaccMallocAccount (gnc_account_get_book(root));
|
||||
xaccAccountBeginEdit (acc);
|
||||
xaccAccountSetName (acc, accname);
|
||||
xaccAccountSetCommodity (acc, currency);
|
||||
@@ -256,7 +253,7 @@ GetOrMakeLotOrphanAccount (AccountGroup *root, gnc_commodity * currency)
|
||||
"that haven't been recorded elsewhere."));
|
||||
|
||||
/* Hang the account off the root. */
|
||||
xaccGroupInsertAccount (root, acc);
|
||||
gnc_account_append_child (root, acc);
|
||||
xaccAccountCommitEdit (acc);
|
||||
}
|
||||
|
||||
@@ -344,10 +341,10 @@ GetOrMakeGainAcct (Account *acc, gnc_commodity * currency)
|
||||
* for this account, then create such a place */
|
||||
if (NULL == gain_acct)
|
||||
{
|
||||
AccountGroup *root;
|
||||
Account *root;
|
||||
|
||||
xaccAccountBeginEdit (acc);
|
||||
root = xaccAccountGetRoot(acc);
|
||||
root = gnc_account_get_root(acc);
|
||||
gain_acct = GetOrMakeLotOrphanAccount (root, currency);
|
||||
|
||||
vvv = kvp_value_new_guid (xaccAccountGetGUID (gain_acct));
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
#include "cashobjects.h"
|
||||
#include "gnc-engine.h"
|
||||
#include "AccountP.h"
|
||||
#include "GroupP.h"
|
||||
#include "TransactionP.h"
|
||||
#include "FreqSpec.h"
|
||||
#include "SchedXaction.h"
|
||||
@@ -43,7 +42,6 @@ cashobjects_register(void)
|
||||
g_return_val_if_fail(xaccAccountRegister(), FALSE);
|
||||
g_return_val_if_fail ( xaccTransRegister(), FALSE);
|
||||
g_return_val_if_fail ( xaccSplitRegister(), FALSE);
|
||||
g_return_val_if_fail ( xaccGroupRegister(), FALSE);
|
||||
g_return_val_if_fail ( FreqSpecRegister(), FALSE);
|
||||
g_return_val_if_fail ( SXRegister (), FALSE);
|
||||
g_return_val_if_fail ( gnc_sxtt_register(), FALSE);
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "Account.h"
|
||||
#include "Group.h"
|
||||
#include "engine-helpers.h"
|
||||
#include "glib-helpers.h"
|
||||
#include "gnc-date.h"
|
||||
|
||||
@@ -21,10 +21,10 @@
|
||||
|
||||
;; Copyright 2000 Rob Browning <rlb@cs.utexas.edu>
|
||||
|
||||
(define (gnc:group-map-all-accounts thunk group)
|
||||
(let ((accounts (or (xaccGroupGetSubAccountsSorted group) '())))
|
||||
(map thunk accounts)))
|
||||
(define (gnc:account-map-descendants thunk account)
|
||||
(let ((descendants (or (gnc-account-get-descendants-sorted account) '())))
|
||||
(map thunk descendants)))
|
||||
|
||||
(define (gnc:group-map-accounts thunk group)
|
||||
(let ((accounts (or (xaccGroupGetAccountListSorted group) '())))
|
||||
(map thunk accounts)))
|
||||
(define (gnc:account-map-children thunk account)
|
||||
(let ((children (or (gnc-account-get-children-sorted account) '())))
|
||||
(map thunk children)))
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include <config.h>
|
||||
#include <glib.h>
|
||||
#include <qof.h>
|
||||
#include <Group.h>
|
||||
#include <Query.h>
|
||||
#include <gnc-budget.h>
|
||||
#include <gnc-commodity.h>
|
||||
@@ -61,9 +60,6 @@ functions currently used in guile, but not all the functions that are
|
||||
wrapped. So, we should contract the interface to wrap only the used
|
||||
functions. */
|
||||
|
||||
%newobject xaccGroupGetSubAccountsSorted;
|
||||
%newobject xaccGroupGetAccountListSorted;
|
||||
|
||||
%delobject gnc_price_list_destroy;
|
||||
%newobject gnc_pricedb_lookup_latest_any_currency;
|
||||
|
||||
@@ -89,6 +85,14 @@ functions. */
|
||||
|
||||
%include <Split.h>
|
||||
%include <engine-helpers.h>
|
||||
AccountList * gnc_account_get_children (const Account *account);
|
||||
AccountList * gnc_account_get_children_sorted (const Account *account);
|
||||
AccountList * gnc_account_get_descendants (const Account *account);
|
||||
AccountList * gnc_account_get_descendants_sorted (const Account *account);
|
||||
%ignore gnc_account_get_children;
|
||||
%ignore gnc_account_get_children_sorted;
|
||||
%ignore gnc_account_get_descendants;
|
||||
%ignore gnc_account_get_descendants_sorted;
|
||||
%include <Account.h>
|
||||
%include <Transaction.h>
|
||||
%include <gnc-pricedb.h>
|
||||
@@ -96,8 +100,6 @@ functions. */
|
||||
QofSession * qof_session_new (void);
|
||||
QofBook * qof_session_get_book (QofSession *session);
|
||||
|
||||
%include <Group.h>
|
||||
|
||||
// TODO: Maybe unroll
|
||||
void qof_book_kvp_changed (QofBook *book);
|
||||
|
||||
@@ -194,7 +196,7 @@ void gnc_hook_add_scm_dangler (const gchar *name, SCM proc);
|
||||
void gnc_hook_run (const gchar *name, gpointer data);
|
||||
%include <gnc-hooks.h>
|
||||
|
||||
AccountGroup * gnc_book_get_template_group(QofBook *book);
|
||||
Account * gnc_book_get_template_root(QofBook *book);
|
||||
|
||||
// KVP stuff
|
||||
%typemap(in) KvpValue * " $1 = gnc_scm_to_kvp_value_ptr($input); "
|
||||
|
||||
@@ -42,8 +42,8 @@
|
||||
(export GNC_COMMODITY_NS_MUTUAL)
|
||||
|
||||
(export gnc:url->loaded-session)
|
||||
(export gnc:group-map-all-accounts)
|
||||
(export gnc:group-map-accounts)
|
||||
(export gnc:account-map-descendants)
|
||||
(export gnc:account-map-children)
|
||||
|
||||
(export gnc:split-structure)
|
||||
(export gnc:make-split-scm)
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "AccountP.h"
|
||||
#include "gnc-associate-account.h"
|
||||
#include "gnc-engine.h"
|
||||
#include "qof.h"
|
||||
@@ -297,7 +296,8 @@ gnc_tracking_find_expense_accounts(Account *stock_account,
|
||||
kvpd_on_account_list = kvp_frame_get_slot(account_frame,
|
||||
expense_to_key[category]);
|
||||
|
||||
return de_kvp_account_list(kvpd_on_account_list, stock_account->inst.book);
|
||||
return de_kvp_account_list(kvpd_on_account_list,
|
||||
gnc_account_get_book(stock_account));
|
||||
}
|
||||
|
||||
/*********************************************************************\
|
||||
@@ -329,7 +329,8 @@ gnc_tracking_find_income_accounts(Account *stock_account,
|
||||
kvpd_on_account_list = kvp_frame_get_slot(income_acc_frame,
|
||||
income_to_key[category]);
|
||||
|
||||
return de_kvp_account_list(kvpd_on_account_list, stock_account->inst.book);
|
||||
return de_kvp_account_list(kvpd_on_account_list,
|
||||
gnc_account_get_book(stock_account));
|
||||
}
|
||||
|
||||
/*********************************************************************\
|
||||
@@ -440,7 +441,7 @@ gnc_tracking_dissociate_account(Account *inc_or_expense_account)
|
||||
|
||||
inc_or_expense_account_guid = xaccAccountGetGUID(inc_or_expense_account);
|
||||
stock_account = xaccAccountLookup
|
||||
(stock_account_guid, inc_or_expense_account->inst.book);
|
||||
(stock_account_guid, gnc_account_get_book(inc_or_expense_account));
|
||||
|
||||
stock_account_kvpframe = xaccAccountGetSlots(stock_account);
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
#include "glib-compat.h"
|
||||
|
||||
#include "Account.h"
|
||||
#include "Group.h"
|
||||
|
||||
#include "gnc-budget.h"
|
||||
#include "gnc-commodity.h"
|
||||
@@ -290,14 +289,12 @@ is_same_commodity(Account *a, gpointer data)
|
||||
static gboolean
|
||||
xaccAccountChildrenHaveSameCommodity(Account *account)
|
||||
{
|
||||
AccountGroup *grp;
|
||||
gpointer different;
|
||||
gnc_commodity *comm;
|
||||
|
||||
comm = xaccAccountGetCommodity(account);
|
||||
grp = xaccAccountGetChildren(account);
|
||||
different = xaccGroupForEachAccount(
|
||||
grp, is_same_commodity, comm, TRUE);
|
||||
different =
|
||||
gnc_account_foreach_descendant_until(account, is_same_commodity, comm);
|
||||
return (different == NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
#include "qof.h"
|
||||
#include "cashobjects.h"
|
||||
#include "AccountP.h"
|
||||
#include "GroupP.h"
|
||||
#include "SX-book-p.h"
|
||||
#include "gnc-budget.h"
|
||||
#include "TransactionP.h"
|
||||
|
||||
@@ -94,7 +94,6 @@
|
||||
#define GNC_ID_COMMODITY_NAMESPACE "CommodityNamespace"
|
||||
#define GNC_ID_COMMODITY_TABLE "CommodityTable"
|
||||
#define GNC_ID_FREQSPEC "FreqSpec"
|
||||
#define GNC_ID_GROUP "AccountGroup"
|
||||
#define GNC_ID_LOT "Lot"
|
||||
#define GNC_ID_PERIOD "Period"
|
||||
#define GNC_ID_PRICE "Price"
|
||||
@@ -133,10 +132,6 @@
|
||||
* through the functions in Account.h .*/
|
||||
typedef struct account_s Account;
|
||||
|
||||
/** @brief A group of accounts in Gnucash.
|
||||
*/
|
||||
typedef struct account_group_s AccountGroup;
|
||||
|
||||
/** @brief Split in Gnucash.
|
||||
* A "split" is more commonly refered to as a "entry" in a
|
||||
* "transaction". Each split belongs to one Account and one
|
||||
|
||||
@@ -29,8 +29,6 @@
|
||||
|
||||
#include "Account.h"
|
||||
#include "AccountP.h"
|
||||
#include "Group.h"
|
||||
#include "GroupP.h"
|
||||
#include "gnc-engine.h"
|
||||
#include "gnc-session.h"
|
||||
#include "Transaction.h"
|
||||
@@ -50,8 +48,8 @@ static GHashTable *exclude_kvp_types = NULL;
|
||||
static gint kvp_max_depth = 5;
|
||||
static gint kvp_frame_max_elements = 10;
|
||||
|
||||
static gint max_group_depth = 1;
|
||||
static gint max_group_accounts = 3;
|
||||
static gint max_tree_depth = 1;
|
||||
static gint max_level_accounts = 3;
|
||||
static gint max_total_accounts = 10;
|
||||
static gint max_trans_num = 1000;
|
||||
static gint total_num_accounts = 0;
|
||||
@@ -74,15 +72,15 @@ gboolean gnc_engine_debug_random = FALSE;
|
||||
/* Set control parameters governing the run. */
|
||||
|
||||
void
|
||||
set_max_group_depth (gint max_group_depth_in)
|
||||
set_max_account_tree_depth (gint max_tree_depth_in)
|
||||
{
|
||||
max_group_depth = MAX (max_group_depth_in, 1);
|
||||
max_tree_depth = MAX (max_tree_depth_in, 1);
|
||||
}
|
||||
|
||||
void
|
||||
set_max_group_accounts (gint max_group_accounts_in)
|
||||
set_max_accounts_per_level (gint max_level_accounts_in)
|
||||
{
|
||||
max_group_accounts = MAX (max_group_accounts_in, 1);
|
||||
max_level_accounts = MAX (max_level_accounts_in, 1);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -843,7 +841,7 @@ account_add_subaccounts (QofBook *book, Account *account, int depth)
|
||||
{
|
||||
Account *sub = get_random_account (book);
|
||||
|
||||
xaccAccountInsertSubAccount (account, sub);
|
||||
gnc_account_append_child (account, sub);
|
||||
|
||||
total_num_accounts ++;
|
||||
if (total_num_accounts > max_total_accounts) return;
|
||||
@@ -853,64 +851,40 @@ account_add_subaccounts (QofBook *book, Account *account, int depth)
|
||||
}
|
||||
|
||||
static void
|
||||
make_random_group_depth (QofBook *book, AccountGroup *group, int depth)
|
||||
{
|
||||
int num_accounts;
|
||||
|
||||
g_return_if_fail (book);
|
||||
g_return_if_fail (group);
|
||||
|
||||
if (depth <= 0)
|
||||
return;
|
||||
|
||||
num_accounts = get_random_int_in_range (1, max_group_accounts);
|
||||
|
||||
while (num_accounts-- > 0)
|
||||
{
|
||||
Account *account = get_random_account (book);
|
||||
|
||||
xaccGroupInsertAccount (group, account);
|
||||
total_num_accounts++;
|
||||
|
||||
account_add_subaccounts (book, account, depth - 1);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
make_random_group (QofBook *book, AccountGroup *group)
|
||||
make_random_account_tree (QofBook *book, Account *root)
|
||||
{
|
||||
int depth;
|
||||
|
||||
g_return_if_fail (book);
|
||||
g_return_if_fail (group);
|
||||
g_return_if_fail (root);
|
||||
|
||||
total_num_accounts = 0;
|
||||
depth = get_random_int_in_range (1, max_group_depth);
|
||||
depth = get_random_int_in_range (1, max_tree_depth);
|
||||
|
||||
make_random_group_depth (book, group, depth);
|
||||
account_add_subaccounts (book, root, depth);
|
||||
|
||||
/* Make sure we have at least two accounts! */
|
||||
if (total_num_accounts <= 1)
|
||||
make_random_group_depth (book, group, 1);
|
||||
account_add_subaccounts (book, root, 1);
|
||||
}
|
||||
|
||||
AccountGroup *
|
||||
get_random_group (QofBook *book)
|
||||
Account *
|
||||
get_random_account_tree (QofBook *book)
|
||||
{
|
||||
AccountGroup * group;
|
||||
Account * root;
|
||||
|
||||
g_return_val_if_fail (book, NULL);
|
||||
|
||||
group = xaccGetAccountGroup (book);
|
||||
if (!group)
|
||||
root = gnc_book_get_root_account (book);
|
||||
if (!root)
|
||||
{
|
||||
group = xaccMallocAccountGroup (book);
|
||||
xaccSetAccountGroup (book, group);
|
||||
root = xaccMallocAccount (book);
|
||||
gnc_book_set_root_account (book, root);
|
||||
}
|
||||
|
||||
make_random_group (book, group);
|
||||
make_random_account_tree (book, root);
|
||||
|
||||
return group;
|
||||
return root;
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
@@ -1078,7 +1052,7 @@ add_trans_helper (Transaction *trans, gpointer data)
|
||||
}
|
||||
|
||||
void
|
||||
make_random_changes_to_group (QofBook *book, AccountGroup *group)
|
||||
make_random_changes_to_level (QofBook *book, Account *parent)
|
||||
{
|
||||
Account *new_account;
|
||||
Account *account;
|
||||
@@ -1087,24 +1061,24 @@ make_random_changes_to_group (QofBook *book, AccountGroup *group)
|
||||
GList *splits;
|
||||
GList *node;
|
||||
|
||||
g_return_if_fail (group && book);
|
||||
g_return_if_fail (parent && book);
|
||||
|
||||
accounts = xaccGroupGetSubAccounts (group);
|
||||
accounts = gnc_account_get_descendants (parent);
|
||||
|
||||
/* Add a new account */
|
||||
new_account = get_random_account (book);
|
||||
|
||||
if (get_random_boolean () || !accounts)
|
||||
xaccGroupInsertAccount (group, new_account);
|
||||
gnc_account_append_child (parent, new_account);
|
||||
else
|
||||
{
|
||||
account = get_random_list_element (accounts);
|
||||
|
||||
xaccAccountInsertSubAccount (account, new_account);
|
||||
gnc_account_append_child (account, new_account);
|
||||
}
|
||||
|
||||
g_list_free (accounts);
|
||||
accounts = xaccGroupGetSubAccounts (group);
|
||||
accounts = gnc_account_get_descendants (parent);
|
||||
|
||||
/* Add some new transactions */
|
||||
add_random_transactions_to_book (book, get_random_int_in_range (1, 6));
|
||||
@@ -1120,7 +1094,7 @@ make_random_changes_to_group (QofBook *book, AccountGroup *group)
|
||||
|
||||
/* Mess with the transactions & splits */
|
||||
transes = NULL;
|
||||
xaccGroupForEachTransaction (group, add_trans_helper, &transes);
|
||||
xaccAccountTreeForEachTransaction (parent, add_trans_helper, &transes);
|
||||
|
||||
for (node = transes; node; node = node->next)
|
||||
{
|
||||
@@ -1166,7 +1140,7 @@ make_random_changes_to_group (QofBook *book, AccountGroup *group)
|
||||
g_list_free (splits);
|
||||
g_list_free (accounts);
|
||||
|
||||
accounts = xaccGroupGetSubAccounts (group);
|
||||
accounts = gnc_account_get_descendants (parent);
|
||||
|
||||
/* move some accounts around */
|
||||
if (accounts && (g_list_length (accounts) > 1))
|
||||
@@ -1186,7 +1160,7 @@ make_random_changes_to_group (QofBook *book, AccountGroup *group)
|
||||
|
||||
if (!a2)
|
||||
{
|
||||
xaccGroupInsertAccount (group, a1);
|
||||
gnc_account_append_child (parent, a1);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1198,7 +1172,7 @@ make_random_changes_to_group (QofBook *book, AccountGroup *group)
|
||||
continue;
|
||||
}
|
||||
|
||||
xaccAccountInsertSubAccount (a2, a1);
|
||||
gnc_account_append_child (a2, a1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1208,8 +1182,7 @@ make_random_changes_to_group (QofBook *book, AccountGroup *group)
|
||||
Account*
|
||||
get_random_account(QofBook *book)
|
||||
{
|
||||
AccountGroup *grp;
|
||||
Account *ret;
|
||||
Account *root, *ret;
|
||||
int tmp_int;
|
||||
|
||||
ret = xaccMallocAccount(book);
|
||||
@@ -1229,13 +1202,13 @@ get_random_account(QofBook *book)
|
||||
|
||||
xaccAccountSetSlots_nc(ret, get_random_kvp_frame());
|
||||
|
||||
grp = xaccGetAccountGroup (book);
|
||||
if (!grp)
|
||||
root = gnc_book_get_root_account (book);
|
||||
if (!root)
|
||||
{
|
||||
grp = xaccMallocAccountGroup (book);
|
||||
xaccSetAccountGroup (book, grp);
|
||||
root = xaccMallocAccount (book);
|
||||
gnc_book_set_root_account (book, root);
|
||||
}
|
||||
xaccGroupInsertAccount (grp, ret);
|
||||
gnc_account_append_child (root, ret);
|
||||
xaccAccountCommitEdit(ret);
|
||||
|
||||
return ret;
|
||||
@@ -1435,7 +1408,7 @@ get_random_transaction_with_currency(QofBook *book,
|
||||
numstr = g_new0(gchar, 10);
|
||||
if (!account_list)
|
||||
{
|
||||
account_list = xaccGroupGetSubAccounts (xaccGetAccountGroup (book));
|
||||
account_list = gnc_account_get_descendants (gnc_book_get_root_account (book));
|
||||
}
|
||||
|
||||
/* Gotta have at least two different accounts */
|
||||
@@ -1883,7 +1856,7 @@ get_random_book (void)
|
||||
|
||||
book = qof_book_new ();
|
||||
|
||||
get_random_group (book);
|
||||
get_random_account_tree (book);
|
||||
get_random_pricedb (book);
|
||||
|
||||
return book;
|
||||
@@ -1899,7 +1872,7 @@ get_random_session (void)
|
||||
|
||||
book = qof_session_get_book (session);
|
||||
|
||||
get_random_group (book);
|
||||
get_random_account_tree (book);
|
||||
get_random_pricedb (book);
|
||||
|
||||
return session;
|
||||
@@ -1915,7 +1888,7 @@ add_random_transactions_to_book (QofBook *book, gint num_transactions)
|
||||
|
||||
g_return_if_fail (book);
|
||||
|
||||
accounts = xaccGroupGetSubAccounts (xaccGetAccountGroup (book));
|
||||
accounts = gnc_account_get_descendants (gnc_book_get_root_account (book));
|
||||
g_return_if_fail (accounts);
|
||||
|
||||
table = gnc_commodity_table_get_table (book);
|
||||
@@ -1936,7 +1909,7 @@ make_random_changes_to_book (QofBook *book)
|
||||
{
|
||||
g_return_if_fail (book);
|
||||
|
||||
make_random_changes_to_group (book, xaccGetAccountGroup (book));
|
||||
make_random_changes_to_level (book, gnc_book_get_root_account (book));
|
||||
make_random_changes_to_pricedb (book, gnc_pricedb_get_db (book));
|
||||
|
||||
#if 0
|
||||
|
||||
@@ -36,13 +36,13 @@ void random_glist_strings_only (gboolean strings_only);
|
||||
void kvp_exclude_type (KvpValueType kvp_type);
|
||||
void set_max_kvp_depth (gint max_kvp_depth);
|
||||
void set_max_kvp_frame_elements (gint max_kvp_frame_elements);
|
||||
void set_max_group_depth (gint max_group_depth);
|
||||
void set_max_group_accounts (gint max_group_accounts);
|
||||
void set_max_account_tree_depth (gint max_tree_depth);
|
||||
void set_max_accounts_per_level (gint max_accounts);
|
||||
|
||||
GNCPrice * get_random_price(QofBook *book);
|
||||
gboolean make_random_pricedb (QofBook *book, GNCPriceDB *pdb);
|
||||
GNCPriceDB * get_random_pricedb(QofBook *book);
|
||||
AccountGroup * get_random_group(QofBook * book);
|
||||
Account * get_random_account_tree(QofBook * book);
|
||||
Account* get_random_account(QofBook * book);
|
||||
Split* get_random_split(QofBook *book, Account *account, Transaction *trn);
|
||||
Transaction* get_random_transaction(QofBook *book);
|
||||
@@ -85,7 +85,7 @@ void make_random_changes_to_transaction_and_splits (QofBook *book,
|
||||
Transaction *trans,
|
||||
GList *accounts);
|
||||
void make_random_changes_to_account (QofBook *book, Account *account);
|
||||
void make_random_changes_to_group (QofBook *book, AccountGroup *group);
|
||||
void make_random_changes_to_level (QofBook *book, Account *parent);
|
||||
void make_random_changes_to_book (QofBook *book);
|
||||
void make_random_changes_to_session (QofSession *session);
|
||||
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
|
||||
(let* ((session (qof-session-new))
|
||||
(book (qof-session-get-book session))
|
||||
(group (xaccMallocAccountGroup book))
|
||||
(root (xaccMallocAccount book))
|
||||
(acct (xaccMallocAccount book)))
|
||||
(xaccAccountBeginEdit acct)
|
||||
(xaccAccountSetName acct "foo")
|
||||
(xaccAccountCommitEdit acct)
|
||||
(xaccGroupInsertAccount group acct))
|
||||
(gnc-account-append-child root acct))
|
||||
#t)
|
||||
|
||||
@@ -25,34 +25,30 @@
|
||||
#include <glib.h>
|
||||
#include "qof.h"
|
||||
#include "cashobjects.h"
|
||||
#include "Group.h"
|
||||
#include "GroupP.h"
|
||||
#include "Account.h"
|
||||
#include "TransLog.h"
|
||||
#include "gnc-engine.h"
|
||||
#include "test-engine-stuff.h"
|
||||
#include "test-stuff.h"
|
||||
|
||||
static gboolean
|
||||
group_has_book (AccountGroup *group, QofBook *book)
|
||||
account_tree_has_book (Account *parent, QofBook *book)
|
||||
{
|
||||
GList *node;
|
||||
GList *children, *node;
|
||||
|
||||
if (!group)
|
||||
if (!parent)
|
||||
return (book == NULL);
|
||||
|
||||
if (xaccGroupGetBook (group) != book)
|
||||
if (gnc_account_get_book(parent) != book)
|
||||
return FALSE;
|
||||
|
||||
for (node = xaccGroupGetAccountList (group); node; node = node->next)
|
||||
children = gnc_account_get_children(parent);
|
||||
for (node = children; node; node = node->next)
|
||||
{
|
||||
AccountGroup *children = xaccAccountGetChildren (node->data);
|
||||
|
||||
if (!children)
|
||||
continue;
|
||||
|
||||
if (!group_has_book (children, book))
|
||||
if (!account_tree_has_book (node->data, book))
|
||||
return FALSE;
|
||||
}
|
||||
g_list_free(children);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@@ -61,8 +57,8 @@ group_has_book (AccountGroup *group, QofBook *book)
|
||||
static void
|
||||
run_test (void)
|
||||
{
|
||||
AccountGroup *group1;
|
||||
AccountGroup *group2;
|
||||
Account *root1;
|
||||
Account *root2;
|
||||
Account *account1;
|
||||
Account *account2;
|
||||
QofBook *book;
|
||||
@@ -74,16 +70,16 @@ run_test (void)
|
||||
exit(get_rv());
|
||||
}
|
||||
|
||||
group1 = get_random_group (book);
|
||||
if(!group1)
|
||||
root1 = get_random_account (book);
|
||||
if(!root1)
|
||||
{
|
||||
failure("group1 not created");
|
||||
failure("root1 not created");
|
||||
exit(get_rv());
|
||||
}
|
||||
|
||||
if (!group_has_book (group1, book))
|
||||
if (!account_tree_has_book (root1, book))
|
||||
{
|
||||
failure("new group has wrong book");
|
||||
failure("new root has wrong book");
|
||||
exit(get_rv());
|
||||
}
|
||||
|
||||
@@ -93,34 +89,34 @@ run_test (void)
|
||||
* interface. the maintenance of the correct
|
||||
* book pointers is important for correct
|
||||
* engine operation. */
|
||||
xaccSetAccountGroup (book, group1);
|
||||
if (!group_has_book (group1, book))
|
||||
gnc_book_set_root_account (book, root1);
|
||||
if (!account_tree_has_book (root1, book))
|
||||
{
|
||||
failure("xaccSetAccountGroup didn't take");
|
||||
failure("gnc_book_set_root_account didn't take");
|
||||
exit(get_rv());
|
||||
}
|
||||
|
||||
group2 = get_random_group (book);
|
||||
if(!group2)
|
||||
root2 = get_random_account (book);
|
||||
if(!root2)
|
||||
{
|
||||
failure("group2 not created");
|
||||
failure("root2 not created");
|
||||
exit(get_rv());
|
||||
}
|
||||
|
||||
xaccSetAccountGroup (book, group2);
|
||||
gnc_book_set_root_account (book, root2);
|
||||
|
||||
#if 0
|
||||
/* a group cannot have a 'null' book; this test is nonsense. */
|
||||
if (!group_has_book (group1, NULL))
|
||||
if (!account_tree_has_book (root1, NULL))
|
||||
{
|
||||
failure("xaccSetAccountGroup didn't clear old");
|
||||
failure("gnc_book_set_root_account didn't clear old");
|
||||
exit(get_rv());
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!group_has_book (group2, book))
|
||||
if (!account_tree_has_book (root2, book))
|
||||
{
|
||||
failure("xaccSetAccountGroup didn't take");
|
||||
failure("gnc_book_set_root_account didn't take");
|
||||
exit(get_rv());
|
||||
}
|
||||
|
||||
@@ -131,8 +127,8 @@ run_test (void)
|
||||
exit(get_rv());
|
||||
}
|
||||
|
||||
xaccGroupInsertAccount (group2, account1);
|
||||
if (group2 != xaccAccountGetParent (account1))
|
||||
gnc_account_append_child (root2, account1);
|
||||
if (root2 != gnc_account_get_parent (account1))
|
||||
{
|
||||
failure("group insert account didn't work");
|
||||
exit(get_rv());
|
||||
@@ -145,15 +141,15 @@ run_test (void)
|
||||
exit(get_rv());
|
||||
}
|
||||
|
||||
xaccAccountInsertSubAccount (account1, account2);
|
||||
if (!group_has_book (xaccAccountGetParent (account2), book))
|
||||
gnc_account_append_child (account1, account2);
|
||||
if (!account_tree_has_book (gnc_account_get_parent (account2), book))
|
||||
{
|
||||
failure("account2 has wrong book");
|
||||
exit(get_rv());
|
||||
}
|
||||
|
||||
xaccGroupRemoveAccount (group2, account1);
|
||||
if (xaccAccountGetParent (account1) != NULL)
|
||||
gnc_account_remove_child (root2, account1);
|
||||
if (gnc_account_get_parent (account1) != NULL)
|
||||
{
|
||||
failure("remove group didn't take");
|
||||
exit(get_rv());
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#include <glib.h>
|
||||
#include "qof.h"
|
||||
#include "Account.h"
|
||||
#include "Group.h"
|
||||
#include "Scrub3.h"
|
||||
#include "cashobjects.h"
|
||||
#include "test-stuff.h"
|
||||
@@ -45,7 +44,7 @@ run_test (void)
|
||||
{
|
||||
QofSession *sess;
|
||||
QofBook *book;
|
||||
AccountGroup *grp;
|
||||
Account *root;
|
||||
|
||||
/* --------------------------------------------------------- */
|
||||
/* In the first test, we will merely try to see if we can run
|
||||
@@ -56,8 +55,8 @@ run_test (void)
|
||||
|
||||
add_random_transactions_to_book (book, transaction_num);
|
||||
|
||||
grp = xaccGetAccountGroup (book);
|
||||
xaccGroupScrubLots (grp);
|
||||
root = gnc_book_get_root_account (book);
|
||||
xaccAccountTreeScrubLots (root);
|
||||
|
||||
/* --------------------------------------------------------- */
|
||||
/* In the second test, we create an account with unrealized gains,
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
#include <time.h>
|
||||
#include "cashobjects.h"
|
||||
#include "Account.h"
|
||||
#include "Group.h"
|
||||
#include "Period.h"
|
||||
#include "test-stuff.h"
|
||||
#include "test-engine-stuff.h"
|
||||
@@ -44,9 +43,8 @@ run_test (void)
|
||||
{
|
||||
QofSession *sess1, *sess2;
|
||||
QofBook *openbook, *closedbook;
|
||||
AccountGroup *grp;
|
||||
AccountList *acclist, *anode;
|
||||
Account *acc, *equity;
|
||||
GList *acclist, *anode;
|
||||
Account *root, *acc, *equity;
|
||||
SplitList *splist;
|
||||
Split *sfirst, *slast;
|
||||
Transaction *tfirst, *tlast;
|
||||
@@ -66,9 +64,9 @@ run_test (void)
|
||||
|
||||
add_random_transactions_to_book (openbook, num_trans);
|
||||
|
||||
grp = xaccGetAccountGroup (openbook);
|
||||
root = gnc_book_get_root_account (openbook);
|
||||
|
||||
acclist = xaccGroupGetSubAccounts (grp);
|
||||
acclist = gnc_account_get_descendants (root);
|
||||
for (anode=acclist; anode; anode=anode->next)
|
||||
{
|
||||
int ns;
|
||||
@@ -77,10 +75,11 @@ run_test (void)
|
||||
if (2 <= ns) break;
|
||||
acc = NULL;
|
||||
}
|
||||
g_list_free(acclist);
|
||||
|
||||
if(!acc)
|
||||
{
|
||||
failure("group didn't have accounts with enough splits");
|
||||
failure("book didn't have accounts with enough splits");
|
||||
exit(get_rv());
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#include <glib.h>
|
||||
#include "qof.h"
|
||||
#include "cashobjects.h"
|
||||
#include "Group.h"
|
||||
#include "Transaction.h"
|
||||
#include "TransLog.h"
|
||||
#include "gnc-engine.h"
|
||||
@@ -70,16 +69,16 @@ static void
|
||||
run_test (void)
|
||||
{
|
||||
QofSession *session;
|
||||
AccountGroup *group;
|
||||
Account *root;
|
||||
QofBook *book;
|
||||
|
||||
session = get_random_session ();
|
||||
book = qof_session_get_book (session);
|
||||
group = xaccGetAccountGroup (book);
|
||||
root = gnc_book_get_root_account (book);
|
||||
|
||||
add_random_transactions_to_book (book, 20);
|
||||
|
||||
xaccGroupForEachTransaction (group, test_trans_query, book);
|
||||
xaccAccountTreeForEachTransaction (root, test_trans_query, book);
|
||||
|
||||
qof_session_end (session);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
|
||||
#include "gnc-book.h"
|
||||
#include "gnc-engine.h"
|
||||
#include "Group.h"
|
||||
#include "io-gncxml.h"
|
||||
|
||||
#include <fcgi_stdio.h>
|
||||
@@ -213,7 +212,7 @@ main (int argc, char *argv[])
|
||||
int err, fake_argc =1;
|
||||
char * fake_argv[] = {"hello", 0};
|
||||
GNCBook *book;
|
||||
AccountGroup *grp;
|
||||
Account *root;
|
||||
char *request_bufp, *reply_bufp;
|
||||
int rc, sz;
|
||||
|
||||
@@ -230,8 +229,8 @@ main (int argc, char *argv[])
|
||||
rc = gnc_book_load (book);
|
||||
if (!rc) goto bookerrexit;
|
||||
|
||||
/* the grp pointer points to our local cache of the data */
|
||||
grp = gnc_book_get_group (book);
|
||||
/* the root pointer points to our local cache of the data */
|
||||
root = gnc_book_get_root_account (book);
|
||||
|
||||
/* --------------------------------------------------- */
|
||||
/* done with initialization, go into event loop */
|
||||
@@ -326,7 +325,7 @@ main (int argc, char *argv[])
|
||||
* in, send them the full set of accounts.
|
||||
* (Do not send them any transactions yet).
|
||||
*/
|
||||
gncxml_write_group_to_buf(grp, &reply_bufp, &sz);
|
||||
gncxml_write_account_tree_to_buf(root, &reply_bufp, &sz);
|
||||
|
||||
/* send the xml to the client */
|
||||
printf ("%s", reply_bufp);
|
||||
@@ -345,7 +344,7 @@ main (int argc, char *argv[])
|
||||
|
||||
/* conver the xml input into a gnucash query structure... */
|
||||
q = gncxml_read_query (request_bufp, read_len);
|
||||
xaccQuerySetGroup (q, grp);
|
||||
xaccQuerySetGroup (q, root);
|
||||
|
||||
/* hack -- limit to 30 splits ... */
|
||||
xaccQuerySetMaxSplits (q, 30);
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
|
||||
#include "gnc-book.h"
|
||||
#include "gnc-engine.h"
|
||||
#include "Group.h"
|
||||
#include "io-gncxml.h"
|
||||
#include "Query.h"
|
||||
|
||||
@@ -22,7 +21,7 @@ main (int argc, char *argv[])
|
||||
int fake_argc =1;
|
||||
char * fake_argv[] = {"hello2", 0};
|
||||
GNCBook *book;
|
||||
AccountGroup *grp;
|
||||
Account *root;
|
||||
Query *q, *qq;
|
||||
GList *split_list, *sl2, *node;
|
||||
Split *s;
|
||||
@@ -54,12 +53,12 @@ main (int argc, char *argv[])
|
||||
goto bookerrexit;
|
||||
}
|
||||
|
||||
/* the grp pointer points to our local cache of the data */
|
||||
grp = gnc_book_get_group (book);
|
||||
/* the root pointer points to our local cache of the data */
|
||||
root = gnc_book_get_root_account (book);
|
||||
|
||||
/* build a query */
|
||||
q = xaccMallocQuery ();
|
||||
xaccQuerySetGroup (q, grp);
|
||||
xaccQuerySetGroup (q, root);
|
||||
xaccQuerySetMaxSplits (q, 30);
|
||||
|
||||
/* Get everything between some random dates */
|
||||
@@ -81,7 +80,7 @@ main (int argc, char *argv[])
|
||||
gncxml_write_query_to_buf(q, &bufp, &sz);
|
||||
qq = gncxml_read_query (bufp, sz);
|
||||
xaccQuerySetMaxSplits (qq, 30);
|
||||
xaccQuerySetGroup (qq, grp);
|
||||
xaccQuerySetGroup (qq, root);
|
||||
sl2 = xaccQueryGetSplits (qq);
|
||||
|
||||
/* count number of splits */
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
#include "gnc-book.h"
|
||||
#include "gnc-engine.h"
|
||||
#include "Group.h"
|
||||
#include "io-gncxml.h"
|
||||
|
||||
#include <fcgi_stdio.h>
|
||||
@@ -28,7 +27,7 @@ main (int argc, char *argv[])
|
||||
int err, fake_argc =1;
|
||||
char * fake_argv[] = {"hello", 0};
|
||||
GNCBook *book;
|
||||
AccountGroup *grp;
|
||||
Account *root;
|
||||
char *bufp;
|
||||
int rc, sz;
|
||||
|
||||
@@ -44,8 +43,8 @@ main (int argc, char *argv[])
|
||||
rc = gnc_book_load (book);
|
||||
if (!rc) goto bookerrexit;
|
||||
|
||||
/* the grp pointer points to our local cache of the data */
|
||||
grp = gnc_book_get_group (book);
|
||||
/* the root pointer points to our local cache of the data */
|
||||
root = gnc_book_get_root_account (book);
|
||||
|
||||
/* --------------------------------------------------- */
|
||||
/* done with initialization, go into event loop */
|
||||
@@ -65,7 +64,7 @@ main (int argc, char *argv[])
|
||||
* but not the transactions/splits. */
|
||||
if (!strcmp ("GET", request_method))
|
||||
{
|
||||
gncxml_write_group_to_buf(grp, &bufp, &sz);
|
||||
gncxml_write_account_tree_to_buf(root, &bufp, &sz);
|
||||
|
||||
/* print the HTTP header */
|
||||
printf("Content-type: text/gnc-xml\r\n"
|
||||
@@ -92,7 +91,7 @@ main (int argc, char *argv[])
|
||||
|
||||
/* conver the xml input into a gnucash query structure... */
|
||||
q = gncxml_read_query (bufp, read_len);
|
||||
xaccQuerySetGroup (q, grp);
|
||||
xaccQuerySetGroup (q, root);
|
||||
|
||||
/* hack -- limit to 30 splits ... */
|
||||
xaccQuerySetMaxSplits (q, 30);
|
||||
|
||||
@@ -54,7 +54,7 @@ typedef struct {
|
||||
gboolean load_list_store;
|
||||
GtkListStore *list_store;
|
||||
QofBook *book;
|
||||
AccountGroup *group;
|
||||
Account *root;
|
||||
gint listener;
|
||||
AccountBoolCB dont_add_cb;
|
||||
gpointer dont_add_data;
|
||||
@@ -105,7 +105,7 @@ shared_quickfill_find_accounts (GtkTreeModel *model,
|
||||
|
||||
|
||||
/* Splat the account name into the shared quickfill object */
|
||||
static gpointer
|
||||
static void
|
||||
load_shared_qf_cb (Account *account, gpointer data)
|
||||
{
|
||||
QFB *qfb = data;
|
||||
@@ -115,11 +115,11 @@ load_shared_qf_cb (Account *account, gpointer data)
|
||||
if (qfb->dont_add_cb)
|
||||
{
|
||||
gboolean skip = (qfb->dont_add_cb) (account, qfb->dont_add_data);
|
||||
if (skip) return NULL;
|
||||
if (skip) return;
|
||||
}
|
||||
|
||||
name = xaccAccountGetFullName (account);
|
||||
if (NULL == name) return NULL;
|
||||
if (NULL == name) return;
|
||||
gnc_quickfill_insert (qfb->qf, name, QUICKFILL_ALPHA);
|
||||
if (qfb->load_list_store) {
|
||||
gtk_list_store_append (qfb->list_store, &iter);
|
||||
@@ -129,8 +129,6 @@ load_shared_qf_cb (Account *account, gpointer data)
|
||||
-1);
|
||||
}
|
||||
g_free(name);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -142,7 +140,7 @@ shared_quickfill_gconf_changed (GConfEntry *entry, gpointer user_data)
|
||||
gnc_quickfill_purge(qfb->qf);
|
||||
gtk_list_store_clear(qfb->list_store);
|
||||
qfb->load_list_store = TRUE;
|
||||
xaccGroupForEachAccount (qfb->group, load_shared_qf_cb, qfb, TRUE);
|
||||
gnc_account_foreach_descendant(qfb->root, load_shared_qf_cb, qfb);
|
||||
qfb->load_list_store = FALSE;
|
||||
}
|
||||
|
||||
@@ -151,7 +149,7 @@ shared_quickfill_gconf_changed (GConfEntry *entry, gpointer user_data)
|
||||
* Essentially same loop as in gnc_load_xfer_cell() above.
|
||||
*/
|
||||
static QFB *
|
||||
build_shared_quickfill (QofBook *book, AccountGroup *group, const char * key,
|
||||
build_shared_quickfill (QofBook *book, Account *root, const char * key,
|
||||
AccountBoolCB cb, gpointer data)
|
||||
{
|
||||
QFB *qfb;
|
||||
@@ -159,7 +157,7 @@ build_shared_quickfill (QofBook *book, AccountGroup *group, const char * key,
|
||||
qfb = g_new0(QFB, 1);
|
||||
qfb->qf = gnc_quickfill_new ();
|
||||
qfb->book = book;
|
||||
qfb->group = group;
|
||||
qfb->root = root;
|
||||
qfb->listener = 0;
|
||||
qfb->dont_add_cb = cb;
|
||||
qfb->dont_add_data = data;
|
||||
@@ -171,7 +169,7 @@ build_shared_quickfill (QofBook *book, AccountGroup *group, const char * key,
|
||||
shared_quickfill_gconf_changed,
|
||||
qfb);
|
||||
|
||||
xaccGroupForEachAccount (group, load_shared_qf_cb, qfb, TRUE);
|
||||
gnc_account_foreach_descendant(root, load_shared_qf_cb, qfb);
|
||||
qfb->load_list_store = FALSE;
|
||||
|
||||
qfb->listener =
|
||||
@@ -183,36 +181,36 @@ build_shared_quickfill (QofBook *book, AccountGroup *group, const char * key,
|
||||
}
|
||||
|
||||
QuickFill *
|
||||
gnc_get_shared_account_name_quickfill (AccountGroup *group,
|
||||
gnc_get_shared_account_name_quickfill (Account *root,
|
||||
const char * key,
|
||||
AccountBoolCB cb, gpointer cb_data)
|
||||
{
|
||||
QFB *qfb;
|
||||
QofBook *book;
|
||||
|
||||
book = xaccGroupGetBook (group);
|
||||
book = gnc_account_get_book (root);
|
||||
qfb = qof_book_get_data (book, key);
|
||||
|
||||
if (qfb) return qfb->qf;
|
||||
|
||||
qfb = build_shared_quickfill (book, group, key, cb, cb_data);
|
||||
qfb = build_shared_quickfill (book, root, key, cb, cb_data);
|
||||
return qfb->qf;
|
||||
}
|
||||
|
||||
GtkListStore *
|
||||
gnc_get_shared_account_name_list_store (AccountGroup *group,
|
||||
gnc_get_shared_account_name_list_store (Account *root,
|
||||
const char * key,
|
||||
AccountBoolCB cb, gpointer cb_data)
|
||||
{
|
||||
QFB *qfb;
|
||||
QofBook *book;
|
||||
|
||||
book = xaccGroupGetBook (group);
|
||||
book = gnc_account_get_book (root);
|
||||
qfb = qof_book_get_data (book, key);
|
||||
|
||||
if (qfb) return qfb->list_store;
|
||||
|
||||
qfb = build_shared_quickfill (book, group, key, cb, cb_data);
|
||||
qfb = build_shared_quickfill (book, root, key, cb, cb_data);
|
||||
return qfb->list_store;
|
||||
}
|
||||
|
||||
@@ -245,8 +243,8 @@ listen_for_account_events (QofEntity *entity, QofEventId event_type,
|
||||
ENTER("entity %p, event type %x, user data %p, ecent data %p",
|
||||
entity, event_type, user_data, event_data);
|
||||
|
||||
if (xaccAccountGetRoot(account) != qfb->group) {
|
||||
LEAVE("root group mismatch");
|
||||
if (gnc_account_get_root(account) != qfb->root) {
|
||||
LEAVE("root account mismatch");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -262,7 +260,7 @@ listen_for_account_events (QofEntity *entity, QofEventId event_type,
|
||||
|
||||
/* Find the account (and all its descendants) in the model. The
|
||||
* full name of all these accounts has changed. */
|
||||
data.accounts = xaccAccountGetDescendants(account);
|
||||
data.accounts = gnc_account_get_descendants(account);
|
||||
data.accounts = g_list_prepend(data.accounts, account);
|
||||
gtk_tree_model_foreach(GTK_TREE_MODEL(qfb->list_store),
|
||||
shared_quickfill_find_accounts, &data);
|
||||
@@ -313,7 +311,7 @@ listen_for_account_events (QofEntity *entity, QofEventId event_type,
|
||||
|
||||
/* Remove from qf */
|
||||
gnc_quickfill_purge(qfb->qf);
|
||||
xaccGroupForEachAccount (qfb->group, load_shared_qf_cb, qfb, TRUE);
|
||||
gnc_account_foreach_descendant(qfb->root, load_shared_qf_cb, qfb);
|
||||
|
||||
/* Does the account exist in the model? */
|
||||
data.accounts = g_list_append(NULL, account);
|
||||
|
||||
@@ -43,7 +43,6 @@
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "Account.h"
|
||||
#include "Group.h"
|
||||
#include "QuickFill.h"
|
||||
|
||||
typedef gboolean (*AccountBoolCB) (Account *, gpointer);
|
||||
@@ -57,7 +56,7 @@ typedef gboolean (*AccountBoolCB) (Account *, gpointer);
|
||||
* the quickfill. The 'cb_data' is passed to the callback.
|
||||
*
|
||||
* The quickfill is created only once; it is then stored with
|
||||
* the QofBook that is the parent of the AccountGroup. It is
|
||||
* the QofBook that is the parent of the root account. It is
|
||||
* automatically destroyed when the QofBook is destroyed.
|
||||
*
|
||||
* Multiple, distinct quickfills, for different uses, are allowed.
|
||||
@@ -69,12 +68,12 @@ typedef gboolean (*AccountBoolCB) (Account *, gpointer);
|
||||
* it). This code does not currently listen to account-destroy
|
||||
* events.
|
||||
*/
|
||||
QuickFill * gnc_get_shared_account_name_quickfill (AccountGroup *group,
|
||||
QuickFill * gnc_get_shared_account_name_quickfill (Account *root,
|
||||
const char * key,
|
||||
AccountBoolCB skip_cb,
|
||||
gpointer cb_data);
|
||||
GtkListStore *
|
||||
gnc_get_shared_account_name_list_store (AccountGroup *group,
|
||||
gnc_get_shared_account_name_list_store (Account *root,
|
||||
const char * key,
|
||||
AccountBoolCB cb, gpointer cb_data);
|
||||
|
||||
|
||||
@@ -70,13 +70,13 @@ typedef enum
|
||||
|
||||
typedef struct _AccountWindow
|
||||
{
|
||||
QofBook *book;
|
||||
gboolean modal;
|
||||
GtkWidget *dialog;
|
||||
|
||||
AccountDialogType dialog_type;
|
||||
|
||||
GUID account;
|
||||
Account *top_level_account; /* owned by the model */
|
||||
Account *created_account;
|
||||
|
||||
gchar **subaccount_names;
|
||||
@@ -161,7 +161,7 @@ aw_get_account (AccountWindow *aw)
|
||||
if (!aw)
|
||||
return NULL;
|
||||
|
||||
return xaccAccountLookup (&aw->account, gnc_get_current_book ());
|
||||
return xaccAccountLookup (&aw->account, aw->book);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -246,7 +246,8 @@ gnc_account_to_ui(AccountWindow *aw)
|
||||
|
||||
|
||||
static gboolean
|
||||
gnc_account_create_transfer_balance (Account *account,
|
||||
gnc_account_create_transfer_balance (QofBook *book,
|
||||
Account *account,
|
||||
Account *transfer,
|
||||
gnc_numeric balance,
|
||||
time_t date)
|
||||
@@ -263,7 +264,7 @@ gnc_account_create_transfer_balance (Account *account,
|
||||
xaccAccountBeginEdit (account);
|
||||
xaccAccountBeginEdit (transfer);
|
||||
|
||||
trans = xaccMallocTransaction (gnc_get_current_book ());
|
||||
trans = xaccMallocTransaction (book);
|
||||
|
||||
xaccTransBeginEdit (trans);
|
||||
|
||||
@@ -271,7 +272,7 @@ gnc_account_create_transfer_balance (Account *account,
|
||||
xaccTransSetDateSecs (trans, date);
|
||||
xaccTransSetDescription (trans, _("Opening Balance"));
|
||||
|
||||
split = xaccMallocSplit (gnc_get_current_book ());
|
||||
split = xaccMallocSplit (book);
|
||||
|
||||
xaccTransAppendSplit (trans, split);
|
||||
xaccAccountInsertSplit (account, split);
|
||||
@@ -281,7 +282,7 @@ gnc_account_create_transfer_balance (Account *account,
|
||||
|
||||
balance = gnc_numeric_neg (balance);
|
||||
|
||||
split = xaccMallocSplit (gnc_get_current_book ());
|
||||
split = xaccMallocSplit (book);
|
||||
|
||||
xaccTransAppendSplit (trans, split);
|
||||
xaccAccountInsertSplit (transfer, split);
|
||||
@@ -383,18 +384,11 @@ gnc_ui_to_account(AccountWindow *aw)
|
||||
xaccAccountSetHidden (account, flag);
|
||||
|
||||
parent_account = gnc_tree_view_account_get_selected_account (GNC_TREE_VIEW_ACCOUNT (aw->parent_tree));
|
||||
if (parent_account == aw->top_level_account)
|
||||
parent_account = NULL;
|
||||
|
||||
if (parent_account != NULL)
|
||||
{
|
||||
xaccAccountBeginEdit (parent_account);
|
||||
if (parent_account != xaccAccountGetParentAccount (account))
|
||||
xaccAccountInsertSubAccount (parent_account, account);
|
||||
xaccAccountCommitEdit (parent_account);
|
||||
}
|
||||
else
|
||||
xaccGroupInsertAccount (gnc_get_current_group (), account);
|
||||
if (parent_account == NULL)
|
||||
parent_account = gnc_book_get_root_account(aw->book);
|
||||
if (parent_account != gnc_account_get_parent (account))
|
||||
gnc_account_append_child (parent_account, account);
|
||||
|
||||
xaccAccountCommitEdit (account);
|
||||
|
||||
@@ -417,8 +411,7 @@ gnc_ui_to_account(AccountWindow *aw)
|
||||
|
||||
if (use_equity)
|
||||
{
|
||||
if (!gnc_account_create_opening_balance (account, balance, date,
|
||||
gnc_get_current_book ()))
|
||||
if (!gnc_account_create_opening_balance (account, balance, date, aw->book))
|
||||
{
|
||||
const char *message = _("Could not create opening balance.");
|
||||
gnc_error_dialog(aw->dialog, message);
|
||||
@@ -434,7 +427,7 @@ gnc_ui_to_account(AccountWindow *aw)
|
||||
return;
|
||||
}
|
||||
|
||||
gnc_account_create_transfer_balance (account, transfer, balance, date);
|
||||
gnc_account_create_transfer_balance (aw->book, account, transfer, balance, date);
|
||||
}
|
||||
LEAVE(" ");
|
||||
}
|
||||
@@ -443,14 +436,13 @@ gnc_ui_to_account(AccountWindow *aw)
|
||||
static void
|
||||
set_children_types (Account *account, GNCAccountType type)
|
||||
{
|
||||
AccountGroup *children;
|
||||
GList *iter;
|
||||
GList *children, *iter;
|
||||
|
||||
children = xaccAccountGetChildren (account);
|
||||
children = gnc_account_get_children(account);
|
||||
if (children == NULL)
|
||||
return;
|
||||
|
||||
for (iter=xaccGroupGetAccountList (children); iter; iter=iter->next) {
|
||||
for (iter=children; iter; iter=iter->next) {
|
||||
account = iter->data;
|
||||
if (type == xaccAccountGetType(account))
|
||||
continue;
|
||||
@@ -464,6 +456,7 @@ set_children_types (Account *account, GNCAccountType type)
|
||||
|
||||
set_children_types (account, type);
|
||||
}
|
||||
g_list_free(children);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -505,7 +498,7 @@ gnc_finish_ok (AccountWindow *aw)
|
||||
gnc_suspend_gui_refresh ();
|
||||
|
||||
parent = aw_get_account (aw);
|
||||
account = xaccMallocAccount (gnc_get_current_book ());
|
||||
account = xaccMallocAccount (aw->book);
|
||||
aw->account = *xaccAccountGetGUID (account);
|
||||
aw->type = xaccAccountGetType (parent);
|
||||
|
||||
@@ -551,8 +544,7 @@ add_children_to_expander (GObject *object, GParamSpec *param_spec, gpointer data
|
||||
if (gtk_expander_get_expanded (expander) &&
|
||||
!gtk_bin_get_child (GTK_BIN (expander))) {
|
||||
|
||||
view = gnc_tree_view_account_new_with_group (
|
||||
xaccAccountGetChildren (account), FALSE);
|
||||
view = gnc_tree_view_account_new_with_root (account, FALSE);
|
||||
|
||||
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
|
||||
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
|
||||
@@ -573,7 +565,6 @@ static gboolean
|
||||
verify_children_compatible (AccountWindow *aw)
|
||||
{
|
||||
Account *account;
|
||||
AccountGroup *children;
|
||||
GtkWidget *dialog, *vbox, *hbox, *label, *expander;
|
||||
gchar *str;
|
||||
gboolean result;
|
||||
@@ -588,9 +579,7 @@ verify_children_compatible (AccountWindow *aw)
|
||||
if (xaccAccountTypesCompatible (xaccAccountGetType (account), aw->type))
|
||||
return TRUE;
|
||||
|
||||
children = xaccAccountGetChildren (account);
|
||||
if (!children ||
|
||||
!xaccGroupGetNumAccounts (children))
|
||||
if (gnc_account_n_children(account) == 0)
|
||||
return TRUE;
|
||||
|
||||
dialog = gtk_dialog_new_with_buttons ("",
|
||||
@@ -684,7 +673,7 @@ gnc_filter_parent_accounts (Account *account, gpointer data)
|
||||
if (aw_account == NULL)
|
||||
return FALSE;
|
||||
|
||||
if (account == aw->top_level_account)
|
||||
if (gnc_account_is_root(account))
|
||||
return TRUE;
|
||||
|
||||
if (account == aw_account)
|
||||
@@ -700,14 +689,13 @@ gnc_filter_parent_accounts (Account *account, gpointer data)
|
||||
static gboolean
|
||||
gnc_common_ok (AccountWindow *aw)
|
||||
{
|
||||
Account *account, *parent;
|
||||
AccountGroup *group;
|
||||
Account *root, *account, *parent;
|
||||
gnc_commodity * commodity;
|
||||
gchar *fullname, *fullname_parent;
|
||||
const gchar *name, *separator;
|
||||
|
||||
ENTER("aw %p", aw);
|
||||
group = gnc_get_current_group ();
|
||||
root = gnc_book_get_root_account (aw->book);
|
||||
|
||||
separator = gnc_get_account_separator_string();
|
||||
|
||||
@@ -724,12 +712,12 @@ gnc_common_ok (AccountWindow *aw)
|
||||
parent = gnc_tree_view_account_get_selected_account
|
||||
(GNC_TREE_VIEW_ACCOUNT (aw->parent_tree));
|
||||
if (parent == NULL) {
|
||||
account = xaccGetAccountFromFullName(group, name);
|
||||
account = gnc_account_lookup_by_full_name(root, name);
|
||||
} else {
|
||||
fullname_parent = xaccAccountGetFullName(parent);
|
||||
fullname = g_strconcat(fullname_parent, separator, name, NULL);
|
||||
|
||||
account = xaccGetAccountFromFullName(group, fullname);
|
||||
account = gnc_account_lookup_by_full_name(root, fullname);
|
||||
|
||||
g_free(fullname_parent);
|
||||
g_free(fullname);
|
||||
@@ -759,7 +747,7 @@ gnc_common_ok (AccountWindow *aw)
|
||||
}
|
||||
|
||||
/* check whether the types of child and parent are compatible */
|
||||
if (parent != aw->top_level_account &&
|
||||
if (!gnc_account_is_root(parent) &&
|
||||
!xaccAccountTypesCompatible (aw->type, xaccAccountGetType (parent))) {
|
||||
const char *message = _("The selected account type is incompatible with "
|
||||
"the one of the selected parent.");
|
||||
@@ -945,8 +933,6 @@ gnc_account_window_destroy_cb (GtkObject *object, gpointer data)
|
||||
|
||||
gnc_unregister_gui_component (aw->component_id);
|
||||
|
||||
aw->top_level_account = NULL;
|
||||
|
||||
gnc_resume_gui_refresh ();
|
||||
|
||||
if (aw->subaccount_names) {
|
||||
@@ -976,7 +962,7 @@ gnc_account_parent_changed_cb (GtkTreeSelection *selection, gpointer data)
|
||||
if (!parent_account)
|
||||
return;
|
||||
|
||||
if (parent_account == aw->top_level_account) {
|
||||
if (gnc_account_is_root(parent_account)) {
|
||||
types = aw->valid_types;
|
||||
} else {
|
||||
types = aw->valid_types &
|
||||
@@ -1232,15 +1218,12 @@ gnc_account_window_create(AccountWindow *aw)
|
||||
|
||||
box = glade_xml_get_widget (xml, "parent_scroll");
|
||||
|
||||
// group = gnc_book_get_group (gnc_get_current_book ());
|
||||
aw->parent_tree = gnc_tree_view_account_new(TRUE);
|
||||
gtk_container_add(GTK_CONTAINER(box), GTK_WIDGET(aw->parent_tree));
|
||||
gtk_widget_show(GTK_WIDGET(aw->parent_tree));
|
||||
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (aw->parent_tree));
|
||||
g_signal_connect (G_OBJECT (selection), "changed",
|
||||
G_CALLBACK (gnc_account_parent_changed_cb), aw);
|
||||
aw->top_level_account =
|
||||
gnc_tree_view_account_get_top_level (GNC_TREE_VIEW_ACCOUNT(aw->parent_tree));
|
||||
|
||||
aw->tax_related_button = glade_xml_get_widget (xml, "tax_related_button");
|
||||
aw->placeholder_button = glade_xml_get_widget (xml, "placeholder_button");
|
||||
@@ -1302,13 +1285,9 @@ get_ui_fullname (AccountWindow *aw)
|
||||
if (!name || *name == '\0')
|
||||
name = _("<No name>");
|
||||
|
||||
parent_account = NULL;
|
||||
|
||||
parent_account = gnc_tree_view_account_get_selected_account (GNC_TREE_VIEW_ACCOUNT (aw->parent_tree));
|
||||
if (parent_account == aw->top_level_account)
|
||||
parent_account = NULL;
|
||||
|
||||
if (parent_account)
|
||||
if (!gnc_account_is_root(parent_account))
|
||||
{
|
||||
char *parent_name;
|
||||
const gchar *separator;
|
||||
@@ -1421,7 +1400,8 @@ refresh_handler (GHashTable *changes, gpointer user_data)
|
||||
|
||||
|
||||
static AccountWindow *
|
||||
gnc_ui_new_account_window_internal (Account *base_account,
|
||||
gnc_ui_new_account_window_internal (QofBook *book,
|
||||
Account *base_account,
|
||||
gchar **subaccount_names,
|
||||
GList *valid_types,
|
||||
gnc_commodity * default_commodity,
|
||||
@@ -1432,16 +1412,15 @@ gnc_ui_new_account_window_internal (Account *base_account,
|
||||
Account *account;
|
||||
GList *list;
|
||||
|
||||
g_return_val_if_fail(book, NULL);
|
||||
|
||||
aw = g_new0 (AccountWindow, 1);
|
||||
|
||||
aw->book = book;
|
||||
aw->modal = modal;
|
||||
aw->dialog_type = NEW_ACCOUNT;
|
||||
|
||||
aw->valid_types = 0;
|
||||
for (list = valid_types; list; list = list->next)
|
||||
aw->valid_types |= (1 << GPOINTER_TO_INT (list->data));
|
||||
|
||||
account = xaccMallocAccount (gnc_get_current_book ());
|
||||
account = xaccMallocAccount (book);
|
||||
aw->account = *xaccAccountGetGUID (account);
|
||||
|
||||
if (base_account) {
|
||||
@@ -1477,8 +1456,9 @@ gnc_ui_new_account_window_internal (Account *base_account,
|
||||
commodity);
|
||||
gnc_account_commodity_from_type (aw, FALSE);
|
||||
|
||||
if (base_account == NULL)
|
||||
base_account = aw->top_level_account;
|
||||
if (base_account == NULL) {
|
||||
base_account = gnc_book_get_root_account(book);
|
||||
}
|
||||
|
||||
gtk_tree_view_collapse_all (aw->parent_tree);
|
||||
gnc_tree_view_account_set_selected_account (
|
||||
@@ -1504,21 +1484,20 @@ gnc_ui_new_account_window_internal (Account *base_account,
|
||||
|
||||
|
||||
static gchar **
|
||||
gnc_split_account_name (const char *in_name, Account **base_account)
|
||||
gnc_split_account_name (QofBook *book, const char *in_name, Account **base_account)
|
||||
{
|
||||
AccountGroup *group;
|
||||
Account *account;
|
||||
Account *root, *account;
|
||||
gchar **names, **ptr, **out_names;
|
||||
GList *list, *node;
|
||||
|
||||
group = gnc_get_current_group ();
|
||||
root = gnc_book_get_root_account (book);
|
||||
list = gnc_account_get_children(root);
|
||||
names = g_strsplit(in_name, gnc_get_account_separator_string(), -1);
|
||||
|
||||
for (ptr = names; *ptr; ptr++) {
|
||||
/* Stop if there are no children at the current level. */
|
||||
if (group == NULL)
|
||||
if (list == NULL)
|
||||
break;
|
||||
list = xaccGroupGetAccountList (group);
|
||||
|
||||
/* Look for the first name in the children. */
|
||||
for (node = list; node; node = g_list_next(node)) {
|
||||
@@ -1535,11 +1514,14 @@ gnc_split_account_name (const char *in_name, Account **base_account)
|
||||
if (node == NULL)
|
||||
break;
|
||||
|
||||
group = xaccAccountGetChildren (account);
|
||||
g_list_free(list);
|
||||
list = gnc_account_get_children (account);
|
||||
}
|
||||
|
||||
out_names = g_strdupv(ptr);
|
||||
g_strfreev(names);
|
||||
if (list)
|
||||
g_list_free(list);
|
||||
return out_names;
|
||||
}
|
||||
|
||||
@@ -1567,6 +1549,7 @@ gnc_ui_new_accounts_from_name_with_defaults (const char *name,
|
||||
gnc_commodity * default_commodity,
|
||||
Account * parent)
|
||||
{
|
||||
QofBook *book;
|
||||
AccountWindow *aw;
|
||||
Account *base_account = NULL;
|
||||
Account *created_account = NULL;
|
||||
@@ -1576,19 +1559,20 @@ gnc_ui_new_accounts_from_name_with_defaults (const char *name,
|
||||
|
||||
ENTER("name %s, valid %p, commodity %p, account %p",
|
||||
name, valid_types, default_commodity, parent);
|
||||
book = gnc_get_current_book();
|
||||
if (!name || *name == '\0')
|
||||
{
|
||||
subaccount_names = NULL;
|
||||
base_account = NULL;
|
||||
}
|
||||
else
|
||||
subaccount_names = gnc_split_account_name (name, &base_account);
|
||||
subaccount_names = gnc_split_account_name (book, name, &base_account);
|
||||
|
||||
if (parent != NULL)
|
||||
{
|
||||
base_account=parent;
|
||||
}
|
||||
aw = gnc_ui_new_account_window_internal (base_account, subaccount_names,
|
||||
aw = gnc_ui_new_account_window_internal (book, base_account, subaccount_names,
|
||||
valid_types, default_commodity,
|
||||
TRUE);
|
||||
|
||||
@@ -1659,6 +1643,7 @@ gnc_ui_edit_account_window(Account *account)
|
||||
|
||||
aw = g_new0 (AccountWindow, 1);
|
||||
|
||||
aw->book = gnc_account_get_book(account);
|
||||
aw->modal = FALSE;
|
||||
aw->dialog_type = EDIT_ACCOUNT;
|
||||
aw->account = *xaccAccountGetGUID (account);
|
||||
@@ -1675,9 +1660,9 @@ gnc_ui_edit_account_window(Account *account)
|
||||
gtk_widget_show_all (aw->dialog);
|
||||
gtk_widget_hide (aw->opening_balance_page);
|
||||
|
||||
parent = xaccAccountGetParentAccount (account);
|
||||
parent = gnc_account_get_parent (account);
|
||||
if (parent == NULL)
|
||||
parent = aw->top_level_account;
|
||||
parent = account; /* must be at the root */
|
||||
|
||||
gtk_tree_view_collapse_all (aw->parent_tree);
|
||||
gnc_tree_view_account_set_selected_account (
|
||||
@@ -1703,33 +1688,24 @@ gnc_ui_edit_account_window(Account *account)
|
||||
/*
|
||||
* opens up a window to create a new account
|
||||
*
|
||||
* Args: group - not used
|
||||
* Args: book - containing book for the new account
|
||||
* parent - The initial parent for the new account (optional)
|
||||
*/
|
||||
void
|
||||
gnc_ui_new_account_window (AccountGroup *this_is_not_used)
|
||||
gnc_ui_new_account_window(QofBook *book, Account *parent)
|
||||
{
|
||||
/* FIXME get_current_account went away. */
|
||||
gnc_ui_new_account_window_internal (NULL, NULL, NULL, NULL, FALSE);
|
||||
}
|
||||
g_return_if_fail(book != NULL);
|
||||
if (parent && book)
|
||||
g_return_if_fail(gnc_account_get_book(parent) == book);
|
||||
|
||||
/*
|
||||
* opens up a window to create a new account
|
||||
*
|
||||
* Args: group - not used
|
||||
* parent - The initial parent for the new account
|
||||
*/
|
||||
void
|
||||
gnc_ui_new_account_window_with_default(AccountGroup *this_is_not_used,
|
||||
Account * parent)
|
||||
{
|
||||
gnc_ui_new_account_window_internal (parent, NULL, NULL, NULL, FALSE);
|
||||
gnc_ui_new_account_window_internal (book, parent, NULL, NULL, NULL, FALSE);
|
||||
}
|
||||
|
||||
void
|
||||
gnc_ui_new_account_with_types( AccountGroup *unused,
|
||||
gnc_ui_new_account_with_types( QofBook *book,
|
||||
GList *valid_types )
|
||||
{
|
||||
gnc_ui_new_account_window_internal( NULL, NULL, valid_types, NULL, FALSE );
|
||||
gnc_ui_new_account_window_internal( book, NULL, NULL, valid_types, NULL, FALSE );
|
||||
}
|
||||
|
||||
/************************************************************
|
||||
@@ -1798,7 +1774,6 @@ gnc_account_renumber_response_cb (GtkDialog *dialog,
|
||||
gint response,
|
||||
RenumberDialog *data)
|
||||
{
|
||||
AccountGroup *group;
|
||||
GList *children, *tmp;
|
||||
gchar *str;
|
||||
gchar *prefix;
|
||||
@@ -1806,8 +1781,7 @@ gnc_account_renumber_response_cb (GtkDialog *dialog,
|
||||
|
||||
if (response == GTK_RESPONSE_OK) {
|
||||
gtk_widget_hide(data->dialog);
|
||||
group = xaccAccountGetChildren(data->parent);
|
||||
children = xaccGroupGetAccountListSorted(group);
|
||||
children = gnc_account_get_children(data->parent);
|
||||
prefix = gtk_editable_get_chars(GTK_EDITABLE(data->prefix), 0, -1);
|
||||
interval =
|
||||
gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(data->interval));
|
||||
@@ -1820,6 +1794,7 @@ gnc_account_renumber_response_cb (GtkDialog *dialog,
|
||||
g_free(str);
|
||||
}
|
||||
gnc_unset_busy_cursor (NULL);
|
||||
g_list_free(children);
|
||||
}
|
||||
|
||||
gtk_widget_destroy(data->dialog);
|
||||
@@ -1831,14 +1806,12 @@ gnc_account_renumber_create_dialog (GtkWidget *window, Account *account)
|
||||
{
|
||||
RenumberDialog *data;
|
||||
GladeXML *xml;
|
||||
AccountGroup *children;
|
||||
GtkWidget *widget;
|
||||
gchar *string;
|
||||
|
||||
data = g_new(RenumberDialog, 1);
|
||||
data->parent = account;
|
||||
children = xaccAccountGetChildren(account);
|
||||
data->num_children = xaccGroupGetNumAccounts(children);
|
||||
data->num_children = gnc_account_n_children(account);
|
||||
|
||||
xml = gnc_glade_xml_new ("account.glade", "Renumber Accounts");
|
||||
data->dialog = glade_xml_get_widget (xml, "Renumber Accounts");
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#define DIALOG_ACCOUNT_H
|
||||
|
||||
#include "Account.h"
|
||||
#include "Group.h"
|
||||
|
||||
/** @addtogroup GUI
|
||||
@{ */
|
||||
@@ -52,28 +51,24 @@
|
||||
void gnc_ui_edit_account_window (Account *account);
|
||||
|
||||
|
||||
/** Disply a window for creating a new account
|
||||
*
|
||||
* @param group This parameter is not used.
|
||||
*/
|
||||
void gnc_ui_new_account_window (AccountGroup *group);
|
||||
|
||||
|
||||
/** Disply a window for creating a new account. This function will
|
||||
* also initially set the parent account of the new account to what
|
||||
* the caller specified. The user is free, however, to choose any
|
||||
* parent account they wish.
|
||||
*
|
||||
* @param group This parameter is not used.
|
||||
* @param book The book in which the new account should be created.
|
||||
* This is a required argument.
|
||||
*
|
||||
* @param parent The initially selected parent account.
|
||||
* @param parent The initially selected parent account. This
|
||||
* argument is optional, but if supplied must be an account contained
|
||||
* in the specified book.
|
||||
*/
|
||||
void gnc_ui_new_account_window_with_default (AccountGroup *group,
|
||||
Account * parent);
|
||||
void gnc_ui_new_account_window (QofBook *book, Account *parent);
|
||||
|
||||
|
||||
/** Disply a window for creating a new account. This function will
|
||||
* restrict the available account type values to the list specified by the caller.
|
||||
* restrict the available account type values to the list specified
|
||||
* by the caller.
|
||||
*
|
||||
* @param unused This parameter is not used.
|
||||
*
|
||||
@@ -81,7 +76,7 @@ void gnc_ui_new_account_window_with_default (AccountGroup *group,
|
||||
* which are allowed to be created. The calling function is
|
||||
* responsible for freeing this list.
|
||||
*/
|
||||
void gnc_ui_new_account_with_types (AccountGroup *unused,
|
||||
void gnc_ui_new_account_with_types (QofBook *book,
|
||||
GList *valid_types);
|
||||
/** @} */
|
||||
|
||||
|
||||
@@ -1872,7 +1872,7 @@ gnc_xfer_dialog (GtkWidget * parent, Account * initial)
|
||||
xferData->transaction_cb = NULL;
|
||||
|
||||
if (initial) {
|
||||
book = xaccAccountGetBook (initial);
|
||||
book = gnc_account_get_book (initial);
|
||||
} else {
|
||||
book = gnc_get_current_book ();
|
||||
}
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
|
||||
#include "dialog-utils.h"
|
||||
#include "gnc-commodity.h"
|
||||
#include "Group.h"
|
||||
#include "gnc-path.h"
|
||||
#include "gnc-engine.h"
|
||||
#include "gnc-euro.h"
|
||||
|
||||
@@ -171,7 +171,7 @@ void
|
||||
gas_populate_list( GNCAccountSel *gas )
|
||||
{
|
||||
account_filter_data atnd;
|
||||
AccountGroup *ag;
|
||||
Account *root;
|
||||
Account *acc;
|
||||
GtkTreeIter iter;
|
||||
GtkEntry *entry;
|
||||
@@ -183,8 +183,8 @@ gas_populate_list( GNCAccountSel *gas )
|
||||
currentSel = gtk_editable_get_chars(
|
||||
GTK_EDITABLE(entry), 0, -1 );
|
||||
|
||||
ag = gnc_book_get_group( gnc_get_current_book() );
|
||||
accts = (GList*)xaccGroupGetSubAccountsSorted( ag );
|
||||
root = gnc_book_get_root_account( gnc_get_current_book() );
|
||||
accts = gnc_account_get_descendants_sorted( root );
|
||||
|
||||
filteredAccts = NULL;
|
||||
atnd.gas = gas;
|
||||
@@ -404,7 +404,7 @@ gas_new_account_click( GtkButton *b, gpointer ud )
|
||||
gnc_ui_new_accounts_from_name_window_with_types ( NULL,
|
||||
gas->acctTypeFilters );
|
||||
else
|
||||
gnc_ui_new_account_with_types( NULL, gas->acctTypeFilters );
|
||||
gnc_ui_new_account_with_types( gnc_get_current_book(), gas->acctTypeFilters );
|
||||
}
|
||||
|
||||
gint
|
||||
@@ -442,7 +442,7 @@ gnc_account_sel_purge_account( GNCAccountSel *gas,
|
||||
while (acc) {
|
||||
if (acc == target)
|
||||
break;
|
||||
acc = xaccAccountGetParentAccount(acc);
|
||||
acc = gnc_account_get_parent(acc);
|
||||
}
|
||||
|
||||
if (acc == target)
|
||||
|
||||
@@ -738,7 +738,7 @@ gnc_post_file_open (const char * filename)
|
||||
|
||||
if (!uh_oh)
|
||||
{
|
||||
AccountGroup *new_group;
|
||||
Account *new_root;
|
||||
|
||||
char * logpath = xaccResolveFilePath(newfile);
|
||||
PINFO ("logpath=%s", logpath ? logpath : "(null)");
|
||||
@@ -770,12 +770,12 @@ gnc_post_file_open (const char * filename)
|
||||
|
||||
uh_oh = show_session_error (io_err, newfile, GNC_FILE_DIALOG_OPEN);
|
||||
|
||||
new_group = gnc_book_get_group (qof_session_get_book (new_session));
|
||||
if (uh_oh) new_group = NULL;
|
||||
new_root = gnc_book_get_root_account (qof_session_get_book (new_session));
|
||||
if (uh_oh) new_root = NULL;
|
||||
|
||||
/* Umm, came up empty-handed, but no error:
|
||||
* The backend forgot to set an error. So make one up. */
|
||||
if (!uh_oh && !new_group)
|
||||
if (!uh_oh && !new_root)
|
||||
{
|
||||
uh_oh = show_session_error (ERR_BACKEND_MISC, newfile,
|
||||
GNC_FILE_DIALOG_OPEN);
|
||||
@@ -791,11 +791,11 @@ gnc_post_file_open (const char * filename)
|
||||
qof_session_destroy (new_session);
|
||||
xaccLogEnable();
|
||||
|
||||
/* well, no matter what, I think it's a good idea to have a
|
||||
* topgroup around. For example, early in the gnucash startup
|
||||
/* well, no matter what, I think it's a good idea to have a root
|
||||
* account around. For example, early in the gnucash startup
|
||||
* sequence, the user opens a file; if this open fails for any
|
||||
* reason, we don't want to leave them high & dry without a
|
||||
* topgroup, because if the user continues, then bad things will
|
||||
* reason, we don't want to leave them high & dry without a root
|
||||
* account, because if the user continues, then bad things will
|
||||
* happen. */
|
||||
gnc_get_current_session ();
|
||||
|
||||
|
||||
@@ -44,7 +44,6 @@
|
||||
#include <gtkhtml/gtkhtml-embedded.h>
|
||||
|
||||
#include "Account.h"
|
||||
#include "Group.h"
|
||||
#include "print-session.h"
|
||||
#include "gnc-engine.h"
|
||||
#include "gnc-gui-query.h"
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user