r21986 - gnucash/trunk/src/engine - Introduce entry getters that return the balance value as opposed to
Geert Janssens
gjanssens at code.gnucash.org
Fri Feb 10 10:32:38 EST 2012
Author: gjanssens
Date: 2012-02-10 10:32:38 -0500 (Fri, 10 Feb 2012)
New Revision: 21986
Trac: http://svn.gnucash.org/trac/changeset/21986
Modified:
gnucash/trunk/src/engine/gncEntry.c
gnucash/trunk/src/engine/gncEntry.h
Log:
Introduce entry getters that return the balance value as opposed to
internal value and document value.
Modified: gnucash/trunk/src/engine/gncEntry.c
===================================================================
--- gnucash/trunk/src/engine/gncEntry.c 2012-02-10 15:32:27 UTC (rev 21985)
+++ gnucash/trunk/src/engine/gncEntry.c 2012-02-10 15:32:38 UTC (rev 21986)
@@ -1364,6 +1364,7 @@
return (is_cust_doc ? entry->i_tax_value : entry->b_tax_value);
}
+/* Careful: the returned list is managed by the entry, and will only be valid for a short time */
AccountValueList * gncEntryGetIntTaxValues (GncEntry *entry, gboolean is_cust_doc)
{
if (!entry) return NULL;
@@ -1393,12 +1394,22 @@
return (is_cn ? gnc_numeric_neg (value) : value);
}
+/* Careful: the returned list is NOT owned by the entry and should be freed by the caller */
AccountValueList * gncEntryGetDocTaxValues (GncEntry *entry, gboolean is_cust_doc, gboolean is_cn)
{
- AccountValueList *values = gncEntryGetIntTaxValues (entry, is_cust_doc);
- g_assert_not_reached ();
- /* FIXME How to invert the values in this case ? */
- return (is_cn ? values : values);
+ AccountValueList *int_values = gncEntryGetIntTaxValues (entry, is_cust_doc);
+ AccountValueList *values = NULL, *node;
+
+ /* Make a copy of the list with negated values if necessary. */
+ for (node = int_values; node; node = node->next)
+ {
+ GncAccountValue *acct_val = node->data;
+ values = gncAccountValueAdd (values, acct_val->account,
+ (is_cn ? gnc_numeric_neg (acct_val->value)
+ : acct_val->value));
+ }
+
+ return values;
}
gnc_numeric gncEntryGetDocDiscountValue (GncEntry *entry, gboolean round, gboolean is_cust_doc, gboolean is_cn)
@@ -1407,30 +1418,40 @@
return (is_cn ? gnc_numeric_neg (value) : value);
}
-gnc_numeric gncEntryGetBalValue (GncEntry *entry, gboolean round, gboolean is_cust_doc, gboolean is_cn)
+gnc_numeric gncEntryGetBalValue (GncEntry *entry, gboolean round, gboolean is_cust_doc)
{
gnc_numeric value = gncEntryGetIntValue (entry, round, is_cust_doc);
- return (is_cn ? gnc_numeric_neg (value) : value);
+ return (is_cust_doc ? gnc_numeric_neg (value) : value);
}
-gnc_numeric gncEntryGetBalTaxValue (GncEntry *entry, gboolean round, gboolean is_cust_doc, gboolean is_cn)
+gnc_numeric gncEntryGetBalTaxValue (GncEntry *entry, gboolean round, gboolean is_cust_doc)
{
gnc_numeric value = gncEntryGetIntTaxValue (entry, round, is_cust_doc);
- return (is_cn ? gnc_numeric_neg (value) : value);
+ return (is_cust_doc ? gnc_numeric_neg (value) : value);
}
-AccountValueList * gncEntryGetBalTaxValues (GncEntry *entry, gboolean is_cust_doc, gboolean is_cn)
+/* Careful: the returned list is NOT owned by the entry and should be freed by the caller */
+AccountValueList * gncEntryGetBalTaxValues (GncEntry *entry, gboolean is_cust_doc)
{
- AccountValueList *values = gncEntryGetIntTaxValues (entry, is_cust_doc);
- g_assert_not_reached ();
- /* FIXME How to invert the values in this case ? */
- return (is_cn ? values : values);
+ AccountValueList *int_values = gncEntryGetIntTaxValues (entry, is_cust_doc);
+ AccountValueList *values = NULL, *node;
+
+ /* Make a copy of the list with negated values if necessary. */
+ for (node = int_values; node; node = node->next)
+ {
+ GncAccountValue *acct_val = node->data;
+ values = gncAccountValueAdd (values, acct_val->account,
+ (is_cust_doc ? gnc_numeric_neg (acct_val->value)
+ : acct_val->value));
+ }
+
+ return values;
}
-gnc_numeric gncEntryGetBalDiscountValue (GncEntry *entry, gboolean round, gboolean is_cust_doc, gboolean is_cn)
+gnc_numeric gncEntryGetBalDiscountValue (GncEntry *entry, gboolean round, gboolean is_cust_doc)
{
gnc_numeric value = gncEntryGetIntDiscountValue (entry, round, is_cust_doc);
- return (is_cn ? gnc_numeric_neg (value) : value);
+ return (is_cust_doc ? gnc_numeric_neg (value) : value);
}
/* XXX this existence of this routine is just wrong */
Modified: gnucash/trunk/src/engine/gncEntry.h
===================================================================
--- gnucash/trunk/src/engine/gncEntry.h 2012-02-10 15:32:27 UTC (rev 21985)
+++ gnucash/trunk/src/engine/gncEntry.h 2012-02-10 15:32:38 UTC (rev 21986)
@@ -214,9 +214,14 @@
* tax values for this entry. This list holds unrounded values only, there's
* no variant with rounded values.
*
- * The list is owned by the entry and will be destroyed automatically,
- * so use it quickly.
+ * Note that this list may or may not be owned by the entry depending on the
+ * variant being called. If not owned by the entry, it should be freed with
+ * gncAccountValueDestroy.
*
+ * - gncEntryGetIntTaxValues returns a list owned by the entry.
+ * - gncEntryGetDocTaxValues returns a list NOT owned by the entry. It should be freed by the caller.
+ * - gncEntryGetBalTaxValues returns a list NOT owned by the entry. It should be freed by the caller.
+ *
* Finally, there are rounded and unrounded variants of most of
* these functions.
@{
@@ -224,18 +229,21 @@
typedef GList AccountValueList;
gnc_numeric gncEntryGetIntValue (GncEntry *entry, gboolean round, gboolean is_cust_doc);
gnc_numeric gncEntryGetIntTaxValue (GncEntry *entry, gboolean round, gboolean is_cust_doc);
+/** Careful: the returned list is managed by the entry, and will only be valid for a short time */
AccountValueList * gncEntryGetIntTaxValues (GncEntry *entry, gboolean is_cust_doc);
gnc_numeric gncEntryGetIntDiscountValue (GncEntry *entry, gboolean round, gboolean is_cust_doc);
gnc_numeric gncEntryGetDocValue (GncEntry *entry, gboolean round, gboolean is_cust_doc, gboolean is_cn);
gnc_numeric gncEntryGetDocTaxValue (GncEntry *entry, gboolean round, gboolean is_cust_doc, gboolean is_cn);
+/** Careful: the returned list is NOT owned by the entry and should be freed by the caller */
AccountValueList * gncEntryGetDocTaxValues (GncEntry *entry, gboolean is_cust_doc, gboolean is_cn);
gnc_numeric gncEntryGetDocDiscountValue (GncEntry *entry, gboolean round, gboolean is_cust_doc, gboolean is_cn);
-gnc_numeric gncEntryGetBalValue (GncEntry *entry, gboolean round, gboolean is_cust_doc, gboolean is_cn);
-gnc_numeric gncEntryGetBalTaxValue (GncEntry *entry, gboolean round, gboolean is_cust_doc, gboolean is_cn);
-AccountValueList * gncEntryGetBalTaxValues (GncEntry *entry, gboolean is_cust_doc, gboolean is_cn);
-gnc_numeric gncEntryGetBalDiscountValue (GncEntry *entry, gboolean round, gboolean is_cust_doc, gboolean is_cn);
+gnc_numeric gncEntryGetBalValue (GncEntry *entry, gboolean round, gboolean is_cust_doc);
+gnc_numeric gncEntryGetBalTaxValue (GncEntry *entry, gboolean round, gboolean is_cust_doc);
+/** Careful: the returned list is NOT owned by the entry and should be freed by the caller */
+AccountValueList * gncEntryGetBalTaxValues (GncEntry *entry, gboolean is_cust_doc);
+gnc_numeric gncEntryGetBalDiscountValue (GncEntry *entry, gboolean round, gboolean is_cust_doc);
/** Compute the Entry value, tax_value, and discount_value, based on
* the quantity, price, discount, tax_-table, and types. The value is
More information about the gnucash-changes
mailing list