Skip to content

Commit

Permalink
Merge branch 'private-kvp' into master again
Browse files Browse the repository at this point in the history
This was done by branching right before the original merge
and redoing a clean merge of the private-kvp branch again.

This result was then cherry-picked onto master with
git cherry-pick <merge-commit> -m 1

It was done like this because git merge would consider
the private-kvp branch already merged even after a revert
(see git-revert man page) and won't allow to merge a
second time on the same branch.

Resolved conflicts:
	README.dependencies
	src/app-utils/gnc-sx-instance-model.c
	src/engine/cap-gains.c
	src/engine/test/Makefile.am
	src/gnome/assistant-hierarchy.c
	src/import-export/import-match-map.c
	src/import-export/import-utilities.c
	src/import-export/ofx/gnc-ofx-kvp.c
	src/libqof/qof/qofbook.cpp
	src/libqof/qof/qofinstance-p.h
	src/libqof/qof/qofinstance.cpp
	src/libqof/qof/test/test-kvp_frame.c
	src/report/report-gnome/gnc-plugin-page-report.c
  • Loading branch information
gjanssens committed May 7, 2014
1 parent ae98012 commit 45cb550
Show file tree
Hide file tree
Showing 117 changed files with 4,090 additions and 2,294 deletions.
1 change: 0 additions & 1 deletion po/POTFILES.in
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,6 @@ src/import-export/import-backend.c
src/import-export/import-commodity-matcher.c
src/import-export/import-format-dialog.c
src/import-export/import-main-matcher.c
src/import-export/import-match-map.c
src/import-export/import-match-picker.c
src/import-export/import-parse.c
src/import-export/import-settings.c
Expand Down
2 changes: 1 addition & 1 deletion src/app-utils/business-helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ GncTaxTable* gnc_business_get_default_tax_table (QofBook *book, GncOwnerType own
GNCOptionDB *odb;

odb = gnc_option_db_new_for_type (GNC_ID_BOOK);
gnc_option_db_load_from_kvp (odb, qof_book_get_slots (book));
qof_book_load_options (book, gnc_option_db_load_from_kvp, odb);

switch (ownertype)
{
Expand Down
12 changes: 5 additions & 7 deletions src/app-utils/gnc-accounting-period.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,13 @@ get_fy_end(void)
{
QofBook *book;
KvpFrame *book_frame;
gint64 month, day;
GDate *date = NULL;

book = gnc_get_current_book();
book_frame = qof_book_get_slots(book);
month = kvp_frame_get_gint64(book_frame, "/book/fyear_end/month");
day = kvp_frame_get_gint64(book_frame, "/book/fyear_end/day");
if (g_date_valid_dmy(day, month, 2005 /* not leap year */))
return g_date_new_dmy(day, month, G_DATE_BAD_YEAR);
return NULL;
qof_instance_get (QOF_INSTANCE (book),
"fy-end", &date,
NULL);
return date;
}

time64
Expand Down
162 changes: 65 additions & 97 deletions src/app-utils/gnc-sx-instance-model.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,9 @@ _get_vars_helper(Transaction *txn, void *var_hash_data)
{
GHashTable *var_hash = (GHashTable*)var_hash_data;
GList *split_list;
kvp_frame *kvpf;
kvp_value *kvp_val;
Split *s;
char *str;
gchar *credit_formula = NULL;
gchar *debit_formula = NULL;
gnc_commodity *first_cmdty = NULL;

split_list = xaccTransGetSplitList(txn);
Expand All @@ -191,16 +190,16 @@ _get_vars_helper(Transaction *txn, void *var_hash_data)
for ( ; split_list; split_list = split_list->next)
{
gnc_commodity *split_cmdty = NULL;
GncGUID *acct_guid;
GncGUID *acct_guid = NULL;
Account *acct;

s = (Split*)split_list->data;
kvpf = xaccSplitGetSlots(s);
kvp_val = kvp_frame_get_slot_path(kvpf,
GNC_SX_ID,
GNC_SX_ACCOUNT,
NULL);
acct_guid = kvp_value_get_guid(kvp_val);

qof_instance_get (QOF_INSTANCE (s),
"sx-account", &acct_guid,
"sx-credit-formula", &credit_formula,
"sx-debit-formula", &debit_formula,
NULL);
acct = xaccAccountLookup(acct_guid, gnc_get_current_book());
split_cmdty = xaccAccountGetCommodity(acct);
if (first_cmdty == NULL)
Expand All @@ -226,31 +225,16 @@ _get_vars_helper(Transaction *txn, void *var_hash_data)
}

// existing... ------------------------------------------
kvp_val = kvp_frame_get_slot_path(kvpf,
GNC_SX_ID,
GNC_SX_CREDIT_FORMULA,
NULL);
if (kvp_val != NULL)
{
str = kvp_value_get_string(kvp_val);
if (str && strlen(str) != 0)
{
gnc_sx_parse_vars_from_formula(str, var_hash, NULL);
}
}

kvp_val = kvp_frame_get_slot_path(kvpf,
GNC_SX_ID,
GNC_SX_DEBIT_FORMULA,
NULL);
if (kvp_val != NULL)
{
str = kvp_value_get_string(kvp_val);
if (str && strlen(str) != 0)
{
gnc_sx_parse_vars_from_formula(str, var_hash, NULL);
}
}
if (credit_formula && strlen(credit_formula) != 0)
{
gnc_sx_parse_vars_from_formula(credit_formula, var_hash, NULL);
}
if (debit_formula && strlen(debit_formula) != 0)
{
gnc_sx_parse_vars_from_formula(debit_formula, var_hash, NULL);
}
g_free (credit_formula);
g_free (debit_formula);
}

return 0;
Expand Down Expand Up @@ -900,31 +884,15 @@ typedef struct _SxTxnCreationData
} SxTxnCreationData;

static gboolean
_get_template_split_account(const SchedXaction* sx, const Split *template_split, Account **split_acct, GList **creation_errors)
_get_template_split_account(const SchedXaction* sx,
const Split *template_split,
Account **split_acct,
GList **creation_errors)
{
GncGUID *acct_guid;
kvp_frame *split_kvpf;
kvp_value *kvp_val;

split_kvpf = xaccSplitGetSlots(template_split);
/* contains the guid of the split's actual account. */
kvp_val = kvp_frame_get_slot_path(split_kvpf,
GNC_SX_ID,
GNC_SX_ACCOUNT,
NULL);
if (kvp_val == NULL)
{
GString *err = g_string_new("");
g_string_printf(err, "Null account kvp value for SX [%s], cancelling creation.",
xaccSchedXactionGetName(sx));
g_critical("%s", err->str);
if (creation_errors != NULL)
*creation_errors = g_list_append(*creation_errors, err);
else
g_string_free(err, TRUE);
return FALSE;
}
acct_guid = kvp_value_get_guid( kvp_val );
GncGUID *acct_guid = NULL;
qof_instance_get (QOF_INSTANCE (template_split),
"sx-account", &acct_guid,
NULL);
*split_acct = xaccAccountLookup(acct_guid, gnc_get_current_book());
if (*split_acct == NULL)
{
Expand All @@ -946,34 +914,34 @@ _get_template_split_account(const SchedXaction* sx, const Split *template_split,
}

static void
_get_sx_formula_value(const SchedXaction* sx, const Split *template_split, gnc_numeric *numeric, GList **creation_errors, const char *formula_key, const char* numeric_key, GHashTable *variable_bindings)
_get_sx_formula_value(const SchedXaction* sx,
const Split *template_split,
gnc_numeric *numeric,
GList **creation_errors,
const char *formula_key,
const char* numeric_key,
GHashTable *variable_bindings)
{
kvp_frame *split_kvpf;
kvp_value *kvp_val;
char *formula_str, *parseErrorLoc;

split_kvpf = xaccSplitGetSlots(template_split);

/* First look up the gnc_numeric value in the template split */
kvp_val = kvp_frame_get_slot_path(split_kvpf,
GNC_SX_ID,
numeric_key,
NULL);
*numeric = kvp_value_get_numeric(kvp_val);
if ((gnc_numeric_check(*numeric) == GNC_ERROR_OK)
&& !gnc_numeric_zero_p(*numeric))

char *formula_str = NULL, *parseErrorLoc = NULL;
gnc_numeric *numeric_val = NULL;
qof_instance_get (QOF_INSTANCE (template_split),
formula_key, &formula_str,
numeric_key, &numeric_val,
NULL);

if (numeric_val != NULL &&
gnc_numeric_check(*numeric_val) == GNC_ERROR_OK &&
!gnc_numeric_zero_p(*numeric_val))
{
/* Already a valid non-zero result? Then return and don't
* parse the string. Luckily we avoid any locale problems with
* decimal points here! Phew. */
numeric->num = numeric_val->num;
numeric->denom = numeric_val->denom;
return;
}

kvp_val = kvp_frame_get_slot_path(split_kvpf,
GNC_SX_ID,
formula_key,
NULL);
formula_str = kvp_value_get_string(kvp_val);
if (formula_str != NULL && strlen(formula_str) != 0)
{
GHashTable *parser_vars = NULL;
Expand Down Expand Up @@ -1010,13 +978,17 @@ _get_sx_formula_value(const SchedXaction* sx, const Split *template_split, gnc_n
static void
_get_credit_formula_value(GncSxInstance *instance, const Split *template_split, gnc_numeric *credit_num, GList **creation_errors)
{
_get_sx_formula_value(instance->parent->sx, template_split, credit_num, creation_errors, GNC_SX_CREDIT_FORMULA, GNC_SX_CREDIT_NUMERIC, instance->variable_bindings);
_get_sx_formula_value(instance->parent->sx, template_split, credit_num,
creation_errors, "sx-credit-formula",
"sx-credit-numeric", instance->variable_bindings);
}

static void
_get_debit_formula_value(GncSxInstance *instance, const Split *template_split, gnc_numeric *debit_num, GList **creation_errors)
{
_get_sx_formula_value(instance->parent->sx, template_split, debit_num, creation_errors, GNC_SX_DEBIT_FORMULA, GNC_SX_DEBIT_NUMERIC, instance->variable_bindings);
_get_sx_formula_value(instance->parent->sx, template_split, debit_num,
creation_errors, "sx-debit-formula",
"sx-debit-numeric", instance->variable_bindings);
}

static gboolean
Expand All @@ -1035,7 +1007,7 @@ create_each_transaction_helper(Transaction *template_txn, void *user_data)
as not finding the approrpiate Accounts and not being able to
parse the formula|credit/debit strings. */

new_txn = xaccTransClone(template_txn);
new_txn = xaccTransCloneNoKvp(template_txn);
xaccTransBeginEdit(new_txn);

g_debug("creating template txn desc [%s] for sx [%s]",
Expand All @@ -1044,9 +1016,6 @@ create_each_transaction_helper(Transaction *template_txn, void *user_data)

g_debug("template txn currency is %s", gnc_commodity_get_mnemonic(xaccTransGetCurrency (template_txn)));

/* clear any copied KVP data */
qof_instance_set_slots(QOF_INSTANCE(new_txn), kvp_frame_new());

/* Bug#500427: copy the notes, if any */
if (xaccTransGetNotes(template_txn) != NULL)
{
Expand Down Expand Up @@ -1090,9 +1059,6 @@ create_each_transaction_helper(Transaction *template_txn, void *user_data)
break;
}

/* clear out any copied Split frame data. */
qof_instance_set_slots(QOF_INSTANCE(copying_split), kvp_frame_new());

split_cmdty = xaccAccountGetCommodity(split_acct);
if (first_cmdty == NULL)
{
Expand Down Expand Up @@ -1215,13 +1181,10 @@ create_each_transaction_helper(Transaction *template_txn, void *user_data)
}

{
kvp_frame *txn_frame;
txn_frame = xaccTransGetSlots(new_txn);
kvp_frame_set_guid(txn_frame, "from-sched-xaction",
xaccSchedXactionGetGUID(creation_data->instance->parent->sx));
/* The transaction was probably marked dirty by xaccTransSetCurrency,
* but just in case: */
qof_instance_set_dirty (QOF_INSTANCE (new_txn));
qof_instance_set (QOF_INSTANCE (new_txn),
"from-sched-xaction",
xaccSchedXactionGetGUID(creation_data->instance->parent->sx),
NULL);
}

xaccTransCommitEdit(new_txn);
Expand Down Expand Up @@ -1631,9 +1594,14 @@ create_cashflow_helper(Transaction *template_txn, void *user_data)
gint gncn_error;

/* Credit value */
_get_sx_formula_value(creation_data->sx, template_split, &credit_num, creation_data->creation_errors, GNC_SX_CREDIT_FORMULA, GNC_SX_CREDIT_NUMERIC, NULL);
_get_sx_formula_value(creation_data->sx, template_split,
&credit_num, creation_data->creation_errors,
"sx-credit-formula", "sx-credit-numeric",
NULL);
/* Debit value */
_get_sx_formula_value(creation_data->sx, template_split, &debit_num, creation_data->creation_errors, GNC_SX_DEBIT_FORMULA, GNC_SX_DEBIT_NUMERIC, NULL);
_get_sx_formula_value(creation_data->sx, template_split,
&debit_num, creation_data->creation_errors,
"sx-debit-formula", "sx-debit-numeric", NULL);

/* The resulting cash flow number: debit minus credit,
* multiplied with the count factor. */
Expand Down
2 changes: 1 addition & 1 deletion src/app-utils/option-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

typedef struct gnc_option GNCOption;
typedef struct gnc_option_section GNCOptionSection;
typedef struct gnc_option_db GNCOptionDB;
/* typedef struct gnc_option_db GNCOptionDB is in qof-book.h */

typedef int GNCOptionDBHandle;

Expand Down
16 changes: 16 additions & 0 deletions src/app-utils/test/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include $(top_srcdir)/test-templates/Makefile.decl

TESTS = \
test-link-module \
test-load-module \
Expand Down Expand Up @@ -66,3 +68,17 @@ AM_CPPFLAGS = \
-I${top_srcdir}/src/libqof/qof \
${GUILE_CFLAGS} \
${GLIB_CFLAGS}

TEST_PROGS += test-app-utils

noinst_PROGRAMS = ${TEST_PROGS} ${CHECK_PROGS}

test_app_utils_SOURCES = \
test-app-utils.c \
test-option-util.c

test_app_utils_CFLAGS = \
${DEFAULT_INCLUDES} \
-I${top_srcdir}/${MODULEPATH}/ \
-DTESTPROG=test_app_utils \
${GLIB_CFLAGS}
56 changes: 56 additions & 0 deletions src/app-utils/test/test-app-utils.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/********************************************************************
* test-app-utils.c: GLib g_test test execution file. *
* Copyright 2013 John Ralls <[email protected]> *
* *
* 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 [email protected] *
\********************************************************************/

#include <config.h>
#include <glib.h>
#include <qof.h>
#include <libguile.h>
#include <gnc-module.h>

extern void test_suite_option_util (void);

static void
guile_main (void *closure, int argc, char **argv)
{
GNCModule mod;
int retval;
gnc_module_system_init ();
mod = gnc_module_load ("gnucash/app-utils", 0);

test_suite_option_util ();
retval = g_test_run ();

exit (retval);
}

int
main (int argc, char *argv[])
{
qof_init (); /* Initialize the GObject system */
qof_log_init_filename_special ("stderr"); /* Init the log system */
g_test_init (&argc, &argv, NULL); /* initialize test program */
//qof_log_set_level("gnc", G_LOG_LEVEL_DEBUG);
g_test_bug_base("https://bugzilla.gnome.org/show_bug.cgi?id="); /* init the bugzilla URL */
g_setenv ("GNC_UNINSTALLED", "1", TRUE);
scm_boot_guile (argc, argv, guile_main, NULL);

}
Loading

0 comments on commit 45cb550

Please sign in to comment.