From 962512ab7de17e98845b00131b0dd9bd87b3259b Mon Sep 17 00:00:00 2001 From: Phil Longstaff Date: Thu, 25 Mar 2010 18:32:40 +0000 Subject: [PATCH] Extend xaccXXXXXEqual() routines so that they can compare objects in different books to see if they have the same contents. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18962 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/engine/Split.c | 10 +++++++--- src/engine/Transaction.c | 27 +++++++++++++++++++++------ src/engine/gnc-commodity.c | 6 +++++- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/engine/Split.c b/src/engine/Split.c index e8ae62c41b..e0b8a817d0 100644 --- a/src/engine/Split.c +++ b/src/engine/Split.c @@ -540,6 +540,8 @@ xaccSplitEqual(const Split *sa, const Split *sb, gboolean check_balances, gboolean check_txn_splits) { + gboolean same_book; + if (!sa && !sb) return TRUE; /* Arguable. FALSE is better, methinks */ if (!sa || !sb) @@ -550,6 +552,8 @@ xaccSplitEqual(const Split *sa, const Split *sb, if (sa == sb) return TRUE; + same_book = qof_instance_get_book(QOF_INSTANCE(sa)) == qof_instance_get_book(QOF_INSTANCE(sb)); + if (check_guids) { if (qof_instance_guid_compare(sa, sb) != 0) @@ -559,15 +563,15 @@ xaccSplitEqual(const Split *sa, const Split *sb, } } - /* Since these strings are cached we can just use pointer equality */ - if (sa->memo != sb->memo) + /* If the same book, since these strings are cached we can just use pointer equality */ + if ((same_book && sa->memo != sb->memo) || (!same_book && safe_strcmp(sa->memo, sb->memo) != 0)) { PWARN ("memos differ: (%p)%s vs (%p)%s", sa->memo, sa->memo, sb->memo, sb->memo); return FALSE; } - if (sa->action != sb->action) + if ((same_book && sa->action != sb->action) || (!same_book && safe_strcmp(sa->action, sb->action) != 0)) { PWARN ("actions differ: %s vs %s", sa->action, sb->action); return FALSE; diff --git a/src/engine/Transaction.c b/src/engine/Transaction.c index 5ca16efdbc..20717ec5d4 100644 --- a/src/engine/Transaction.c +++ b/src/engine/Transaction.c @@ -677,6 +677,8 @@ xaccTransEqual(const Transaction *ta, const Transaction *tb, gboolean check_balances, gboolean assume_ordered) { + gboolean same_book; + if (!ta && !tb) return TRUE; /* Arguable. FALSE may be better. */ if (!ta || !tb) @@ -687,6 +689,8 @@ xaccTransEqual(const Transaction *ta, const Transaction *tb, if (ta == tb) return TRUE; + same_book = qof_instance_get_book(QOF_INSTANCE(ta)) == qof_instance_get_book(QOF_INSTANCE(tb)); + if (check_guids) { if (qof_instance_guid_compare(ta, tb) != 0) @@ -706,26 +710,37 @@ xaccTransEqual(const Transaction *ta, const Transaction *tb, if (timespec_cmp(&(ta->date_entered), &(tb->date_entered))) { - PWARN ("date entered differs"); + char buf1[100]; + char buf2[100]; + + (void)gnc_timespec_to_iso8601_buff(ta->date_entered, buf1); + (void)gnc_timespec_to_iso8601_buff(tb->date_entered, buf2); + PWARN ("date entered differs: '%s' vs '%s'", buf1, buf2); return FALSE; } if (timespec_cmp(&(ta->date_posted), &(tb->date_posted))) { - PWARN ("date posted differs"); + char buf1[100]; + char buf2[100]; + + (void)gnc_timespec_to_iso8601_buff(ta->date_posted, buf1); + (void)gnc_timespec_to_iso8601_buff(tb->date_posted, buf2); + PWARN ("date posted differs: '%s' vs '%s'", buf1, buf2); return FALSE; } - /* Since we use cached strings, we can just compare pointer + /* If the same book, since we use cached strings, we can just compare pointer * equality for num and description */ - if (ta->num != tb->num) + if ((same_book && ta->num != tb->num) || (!same_book && safe_strcmp(ta->num, tb->num) != 0)) { PWARN ("num differs: %s vs %s", ta->num, tb->num); return FALSE; } - if (ta->description != tb->description) + if ((same_book && ta->description != tb->description) + || (!same_book && safe_strcmp(ta->description, tb->description))) { PWARN ("descriptions differ: %s vs %s", ta->description, tb->description); return FALSE; @@ -1338,7 +1353,7 @@ xaccTransCommitEdit (Transaction *trans) tv.tv_usec = 0; #endif trans->date_entered.tv_sec = tv.tv_sec; - trans->date_entered.tv_nsec = 1000 * tv.tv_usec; +// trans->date_entered.tv_nsec = 1000 * tv.tv_usec; qof_instance_set_dirty(QOF_INSTANCE(trans)); } diff --git a/src/engine/gnc-commodity.c b/src/engine/gnc-commodity.c index 377253ba88..043c6ed516 100644 --- a/src/engine/gnc-commodity.c +++ b/src/engine/gnc-commodity.c @@ -1454,6 +1454,7 @@ gnc_commodity_equal(const gnc_commodity * a, const gnc_commodity * b) { CommodityPrivate* priv_a; CommodityPrivate* priv_b; + gboolean same_book; if (a == b) return TRUE; @@ -1465,8 +1466,11 @@ gnc_commodity_equal(const gnc_commodity * a, const gnc_commodity * b) priv_a = GET_PRIVATE(a); priv_b = GET_PRIVATE(b); + same_book = qof_instance_get_book(QOF_INSTANCE(a)) == qof_instance_get_book(QOF_INSTANCE(b)); - if (priv_a->namespace != priv_b->namespace) + if ((same_book && priv_a->namespace != priv_b->namespace) + || (!same_book && safe_strcmp( gnc_commodity_namespace_get_name(priv_a->namespace), + gnc_commodity_namespace_get_name(priv_b->namespace)) != 0)) { DEBUG ("namespaces differ: %p(%s) vs %p(%s)", priv_a->namespace, gnc_commodity_namespace_get_name(priv_a->namespace),