mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Remove the incomplete book-currency code.
Not everything from the 6 Book-Currency commits is removed: Switching the Num and split-action fields and restricting edits of transactions older than n days were included and those changes are left in place. Some other partly-implemented features were also part of these commits and were removed: Options for setting a default capital gains account and currency, completion of the LIFO cap-gains policy, and creation of a list of cap-gains policies. If any of these are to be revived they should each be done in a separate feature branch and submitted via Github pull request for a code review before merging; a design discussion on gnucash-devel before restarting work is also advisable.
This commit is contained in:
parent
aa246d3096
commit
81c5ac6689
@ -396,10 +396,6 @@ void qof_book_set_string_option(QofBook* book, const char* opt_name, const char*
|
||||
|
||||
SET_ENUM("OPTION-SECTION-ACCOUNTS");
|
||||
SET_ENUM("OPTION-NAME-TRADING-ACCOUNTS");
|
||||
SET_ENUM("OPTION-NAME-CURRENCY-ACCOUNTING");
|
||||
SET_ENUM("OPTION-NAME-BOOK-CURRENCY");
|
||||
SET_ENUM("OPTION-NAME-DEFAULT-GAINS-POLICY");
|
||||
SET_ENUM("OPTION-NAME-DEFAULT-GAINS-LOSS-ACCT-GUID");
|
||||
SET_ENUM("OPTION-NAME-AUTO-READONLY-DAYS");
|
||||
SET_ENUM("OPTION-NAME-NUM-FIELD-SOURCE");
|
||||
|
||||
|
@ -66,7 +66,6 @@
|
||||
static QofLogModule log_module = GNC_MOD_GUI;
|
||||
|
||||
#define DIALOG_OPTIONS_CM_CLASS "dialog-options"
|
||||
#define DIALOG_BOOK_OPTIONS_CM_CLASS "dialog-book-options"
|
||||
|
||||
#define GNC_PREFS_GROUP "dialogs.options"
|
||||
|
||||
@ -82,8 +81,6 @@ static QofLogModule log_module = GNC_MOD_GUI;
|
||||
/* A Hash-table of GNCOptionDef_t keyed with option names. */
|
||||
static GHashTable *optionTable = NULL;
|
||||
|
||||
static int gain_loss_accounts_in_filter = 0;
|
||||
|
||||
struct gnc_option_win
|
||||
{
|
||||
GtkWidget * window;
|
||||
@ -127,43 +124,12 @@ enum page_tree
|
||||
NUM_COLUMNS
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GtkWidget *gnc_currency_radiobutton_0;
|
||||
GtkWidget *gnc_currency_radiobutton_1;
|
||||
GtkWidget *gnc_currency_radiobutton_2;
|
||||
GtkWidget *book_currency_widget;
|
||||
GtkWidget *default_cost_policy_widget;
|
||||
GtkWidget *default_gain_loss_account_widget;
|
||||
GtkWidget *book_currency_table;
|
||||
GtkWidget *book_currency_vbox;
|
||||
GtkWidget *gain_loss_account_del_button;
|
||||
GtkWidget *gain_loss_account_table;
|
||||
GtkWidget *default_gain_loss_account_text;
|
||||
GNCOption *option;
|
||||
Account *prior_gain_loss_account;
|
||||
gnc_commodity *retrieved_book_currency;
|
||||
|
||||
SCM retrieved_policy_scm;
|
||||
SCM retrieved_gain_loss_acct_guid_scm;
|
||||
|
||||
} currency_accounting_data;
|
||||
|
||||
static currency_accounting_data *book_currency_data = NULL;
|
||||
|
||||
static GNCOptionWinCallback global_help_cb = NULL;
|
||||
gpointer global_help_cb_data = NULL;
|
||||
|
||||
static void gnc_options_dialog_reset_cb (GtkWidget * w, gpointer data);
|
||||
void gnc_options_dialog_list_select_cb (GtkTreeSelection *selection,
|
||||
gpointer data);
|
||||
void gnc_set_default_cost_policy_widget (SCM list_symbol);
|
||||
void gnc_set_default_gain_loss_account_widget (gnc_commodity *commodity);
|
||||
void gnc_option_changed_book_currency_widget_cb (GtkWidget *widget);
|
||||
void gnc_option_changed_gain_loss_account_widget_cb (GtkTreeSelection *selection,
|
||||
gpointer data);
|
||||
void gnc_option_changed_gain_loss_account_del_button_widget_cb (GtkButton *button,
|
||||
gpointer data);
|
||||
static void component_close_handler (gpointer data);
|
||||
|
||||
GtkWidget *
|
||||
@ -520,6 +486,7 @@ gnc_option_radiobutton_cb (GtkWidget *w, gpointer data)
|
||||
gnc_option_changed_widget_cb (widget, option);
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
static gboolean
|
||||
gnc_gain_loss_account_view_filter (Account *account, gpointer data)
|
||||
{
|
||||
@ -975,6 +942,8 @@ gnc_option_currency_accounting_book_cb (GtkWidget *widget, gpointer data)
|
||||
gtk_widget_set_sensitive (book_currency_data->book_currency_vbox, TRUE);
|
||||
gnc_option_radiobutton_cb (widget, (gpointer) book_currency_data->option);
|
||||
}
|
||||
=======
|
||||
>>>>>>> f87d57145 (Remove the incomplete book-currency code.)
|
||||
|
||||
static GtkWidget *
|
||||
gnc_option_create_date_widget (GNCOption *option)
|
||||
@ -1186,6 +1155,7 @@ gnc_option_create_radiobutton_widget (char *name, GNCOption *option)
|
||||
return frame;
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
static GtkWidget *
|
||||
gnc_option_create_currency_accounting_widget (char *name, GNCOption *option)
|
||||
{
|
||||
@ -1358,6 +1328,8 @@ gnc_option_create_currency_accounting_widget (char *name, GNCOption *option)
|
||||
return frame;
|
||||
}
|
||||
|
||||
=======
|
||||
>>>>>>> f87d57145 (Remove the incomplete book-currency code.)
|
||||
static void
|
||||
gnc_option_account_cb (GtkTreeSelection *selection, gpointer data)
|
||||
{
|
||||
@ -2161,27 +2133,6 @@ component_close_handler (gpointer data)
|
||||
gnc_options_dialog_cancel_button_cb (NULL, win);
|
||||
}
|
||||
|
||||
static void
|
||||
refresh_handler (GHashTable *changes, gpointer user_data)
|
||||
{
|
||||
gnc_commodity *commodity = NULL;
|
||||
GtkTreeIter iter;
|
||||
|
||||
/* The default_gain_loss_account_widget needs to be refreshed if any
|
||||
changes have been made via account maintenance, if it exists and
|
||||
if the book currency widget has a selection */
|
||||
/* if (book_currency_data->default_gain_loss_account_widget &&
|
||||
gtk_combo_box_get_active_iter(
|
||||
GTK_COMBO_BOX(book_currency_data->book_currency_widget), &iter))
|
||||
{
|
||||
commodity = gnc_currency_edit_get_currency(
|
||||
GNC_CURRENCY_EDIT(
|
||||
book_currency_data->book_currency_widget));
|
||||
gnc_set_default_gain_loss_account_widget(commodity);
|
||||
gtk_widget_show_all(book_currency_data->book_currency_vbox);
|
||||
} */
|
||||
}
|
||||
|
||||
/* gnc_options_dialog_new:
|
||||
*
|
||||
* - Opens the dialog-options glade file
|
||||
@ -2294,21 +2245,11 @@ gnc_options_dialog_new_modal (gboolean modal, gchar *title,
|
||||
gtk_widget_show (retval->notebook);
|
||||
gtk_box_pack_start (GTK_BOX(hbox), retval->notebook, TRUE, TRUE, 5);
|
||||
|
||||
retval->component_class =
|
||||
(component_class ? component_class : DIALOG_OPTIONS_CM_CLASS);
|
||||
component_id = gnc_register_gui_component (retval->component_class,
|
||||
refresh_handler, component_close_handler,
|
||||
retval);
|
||||
NULL, component_close_handler,
|
||||
retval);
|
||||
gnc_gui_component_set_session (component_id, gnc_get_current_session());
|
||||
|
||||
/* Watch account maintenance events only if book option dialog */
|
||||
if (g_strcmp0 (retval->component_class, DIALOG_BOOK_OPTIONS_CM_CLASS) == 0)
|
||||
{
|
||||
gnc_gui_component_watch_entity_type (component_id,
|
||||
GNC_ID_ACCOUNT,
|
||||
QOF_EVENT_MODIFY | QOF_EVENT_DESTROY);
|
||||
}
|
||||
|
||||
g_signal_connect (retval->window, "destroy",
|
||||
G_CALLBACK(gnc_options_dialog_destroy_cb), retval);
|
||||
|
||||
@ -3106,28 +3047,6 @@ gnc_option_set_ui_widget_budget (GNCOption *option, GtkGrid *page_box,
|
||||
return value;
|
||||
}
|
||||
|
||||
static GtkWidget *
|
||||
gnc_option_set_ui_widget_currency_accounting (GNCOption *option,
|
||||
GtkGrid *page_box,
|
||||
GtkLabel *name_label, char *documentation,
|
||||
/* Return values */
|
||||
GtkWidget **enclosing,
|
||||
gboolean *packed)
|
||||
{
|
||||
GtkWidget *value;
|
||||
|
||||
*enclosing = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
|
||||
gtk_box_set_homogeneous (GTK_BOX(*enclosing), FALSE);
|
||||
|
||||
value = gnc_option_create_currency_accounting_widget (NULL, option);
|
||||
gnc_option_set_widget (option, value);
|
||||
|
||||
gnc_option_set_ui_value (option, FALSE);
|
||||
gtk_box_pack_start (GTK_BOX(*enclosing), value, TRUE, TRUE, 0);
|
||||
gtk_widget_show_all (*enclosing);
|
||||
return value;
|
||||
}
|
||||
|
||||
/*************************
|
||||
* SET VALUE *
|
||||
*************************
|
||||
@ -3617,113 +3536,6 @@ gnc_option_set_ui_value_plot_size (GNCOption *option, gboolean use_default,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gnc_option_set_ui_value_currency_accounting (GNCOption *option,
|
||||
gboolean use_default,
|
||||
GtkWidget *widget, SCM value)
|
||||
{
|
||||
if (scm_is_pair (value))
|
||||
{
|
||||
SCM rb_symbol;
|
||||
|
||||
rb_symbol = gnc_currency_accounting_option_value_get_method (value);
|
||||
|
||||
if (rb_symbol)
|
||||
{
|
||||
int index;
|
||||
|
||||
index = gnc_option_permissible_value_index (option, rb_symbol);
|
||||
if (index < 0)
|
||||
return TRUE;
|
||||
else
|
||||
{
|
||||
GtkWidget *button = NULL;
|
||||
gpointer val;
|
||||
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
button = book_currency_data->gnc_currency_radiobutton_0;
|
||||
break;
|
||||
case 1:
|
||||
button = book_currency_data->gnc_currency_radiobutton_1;
|
||||
break;
|
||||
case 2:
|
||||
button = book_currency_data->gnc_currency_radiobutton_2;
|
||||
break;
|
||||
default:
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
val = g_object_get_data (G_OBJECT(button),
|
||||
"gnc_radiobutton_index");
|
||||
g_return_val_if_fail (GPOINTER_TO_INT(val) == index, TRUE);
|
||||
|
||||
if (g_strcmp0 (gnc_option_permissible_value_name (option,
|
||||
index),
|
||||
"Use a Book Currency") == 0)
|
||||
{
|
||||
gnc_commodity *commodity = NULL;
|
||||
SCM curr_scm =
|
||||
gnc_currency_accounting_option_value_get_book_currency
|
||||
(value);
|
||||
SCM list_symbol =
|
||||
gnc_currency_accounting_option_value_get_default_policy
|
||||
(value);
|
||||
SCM acct_guid_scm =
|
||||
gnc_currency_accounting_option_value_get_default_account
|
||||
(value);
|
||||
|
||||
commodity = gnc_scm_to_commodity (curr_scm);
|
||||
if (commodity)
|
||||
{
|
||||
book_currency_data->retrieved_book_currency = commodity;
|
||||
}
|
||||
else
|
||||
{
|
||||
book_currency_data->retrieved_book_currency = NULL;
|
||||
}
|
||||
if (list_symbol)
|
||||
{
|
||||
book_currency_data->retrieved_policy_scm = list_symbol;
|
||||
}
|
||||
else
|
||||
{
|
||||
book_currency_data->retrieved_policy_scm = NULL;
|
||||
}
|
||||
if (acct_guid_scm)
|
||||
{
|
||||
book_currency_data->retrieved_gain_loss_acct_guid_scm =
|
||||
acct_guid_scm;
|
||||
}
|
||||
else
|
||||
{
|
||||
book_currency_data->retrieved_gain_loss_acct_guid_scm =
|
||||
NULL;
|
||||
}
|
||||
}
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(button), TRUE);
|
||||
/* when an unselected button in a group is clicked the clicked
|
||||
button receives the “toggled” signal, as does the
|
||||
previously selected button; however, if the first button
|
||||
is active when the currency-accounting dialog is created,
|
||||
that is, it's read from the option, the "toggled" handler
|
||||
is not called while it is if any other button is active.
|
||||
To get desired result, that is, to set sensitivity to
|
||||
FALSE, explicitly call the handler here if first button */
|
||||
if (index == 0)
|
||||
{
|
||||
gnc_option_currency_accounting_non_book_cb (button,
|
||||
(gpointer) book_currency_data);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*************************
|
||||
* GET VALUE *
|
||||
*************************
|
||||
@ -4045,6 +3857,7 @@ gnc_option_get_ui_value_plot_size (GNCOption *option, GtkWidget *widget)
|
||||
return scm_cons (type, val);
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
static SCM
|
||||
gnc_option_get_ui_value_currency_accounting (GNCOption *option,
|
||||
GtkWidget *widget)
|
||||
@ -4148,6 +3961,8 @@ gnc_option_get_ui_value_currency_accounting (GNCOption *option,
|
||||
return (scm_cons (gnc_option_permissible_value (option, index), value));
|
||||
}
|
||||
|
||||
=======
|
||||
>>>>>>> f87d57145 (Remove the incomplete book-currency code.)
|
||||
/************************************/
|
||||
/* INITIALIZATION */
|
||||
/************************************/
|
||||
@ -4228,12 +4043,6 @@ static void gnc_options_initialize_options (void)
|
||||
"budget", gnc_option_set_ui_widget_budget,
|
||||
gnc_option_set_ui_value_budget, gnc_option_get_ui_value_budget
|
||||
},
|
||||
{
|
||||
"currency-accounting",
|
||||
gnc_option_set_ui_widget_currency_accounting,
|
||||
gnc_option_set_ui_value_currency_accounting,
|
||||
gnc_option_get_ui_value_currency_accounting
|
||||
},
|
||||
{ NULL, NULL, NULL, NULL }
|
||||
};
|
||||
int i;
|
||||
|
@ -820,51 +820,6 @@ gnc_new_book_option_display (GtkWidget *parent)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* This function returns a widget for selecting a cost policy
|
||||
*/
|
||||
GtkWidget *
|
||||
gnc_cost_policy_select_new (void)
|
||||
{
|
||||
GtkWidget *cost_policy_widget = NULL;
|
||||
GList *list_of_policies = NULL;
|
||||
|
||||
list_of_policies = gnc_get_valid_policy_list();
|
||||
|
||||
g_return_val_if_fail(g_list_length (list_of_policies) >= 0, NULL);
|
||||
if (list_of_policies)
|
||||
{
|
||||
GtkListStore *store = gtk_list_store_new (1, G_TYPE_STRING);
|
||||
GtkTreeIter iter;
|
||||
GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
|
||||
const char *description;
|
||||
GList *l = NULL;
|
||||
|
||||
/* Add values to the list store, entry and tooltip */
|
||||
for (l = list_of_policies; l != NULL; l = l->next)
|
||||
{
|
||||
GNCPolicy *pcy = l->data;
|
||||
description = PolicyGetDescription (pcy);
|
||||
|
||||
gtk_list_store_append (store, &iter);
|
||||
gtk_list_store_set (store, &iter,
|
||||
0, (description && *description) ? _(description) : "",
|
||||
-1);
|
||||
}
|
||||
g_list_free (list_of_policies);
|
||||
/* Create the new Combo with the store */
|
||||
cost_policy_widget = gtk_combo_box_new_with_model (GTK_TREE_MODEL(store));
|
||||
|
||||
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT(cost_policy_widget), renderer, TRUE);
|
||||
gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT(cost_policy_widget),
|
||||
renderer, "text", 0);
|
||||
g_object_unref (store);
|
||||
}
|
||||
return cost_policy_widget;
|
||||
}
|
||||
|
||||
/* This function returns a string for the CSS 'gnc-class-negative-numbers' class,
|
||||
* the returned string must be freed
|
||||
*/
|
||||
gchar*
|
||||
gnc_get_negative_color (void)
|
||||
{
|
||||
|
@ -4169,12 +4169,9 @@ gnc_book_options_dialog_apply_helper(GNCOptionDB * options)
|
||||
QofBook *book = gnc_get_current_book ();
|
||||
gboolean use_split_action_for_num_before =
|
||||
qof_book_use_split_action_for_num_field (book);
|
||||
gboolean use_book_currency_before =
|
||||
gnc_book_use_book_currency (book);
|
||||
gint use_read_only_threshold_before =
|
||||
qof_book_get_num_days_autoreadonly (book);
|
||||
gboolean use_split_action_for_num_after;
|
||||
gboolean use_book_currency_after;
|
||||
gint use_read_only_threshold_after;
|
||||
gboolean return_val = FALSE;
|
||||
GList *results = NULL, *iter;
|
||||
@ -4199,7 +4196,6 @@ gnc_book_options_dialog_apply_helper(GNCOptionDB * options)
|
||||
qof_book_save_options (book, gnc_option_db_save, options, TRUE);
|
||||
use_split_action_for_num_after =
|
||||
qof_book_use_split_action_for_num_field (book);
|
||||
use_book_currency_after = gnc_book_use_book_currency (book);
|
||||
|
||||
// mark cached value as invalid so we get new value
|
||||
book->cached_num_days_autoreadonly_isvalid = FALSE;
|
||||
@ -4211,11 +4207,6 @@ gnc_book_options_dialog_apply_helper(GNCOptionDB * options)
|
||||
use_split_action_for_num_after);
|
||||
return_val = TRUE;
|
||||
}
|
||||
if (use_book_currency_before != use_book_currency_after)
|
||||
{
|
||||
gnc_book_option_book_currency_selected_cb (use_book_currency_after);
|
||||
return_val = TRUE;
|
||||
}
|
||||
if (use_read_only_threshold_before != use_read_only_threshold_after)
|
||||
return_val = TRUE;
|
||||
|
||||
@ -4264,25 +4255,6 @@ gnc_book_option_num_field_source_change_cb (gboolean num_action)
|
||||
gnc_resume_gui_refresh ();
|
||||
}
|
||||
|
||||
/** Calls gnc_book_option_book_currency_selected to initiate registered
|
||||
* callbacks when currency accounting book option changes to book-currency so
|
||||
* that registers/reports can update themselves; sets feature flag */
|
||||
void
|
||||
gnc_book_option_book_currency_selected_cb (gboolean use_book_currency)
|
||||
{
|
||||
gnc_suspend_gui_refresh ();
|
||||
if (use_book_currency)
|
||||
{
|
||||
/* Set a feature flag in the book for use of book currency. This will
|
||||
* prevent older GnuCash versions that don't support this feature from
|
||||
* opening this file. */
|
||||
gnc_features_set_used (gnc_get_current_book(),
|
||||
GNC_FEATURE_BOOK_CURRENCY);
|
||||
}
|
||||
gnc_book_option_book_currency_selected (use_book_currency);
|
||||
gnc_resume_gui_refresh ();
|
||||
}
|
||||
|
||||
static gboolean
|
||||
show_handler (const char *class_name, gint component_id,
|
||||
gpointer user_data, gpointer iter_data)
|
||||
|
@ -1473,24 +1473,11 @@ on_select_currency_prepare (hierarchy_data *data)
|
||||
{
|
||||
gnc_book_options_dialog_apply_helper(data->options);
|
||||
|
||||
if (gnc_book_use_book_currency (gnc_get_current_book ()))
|
||||
{
|
||||
gnc_currency_edit_set_currency (GNC_CURRENCY_EDIT(data->currency_selector),
|
||||
gnc_book_get_book_currency (gnc_get_current_book ()));
|
||||
gtk_label_set_text (GTK_LABEL(data->currency_selector_label),
|
||||
( _("You selected a book currency and it will be used for\n" \
|
||||
"new accounts. Accounts in other currencies must be\n" \
|
||||
"added manually.") ));
|
||||
gtk_widget_set_sensitive(data->currency_selector, FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
gnc_currency_edit_set_currency (GNC_CURRENCY_EDIT(data->currency_selector),
|
||||
gnc_default_currency());
|
||||
gtk_label_set_text (GTK_LABEL(data->currency_selector_label),
|
||||
( _("Please choose the currency to use for new accounts.") ));
|
||||
gtk_widget_set_sensitive(data->currency_selector, TRUE);
|
||||
}
|
||||
gnc_currency_edit_set_currency (GNC_CURRENCY_EDIT(data->currency_selector),
|
||||
gnc_default_currency());
|
||||
gtk_label_set_text (GTK_LABEL(data->currency_selector_label),
|
||||
( _("Please choose the currency to use for new accounts.") ));
|
||||
gtk_widget_set_sensitive(data->currency_selector, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,46 @@
|
||||
(gnucash app-utils options)
|
||||
(gnucash app-utils c-interface))
|
||||
|
||||
(export gnc:make-internal-option)
|
||||
(export gnc:make-query-option)
|
||||
(export gnc:make-color-option)
|
||||
(export gnc:make-dateformat-option)
|
||||
(export gnc:dateformat-get-format)
|
||||
|
||||
(export gnc:color->html)
|
||||
(export gnc:color-option->html)
|
||||
(export gnc:color-option->hex-string)
|
||||
(export gnc:new-options)
|
||||
|
||||
(export gnc:register-option)
|
||||
(export gnc:unregister-option)
|
||||
(export gnc:options-register-callback)
|
||||
(export gnc:options-register-c-callback)
|
||||
(export gnc:options-unregister-callback-id)
|
||||
(export gnc:options-for-each)
|
||||
(export gnc:options-for-each-general)
|
||||
(export gnc:lookup-option)
|
||||
(export gnc:generate-restore-forms)
|
||||
(export gnc:options-fancy-date)
|
||||
(export gnc:options-scm->kvp)
|
||||
(export gnc:options-kvp->scm)
|
||||
(export gnc:options-clear-changes)
|
||||
(export gnc:options-touch)
|
||||
(export gnc:options-run-callbacks)
|
||||
(export gnc:options-set-default-section)
|
||||
(export gnc:options-get-default-section)
|
||||
(export gnc:options-copy-values)
|
||||
(export gnc:send-options)
|
||||
|
||||
(define (gnc:option-get-value book category key)
|
||||
;;Access an option directly
|
||||
(qof-book-get-option book
|
||||
(if (list? key)
|
||||
(append (list category) key)
|
||||
(list category key))))
|
||||
(export gnc:option-get-value)
|
||||
|
||||
;; gw-engine-spec.scm
|
||||
(re-export HOOK-SAVE-OPTIONS)
|
||||
|
||||
(export gnc:get-debit-string)
|
||||
|
@ -438,122 +438,6 @@ gnc_get_current_book_tax_type (void)
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns TRUE if both book-currency and default gain/loss policy KVPs exist
|
||||
* and are valid and trading accounts are not used. */
|
||||
gboolean
|
||||
gnc_book_use_book_currency (QofBook *book)
|
||||
{
|
||||
const gchar *policy;
|
||||
const gchar *currency;
|
||||
|
||||
if (!book) return FALSE;
|
||||
|
||||
policy = qof_book_get_default_gains_policy (book);
|
||||
currency = qof_book_get_book_currency_name (book);
|
||||
|
||||
/* If either a default gain/loss policy or a book-currency does not exist,
|
||||
book-currency accounting method not valid */
|
||||
if (!policy || !currency)
|
||||
return FALSE;
|
||||
|
||||
/* If both exist, both must be valid */
|
||||
if (!gnc_valid_policy_name (policy) || !gnc_commodity_table_lookup
|
||||
(gnc_commodity_table_get_table
|
||||
(gnc_get_current_book()),
|
||||
GNC_COMMODITY_NS_CURRENCY,
|
||||
currency))
|
||||
return FALSE;
|
||||
|
||||
/* If both exist and are valid, there must be no trading accounts flag */
|
||||
if (qof_book_use_trading_accounts (book))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/** Returns pointer to Book Currency name for book or NULL; determines
|
||||
* that both book-currency and default gain/loss policy KVPs exist and that
|
||||
* both are valid, a requirement for the 'book-currency' currency accounting
|
||||
* method to apply. */
|
||||
const gchar *
|
||||
gnc_book_get_book_currency_name (QofBook *book)
|
||||
{
|
||||
if (!book) return NULL;
|
||||
|
||||
if (gnc_book_use_book_currency (book))
|
||||
return qof_book_get_book_currency_name (book);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/** Returns pointer to Book Currency for book or NULL; determines
|
||||
* that both book-currency and default gain/loss policy KVPs exist and that
|
||||
* both are valid, a requirement for the 'book-currency' currency accounting
|
||||
* method to apply. */
|
||||
gnc_commodity *
|
||||
gnc_book_get_book_currency (QofBook *book)
|
||||
{
|
||||
if (!book) return NULL;
|
||||
|
||||
if (gnc_book_use_book_currency (book))
|
||||
return gnc_commodity_table_lookup
|
||||
(gnc_commodity_table_get_table(book),
|
||||
GNC_COMMODITY_NS_CURRENCY,
|
||||
qof_book_get_book_currency_name (book));
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/** Returns pointer to default gain/loss policy for book or NULL; determines
|
||||
* that both book-currency and default gain/loss policy KVPs exist and that
|
||||
* both are valid, a requirement for the 'book-currency' currency accounting
|
||||
* method to apply. */
|
||||
const gchar *
|
||||
gnc_book_get_default_gains_policy (QofBook *book)
|
||||
{
|
||||
if (!book) return NULL;
|
||||
|
||||
if (gnc_book_use_book_currency (book))
|
||||
return qof_book_get_default_gains_policy (book);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/** Returns pointer to default gain/loss account for book or NULL; determines
|
||||
* that both book-currency and default gain/loss policy KVPs exist and that
|
||||
* both are valid, a requirement for the 'book-currency' currency accounting
|
||||
* method to apply. Also, account must not be hidden or a placeholder, and
|
||||
* must be of same currency as book-currency and income or expense type */
|
||||
Account *
|
||||
gnc_book_get_default_gain_loss_acct (QofBook *book)
|
||||
{
|
||||
Account *gains_account = NULL;
|
||||
|
||||
if (!book) return NULL;
|
||||
|
||||
if (gnc_book_use_book_currency (book))
|
||||
{
|
||||
GncGUID *guid = qof_book_get_default_gain_loss_acct_guid (book);
|
||||
gains_account = xaccAccountLookup (guid, book);
|
||||
guid_free (guid);
|
||||
}
|
||||
|
||||
if (gains_account &&
|
||||
!xaccAccountGetPlaceholder(gains_account) &&
|
||||
!xaccAccountGetHidden(gains_account) &&
|
||||
(gnc_commodity_equal(xaccAccountGetCommodity(gains_account),
|
||||
gnc_book_get_book_currency(book))) &&
|
||||
((xaccAccountGetType(gains_account) == ACCT_TYPE_INCOME) ||
|
||||
(xaccAccountGetType(gains_account) == ACCT_TYPE_EXPENSE)))
|
||||
{
|
||||
return gains_account;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
Account *
|
||||
gnc_get_current_root_account (void)
|
||||
{
|
||||
@ -1168,9 +1052,6 @@ gnc_default_currency_common (gchar *requested_currency,
|
||||
GNC_COMMODITY_NS_CURRENCY,
|
||||
requested_currency);
|
||||
|
||||
if (gnc_book_use_book_currency (gnc_get_current_book ()))
|
||||
return gnc_book_get_book_currency (gnc_get_current_book ());
|
||||
|
||||
if (gnc_prefs_get_bool (section, GNC_PREF_CURRENCY_CHOICE_OTHER))
|
||||
{
|
||||
mnemonic = gnc_prefs_get_string(section, GNC_PREF_CURRENCY_OTHER);
|
||||
|
@ -97,40 +97,6 @@ const gchar * gnc_get_current_book_tax_type (void);
|
||||
* callbacks when num_field_source book option changes so that
|
||||
* registers/reports can update themselves; sets feature flag */
|
||||
void gnc_book_option_num_field_source_change_cb (gboolean num_action);
|
||||
|
||||
/** Calls gnc_book_option_book_currency_selected to initiate registered
|
||||
* callbacks when currency accounting book option changes to book-currency so
|
||||
* that registers/reports can update themselves; sets feature flag */
|
||||
void gnc_book_option_book_currency_selected_cb (gboolean use_book_currency);
|
||||
|
||||
/** Returns TRUE if both book-currency and default gain/loss policy KVPs exist
|
||||
* and are valid and trading accounts are not used */
|
||||
gboolean gnc_book_use_book_currency (QofBook *book);
|
||||
|
||||
/** Returns pointer to Book Currency name for book or NULL; determines
|
||||
* that both book-currency and default gain/loss policy KVPs exist and that
|
||||
* both are valid, a requirement for the 'book-currency' currency accounting
|
||||
* method to apply. */
|
||||
const gchar * gnc_book_get_book_currency_name (QofBook *book);
|
||||
|
||||
/** Returns pointer to Book Currency for book or NULL; determines
|
||||
* that both book-currency and default gain/loss policy KVPs exist and that
|
||||
* both are valid, a requirement for the 'book-currency' currency accounting
|
||||
* method to apply. */
|
||||
gnc_commodity * gnc_book_get_book_currency (QofBook *book);
|
||||
|
||||
/** Returns pointer to default gain/loss policy for book or NULL; determines
|
||||
* that both book-currency and default gain/loss policy KVPs exist and that
|
||||
* both are valid, a requirement for the 'book-currency' currency accounting
|
||||
* method to apply. */
|
||||
const gchar * gnc_book_get_default_gains_policy (QofBook *book);
|
||||
|
||||
/** Returns pointer to default gain/loss account for book or NULL; determines
|
||||
* that both book-currency and default gain/loss policy KVPs exist and that
|
||||
* both are valid, a requirement for the 'book-currency' currency accounting
|
||||
* method to apply. */
|
||||
Account * gnc_book_get_default_gain_loss_acct (QofBook *book);
|
||||
|
||||
Account * gnc_get_current_root_account (void);
|
||||
gnc_commodity_table * gnc_get_current_commodities (void);
|
||||
|
||||
|
@ -106,15 +106,6 @@ struct _Getters
|
||||
SCM date_option_value_relative;
|
||||
SCM plot_size_option_value_type;
|
||||
SCM plot_size_option_value;
|
||||
SCM currency_accounting_option_currency_doc_string;
|
||||
SCM currency_accounting_option_default_currency;
|
||||
SCM currency_accounting_option_policy_doc_string;
|
||||
SCM currency_accounting_option_default_policy;
|
||||
SCM currency_accounting_option_gain_loss_account_doc_string;
|
||||
SCM currency_accounting_option_method;
|
||||
SCM currency_accounting_option_book_currency;
|
||||
SCM currency_accounting_option_selected_default_policy;
|
||||
SCM currency_accounting_option_selected_default_gain_loss_account;
|
||||
};
|
||||
|
||||
|
||||
@ -565,24 +556,6 @@ initialize_getters(void)
|
||||
scm_c_eval_string ("gnc:date-option-relative-time");
|
||||
getters.plot_size_option_value_type = scm_c_eval_string ("gnc:plot-size-option-value-type");
|
||||
getters.plot_size_option_value = scm_c_eval_string ("gnc:plot-size-option-value");
|
||||
getters.currency_accounting_option_currency_doc_string =
|
||||
scm_c_eval_string ("gnc:currency-accounting-option-get-curr-doc-string");
|
||||
getters.currency_accounting_option_default_currency =
|
||||
scm_c_eval_string ("gnc:currency-accounting-option-get-default-curr");
|
||||
getters.currency_accounting_option_policy_doc_string =
|
||||
scm_c_eval_string ("gnc:currency-accounting-option-get-policy-doc-string");
|
||||
getters.currency_accounting_option_default_policy =
|
||||
scm_c_eval_string ("gnc:currency-accounting-option-get-default-policy");
|
||||
getters.currency_accounting_option_gain_loss_account_doc_string =
|
||||
scm_c_eval_string ("gnc:currency-accounting-option-get-gain-loss-account-doc-string");
|
||||
getters.currency_accounting_option_method =
|
||||
scm_c_eval_string ("gnc:currency-accounting-option-selected-method");
|
||||
getters.currency_accounting_option_book_currency =
|
||||
scm_c_eval_string ("gnc:currency-accounting-option-selected-currency");
|
||||
getters.currency_accounting_option_selected_default_policy =
|
||||
scm_c_eval_string ("gnc:currency-accounting-option-selected-policy");
|
||||
getters.currency_accounting_option_selected_default_gain_loss_account =
|
||||
scm_c_eval_string ("gnc:currency-accounting-option-selected-gain-loss-account");
|
||||
|
||||
getters_initialized = TRUE;
|
||||
}
|
||||
@ -728,7 +701,7 @@ gnc_option_default_getter (GNCOption *option)
|
||||
* Args: option - the GNCOption *
|
||||
* Returns: SCM handle to function *
|
||||
\********************************************************************/
|
||||
static SCM
|
||||
SCM
|
||||
gnc_option_value_validator(GNCOption *option)
|
||||
{
|
||||
initialize_getters ();
|
||||
@ -749,7 +722,7 @@ gnc_option_value_validator(GNCOption *option)
|
||||
* Returns: SCM handle to function *
|
||||
* If no such function exists, returns SCM_UNDEFINED. *
|
||||
\********************************************************************/
|
||||
static SCM
|
||||
SCM
|
||||
gnc_option_widget_changed_proc_getter(GNCOption *option)
|
||||
{
|
||||
SCM cb;
|
||||
@ -2133,169 +2106,6 @@ gnc_plot_size_option_value_get_value (SCM option_value)
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
* gnc_currency_accounting_option_currency_documentation *
|
||||
* returns the malloc'ed documentation string for currency *
|
||||
* selector of the currency-accounting option, or NULL if it *
|
||||
* can't be retrieved. *
|
||||
* *
|
||||
* Args: option - the GNCOption *
|
||||
* Returns: malloc'ed char * or NULL *
|
||||
\********************************************************************/
|
||||
char *
|
||||
gnc_currency_accounting_option_currency_documentation (GNCOption *option)
|
||||
{
|
||||
initialize_getters ();
|
||||
|
||||
return gnc_scm_call_1_to_string
|
||||
(getters.currency_accounting_option_currency_doc_string,
|
||||
option->guile_option);
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
* gnc_currency_accounting_option_get_default_currency *
|
||||
* returns the SCM value for the currency-accounting option *
|
||||
* default currency. *
|
||||
* *
|
||||
* Args: option - the GNCOption *
|
||||
* Returns: SCM value *
|
||||
\********************************************************************/
|
||||
SCM
|
||||
gnc_currency_accounting_option_get_default_currency (GNCOption *option)
|
||||
{
|
||||
initialize_getters ();
|
||||
|
||||
return scm_call_1
|
||||
(getters.currency_accounting_option_default_currency,
|
||||
option->guile_option);
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
* gnc_currency_accounting_option_policy_documentation *
|
||||
* returns the malloc'ed documentation string for policy *
|
||||
* selector of the currency-accounting option, or NULL if it *
|
||||
* can't be retrieved. *
|
||||
* *
|
||||
* Args: option - the GNCOption *
|
||||
* Returns: malloc'ed char * or NULL *
|
||||
\********************************************************************/
|
||||
char *
|
||||
gnc_currency_accounting_option_policy_documentation (GNCOption *option)
|
||||
{
|
||||
initialize_getters ();
|
||||
|
||||
return gnc_scm_call_1_to_string
|
||||
(getters.currency_accounting_option_policy_doc_string,
|
||||
option->guile_option);
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
* gnc_currency_accounting_option_get_default_policy *
|
||||
* returns the SCM value for the currency-accounting option *
|
||||
* default policy. *
|
||||
* *
|
||||
* Args: option - the GNCOption *
|
||||
* Returns: SCM value *
|
||||
\********************************************************************/
|
||||
SCM
|
||||
gnc_currency_accounting_option_get_default_policy (GNCOption *option)
|
||||
{
|
||||
initialize_getters ();
|
||||
|
||||
return scm_call_1
|
||||
(getters.currency_accounting_option_default_policy,
|
||||
option->guile_option);
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
* gnc_currency_accounting_option_gain_loss_account_documentation *
|
||||
* returns the malloc'ed documentation string for account *
|
||||
* selector of the currency-accounting option, or NULL if it *
|
||||
* can't be retrieved. *
|
||||
* *
|
||||
* Args: option - the GNCOption *
|
||||
* Returns: malloc'ed char * or NULL *
|
||||
\********************************************************************/
|
||||
char *
|
||||
gnc_currency_accounting_option_gain_loss_account_documentation (GNCOption *option)
|
||||
{
|
||||
initialize_getters ();
|
||||
|
||||
return gnc_scm_call_1_to_string
|
||||
(getters.currency_accounting_option_gain_loss_account_doc_string,
|
||||
option->guile_option);
|
||||
}
|
||||
|
||||
/*******************************************************************\
|
||||
* gnc_currency_accounting_option_value_get_method *
|
||||
* get the currency accounting method of the option as a symbol *
|
||||
* *
|
||||
* Args: option_value - option value to get method of *
|
||||
* Return: SCM value *
|
||||
\*******************************************************************/
|
||||
SCM
|
||||
gnc_currency_accounting_option_value_get_method (SCM option_value)
|
||||
{
|
||||
initialize_getters ();
|
||||
|
||||
return scm_call_1 (getters.currency_accounting_option_method,
|
||||
option_value);
|
||||
}
|
||||
|
||||
/*******************************************************************\
|
||||
* gnc_currency_accounting_option_value_get_book_currency *
|
||||
* get the book-currency if that is the currency accounting *
|
||||
* method of the option as a symbol *
|
||||
* *
|
||||
* Args: option_value - option value to get method of *
|
||||
* Return: SCM value *
|
||||
\*******************************************************************/
|
||||
SCM
|
||||
gnc_currency_accounting_option_value_get_book_currency (SCM option_value)
|
||||
{
|
||||
initialize_getters ();
|
||||
|
||||
return scm_call_1 (getters.currency_accounting_option_book_currency,
|
||||
option_value);
|
||||
}
|
||||
|
||||
/*******************************************************************\
|
||||
* gnc_currency_accounting_option_value_get_default_policy *
|
||||
* get the default policy if book-currency is the currency *
|
||||
* accounting method of the option as a symbol *
|
||||
* *
|
||||
* Args: option_value - option value to get method of *
|
||||
* Return: SCM value *
|
||||
\*******************************************************************/
|
||||
SCM
|
||||
gnc_currency_accounting_option_value_get_default_policy (SCM option_value)
|
||||
{
|
||||
initialize_getters ();
|
||||
|
||||
return scm_call_1
|
||||
(getters.currency_accounting_option_selected_default_policy,
|
||||
option_value);
|
||||
}
|
||||
|
||||
/*******************************************************************\
|
||||
* gnc_currency_accounting_option_value_get_default_account *
|
||||
* get the default gain/loss account if book-currency is the *
|
||||
* currency accounting method, if one is specified, of the *
|
||||
* option as a symbol *
|
||||
* *
|
||||
* Args: option_value - option value to get method of *
|
||||
* Return: SCM value *
|
||||
\*******************************************************************/
|
||||
SCM
|
||||
gnc_currency_accounting_option_value_get_default_account (SCM option_value)
|
||||
{
|
||||
initialize_getters ();
|
||||
|
||||
return scm_call_1
|
||||
(getters.currency_accounting_option_selected_default_gain_loss_account,
|
||||
option_value);
|
||||
}
|
||||
|
||||
static int
|
||||
find_option_db_with_selectable_pred (gpointer key, gpointer value, gpointer data)
|
||||
{
|
||||
|
@ -201,89 +201,6 @@ guint32 gnc_option_db_lookup_color_option_argb (GNCOptionDB *odb,
|
||||
const char *name,
|
||||
guint32 default_value);
|
||||
|
||||
void gnc_option_db_unregister_change_callback_id(GNCOptionDB *odb,
|
||||
SCM callback_id);
|
||||
|
||||
char * gnc_option_section(GNCOption *option);
|
||||
char * gnc_option_name(GNCOption *option);
|
||||
char * gnc_option_type(GNCOption *option);
|
||||
char * gnc_option_sort_tag(GNCOption *option);
|
||||
char * gnc_option_documentation(GNCOption *option);
|
||||
SCM gnc_option_getter(GNCOption *option);
|
||||
SCM gnc_option_setter(GNCOption *option);
|
||||
SCM gnc_option_default_getter(GNCOption *option);
|
||||
SCM gnc_option_get_option_data(GNCOption *option);
|
||||
|
||||
int gnc_option_num_permissible_values(GNCOption *option);
|
||||
int gnc_option_permissible_value_index(GNCOption *option, SCM value);
|
||||
SCM gnc_option_permissible_value(GNCOption *option, int index);
|
||||
char * gnc_option_permissible_value_name(GNCOption *option, int index);
|
||||
char * gnc_option_permissible_value_description(GNCOption *option, int index);
|
||||
|
||||
gboolean gnc_option_show_time(GNCOption *option);
|
||||
|
||||
gboolean gnc_option_multiple_selection(GNCOption *option);
|
||||
GList * gnc_option_get_account_type_list(GNCOption *option);
|
||||
|
||||
gboolean gnc_option_get_range_info(GNCOption *option,
|
||||
double *lower_bound,
|
||||
double *upper_bound,
|
||||
int *num_decimals,
|
||||
double *step_size);
|
||||
|
||||
gdouble gnc_option_color_range(GNCOption *option);
|
||||
gdouble gnc_option_use_alpha(GNCOption *option);
|
||||
gboolean gnc_option_get_color_info(GNCOption *option,
|
||||
gboolean use_default,
|
||||
gdouble *red,
|
||||
gdouble *green,
|
||||
gdouble *blue,
|
||||
gdouble *alpha);
|
||||
|
||||
void gnc_option_call_option_widget_changed_proc (GNCOption *option);
|
||||
|
||||
void gnc_option_set_default(GNCOption *option);
|
||||
|
||||
guint gnc_option_db_num_sections(GNCOptionDB *odb);
|
||||
|
||||
const char * gnc_option_section_name(GNCOptionSection *section);
|
||||
guint gnc_option_section_num_options(GNCOptionSection *section);
|
||||
|
||||
GNCOptionSection * gnc_option_db_get_section(GNCOptionDB *odb, gint i);
|
||||
|
||||
GNCOption * gnc_get_option_section_option(GNCOptionSection *section, int i);
|
||||
|
||||
GNCOption * gnc_option_db_get_option_by_name(GNCOptionDB *odb,
|
||||
const char *section_name,
|
||||
const char *name);
|
||||
|
||||
void gnc_option_db_clean(GNCOptionDB *odb);
|
||||
|
||||
gboolean gnc_option_db_get_changed(GNCOptionDB *odb);
|
||||
GList* gnc_option_db_commit(GNCOptionDB *odb);
|
||||
|
||||
char * gnc_option_db_get_default_section(GNCOptionDB *odb);
|
||||
|
||||
SCM gnc_option_db_lookup_option(GNCOptionDB *odb,
|
||||
const char *section,
|
||||
const char *name,
|
||||
SCM default_value);
|
||||
|
||||
gboolean gnc_option_db_lookup_boolean_option(GNCOptionDB *odb,
|
||||
const char *section,
|
||||
const char *name,
|
||||
gboolean default_value);
|
||||
|
||||
char * gnc_option_db_lookup_string_option(GNCOptionDB *odb,
|
||||
const char *section,
|
||||
const char *name,
|
||||
const char *default_value);
|
||||
|
||||
gdouble gnc_option_db_lookup_number_option(GNCOptionDB *odb,
|
||||
const char *section,
|
||||
const char *name,
|
||||
gdouble default_value);
|
||||
|
||||
gboolean gnc_option_db_set_option(GNCOptionDB *odb,
|
||||
const char *section,
|
||||
const char *name,
|
||||
@ -313,16 +230,6 @@ SCM gnc_date_option_value_get_relative (SCM option_value);
|
||||
char * gnc_plot_size_option_value_get_type (SCM option_value);
|
||||
gdouble gnc_plot_size_option_value_get_value (SCM option_value);
|
||||
|
||||
char * gnc_currency_accounting_option_currency_documentation (GNCOption *option);
|
||||
SCM gnc_currency_accounting_option_get_default_currency (GNCOption *option);
|
||||
char * gnc_currency_accounting_option_policy_documentation (GNCOption *option);
|
||||
SCM gnc_currency_accounting_option_get_default_policy (GNCOption *option);
|
||||
char * gnc_currency_accounting_option_gain_loss_account_documentation (GNCOption *option);
|
||||
SCM gnc_currency_accounting_option_value_get_method (SCM option_value);
|
||||
SCM gnc_currency_accounting_option_value_get_book_currency (SCM option_value);
|
||||
SCM gnc_currency_accounting_option_value_get_default_policy (SCM option_value);
|
||||
SCM gnc_currency_accounting_option_value_get_default_account (SCM option_value);
|
||||
|
||||
void gnc_option_db_set_option_selectable_by_name (SCM guile_options,
|
||||
const char *section,
|
||||
const char *name,
|
||||
|
@ -141,11 +141,6 @@
|
||||
|
||||
(define gnc:*option-section-accounts* OPTION-SECTION-ACCOUNTS)
|
||||
(define gnc:*option-name-trading-accounts* OPTION-NAME-TRADING-ACCOUNTS)
|
||||
(define gnc:*option-name-currency-accounting* OPTION-NAME-CURRENCY-ACCOUNTING)
|
||||
(define gnc:*option-name-book-currency* OPTION-NAME-BOOK-CURRENCY)
|
||||
(define gnc:*option-name-default-gains-policy* OPTION-NAME-DEFAULT-GAINS-POLICY)
|
||||
(define gnc:*option-name-default-gain-loss-account*
|
||||
OPTION-NAME-DEFAULT-GAINS-LOSS-ACCT-GUID)
|
||||
|
||||
(define (gnc:option-get-value book category key)
|
||||
(define acc (if (pair? key) cons list))
|
||||
@ -1529,262 +1524,6 @@ the option '~a'."))
|
||||
(define (gnc:dateformat-get-format v)
|
||||
(cadddr v))
|
||||
|
||||
(define (gnc:make-currency-accounting-option
|
||||
section
|
||||
name
|
||||
sort-tag
|
||||
radiobutton-documentation-string
|
||||
default-radiobutton-value
|
||||
ok-radiobutton-values
|
||||
book-currency-documentation-string
|
||||
default-book-currency-value
|
||||
default-cap-gains-policy-documentation-string
|
||||
default-cap-gains-policy-value
|
||||
default-gains-loss-account-documentation-string
|
||||
)
|
||||
(define (legal-val val p-vals)
|
||||
(cond ((null? p-vals) #f)
|
||||
((not (symbol? val)) #f)
|
||||
((eq? val (vector-ref (car p-vals) 0)) #t)
|
||||
(else (legal-val val (cdr p-vals)))))
|
||||
|
||||
(define (currency-lookup currency-string)
|
||||
(if (string? currency-string)
|
||||
(gnc-commodity-table-lookup
|
||||
(gnc-commodity-table-get-table (gnc-get-current-book))
|
||||
GNC_COMMODITY_NS_CURRENCY currency-string)
|
||||
#f))
|
||||
|
||||
(define (currency? val)
|
||||
(gnc-commodity-is-currency (currency-lookup val)))
|
||||
|
||||
(define (vector-strings p-vals)
|
||||
(if (null? p-vals)
|
||||
'()
|
||||
(cons (vector-ref (car p-vals) 1)
|
||||
(cons (vector-ref (car p-vals) 2)
|
||||
(vector-strings (cdr p-vals))))))
|
||||
|
||||
(define (currency->scm currency)
|
||||
(if (string? currency)
|
||||
currency
|
||||
(gnc-commodity-get-mnemonic currency)))
|
||||
|
||||
(define (scm->currency currency)
|
||||
(currency-lookup currency))
|
||||
|
||||
(define (valid-gains-loss-account? book-currency gains-loss-account-guid)
|
||||
;; xaccAccountLookup returns Account if guid valid otherwise NULL; also must
|
||||
;; be in book-currency, income or expense, and not placeholder nor hidden
|
||||
(let* ((account (xaccAccountLookup gains-loss-account-guid
|
||||
(gnc-get-current-book))))
|
||||
(and account
|
||||
(not (null? account))
|
||||
(not (xaccAccountIsHidden account))
|
||||
(not (xaccAccountGetPlaceholder account))
|
||||
(memv (xaccAccountGetType account)
|
||||
(list ACCT-TYPE-INCOME ACCT-TYPE-EXPENSE))
|
||||
(gnc-commodity-equal
|
||||
(currency-lookup book-currency)
|
||||
(xaccAccountGetCommodity account)))))
|
||||
|
||||
(let* ((value (if (eq? 'book-currency default-radiobutton-value)
|
||||
(list default-radiobutton-value
|
||||
default-book-currency-value
|
||||
default-cap-gains-policy-value)
|
||||
(list default-radiobutton-value)))
|
||||
(value->string (lambda ()
|
||||
(string-append "'" (gnc:value->string
|
||||
(car value)))))
|
||||
(trading-accounts-path (list gnc:*option-section-accounts*
|
||||
gnc:*option-name-trading-accounts*))
|
||||
(book-currency-path (list gnc:*option-section-accounts*
|
||||
gnc:*option-name-book-currency*))
|
||||
(gains-policy-path (list gnc:*option-section-accounts*
|
||||
gnc:*option-name-default-gains-policy*))
|
||||
(gains-loss-account-path (list gnc:*option-section-accounts*
|
||||
gnc:*option-name-default-gain-loss-account*)))
|
||||
(gnc:make-option
|
||||
section name sort-tag 'currency-accounting
|
||||
radiobutton-documentation-string
|
||||
(lambda () value) ;; getter
|
||||
(lambda (x)
|
||||
(if (legal-val (car x) ok-radiobutton-values)
|
||||
(set! value x)
|
||||
(gnc:error "Illegal Radiobutton option set"))) ;;setter
|
||||
(lambda () (if (eq? 'book-currency default-radiobutton-value)
|
||||
(list default-radiobutton-value
|
||||
default-book-currency-value
|
||||
default-cap-gains-policy-value)
|
||||
(list default-radiobutton-value))) ;; default-getter
|
||||
(gnc:restore-form-generator value->string)
|
||||
(lambda (b p) ;; scm->kvp
|
||||
(case (car value)
|
||||
((book-currency)
|
||||
;; Currency = selected currency
|
||||
(qof-book-set-option b (currency->scm (cadr value))
|
||||
book-currency-path)
|
||||
;; Default Gains Policy = selected policy
|
||||
(qof-book-set-option b (symbol->string (caddr value))
|
||||
gains-policy-path)
|
||||
;; Default Gains Account = if selected, selected account
|
||||
(if (car (cdddr value))
|
||||
(qof-book-set-option b (car (cdddr value))
|
||||
gains-loss-account-path)))
|
||||
((trading)
|
||||
;; Use Trading Accounts = "t"
|
||||
(qof-book-set-option b "t" trading-accounts-path))))
|
||||
(lambda (b p) ;; kvp->scm
|
||||
(let* ((trading-option-path-kvp?
|
||||
(qof-book-get-option b trading-accounts-path))
|
||||
(trading? (and trading-option-path-kvp?
|
||||
(string=? "t" trading-option-path-kvp?)))
|
||||
(book-currency #f)
|
||||
(cap-gains-policy #f)
|
||||
(gains-loss-account-guid #f)
|
||||
(v (if trading?
|
||||
'trading
|
||||
(let* ((book-currency-option-path-kvp?
|
||||
(qof-book-get-option
|
||||
b book-currency-path))
|
||||
(gains-policy-option-path-kvp?
|
||||
(qof-book-get-option
|
||||
b gains-policy-path))
|
||||
(gains-loss-account-option-path-kvp?
|
||||
(qof-book-get-option
|
||||
b gains-loss-account-path))
|
||||
(book-currency?
|
||||
(if (and book-currency-option-path-kvp?
|
||||
gains-policy-option-path-kvp?
|
||||
(string?
|
||||
book-currency-option-path-kvp?)
|
||||
(string?
|
||||
gains-policy-option-path-kvp?)
|
||||
(if book-currency-option-path-kvp?
|
||||
(currency?
|
||||
book-currency-option-path-kvp?))
|
||||
(if gains-policy-option-path-kvp?
|
||||
(gnc-valid-policy-name
|
||||
gains-policy-option-path-kvp?)))
|
||||
(begin
|
||||
(set! book-currency
|
||||
book-currency-option-path-kvp?)
|
||||
(set! cap-gains-policy
|
||||
gains-policy-option-path-kvp?)
|
||||
(if gains-loss-account-option-path-kvp?
|
||||
(if (valid-gains-loss-account?
|
||||
book-currency
|
||||
gains-loss-account-option-path-kvp?)
|
||||
(set! gains-loss-account-guid
|
||||
gains-loss-account-option-path-kvp?)))
|
||||
#t)
|
||||
#f)))
|
||||
(if book-currency?
|
||||
'book-currency
|
||||
'neither)))))
|
||||
(if (and v (symbol? v) (legal-val v ok-radiobutton-values))
|
||||
(set! value (cons v (if (eq? 'book-currency v)
|
||||
(list (scm->currency book-currency)
|
||||
(string->symbol cap-gains-policy)
|
||||
gains-loss-account-guid)
|
||||
'())))
|
||||
(set! value (list 'neither)))))
|
||||
(lambda (x) ;; value validator
|
||||
(cond
|
||||
((not (list? x))
|
||||
(list #f "value not a list"))
|
||||
((not (legal-val (car x) ok-radiobutton-values))
|
||||
(list #f "radiobutton-option: illegal choice"))
|
||||
((not (eq? 'book-currency (car x)))
|
||||
(list #t x))
|
||||
((not (currency? (currency->scm (cadr x))))
|
||||
(list #f "currency-option: illegal value"))
|
||||
((not (gnc-valid-policy-name (symbol->string (caddr x))))
|
||||
(list #f "cap-gains-policy-option: illegal value"))
|
||||
((not (car (cdddr x)))
|
||||
(list #t x))
|
||||
((not (valid-gains-loss-account? (currency->scm (cadr x))
|
||||
(car (cdddr x))))
|
||||
(list #f "gains-loss-account-option: illegal value"))
|
||||
(else
|
||||
(list #t x))))
|
||||
(vector book-currency-documentation-string
|
||||
default-book-currency-value
|
||||
default-cap-gains-policy-documentation-string
|
||||
default-cap-gains-policy-value
|
||||
default-gains-loss-account-documentation-string)
|
||||
(vector (lambda () (length ok-radiobutton-values))
|
||||
(lambda (x) (vector-ref (list-ref ok-radiobutton-values x) 0))
|
||||
(lambda (x) (vector-ref (list-ref ok-radiobutton-values x) 1))
|
||||
(lambda (x) (vector-ref (list-ref ok-radiobutton-values x) 2))
|
||||
(lambda (x)
|
||||
(gnc:multichoice-list-lookup ok-radiobutton-values x)))
|
||||
(lambda () (vector-strings ok-radiobutton-values))
|
||||
#f)))
|
||||
|
||||
(define (gnc:get-currency-accounting-option-data-curr-doc-string option-data)
|
||||
(vector-ref option-data 0))
|
||||
|
||||
(define (gnc:get-currency-accounting-option-data-default-curr option-data)
|
||||
(vector-ref option-data 1))
|
||||
|
||||
(define (gnc:get-currency-accounting-option-data-policy-doc-string option-data)
|
||||
(vector-ref option-data 2))
|
||||
|
||||
(define (gnc:get-currency-accounting-option-data-policy-default option-data)
|
||||
(vector-ref option-data 3))
|
||||
|
||||
(define (gnc:get-currency-accounting-option-data-gain-loss-account-doc-string option-data)
|
||||
(vector-ref option-data 4))
|
||||
|
||||
(define (gnc:currency-accounting-option-get-curr-doc-string option)
|
||||
(if (eq? (gnc:option-type option) 'currency-accounting)
|
||||
(gnc:get-currency-accounting-option-data-curr-doc-string
|
||||
(gnc:option-data option))
|
||||
(gnc:error "Not a currency accounting option")))
|
||||
|
||||
(define (gnc:currency-accounting-option-get-default-curr option)
|
||||
(if (eq? (gnc:option-type option) 'currency-accounting)
|
||||
(gnc:get-currency-accounting-option-data-default-curr
|
||||
(gnc:option-data option))
|
||||
(gnc:error "Not a currency accounting option")))
|
||||
|
||||
(define (gnc:currency-accounting-option-get-policy-doc-string option)
|
||||
(if (eq? (gnc:option-type option) 'currency-accounting)
|
||||
(gnc:get-currency-accounting-option-data-policy-doc-string
|
||||
(gnc:option-data option))
|
||||
(gnc:error "Not a currency accounting option")))
|
||||
|
||||
(define (gnc:currency-accounting-option-get-default-policy option)
|
||||
(if (eq? (gnc:option-type option) 'currency-accounting)
|
||||
(gnc:get-currency-accounting-option-data-policy-default
|
||||
(gnc:option-data option))
|
||||
(gnc:error "Not a currency accounting option")))
|
||||
|
||||
(define (gnc:currency-accounting-option-get-gain-loss-account-doc-string option)
|
||||
(if (eq? (gnc:option-type option) 'currency-accounting)
|
||||
(gnc:get-currency-accounting-option-data-gain-loss-account-doc-string
|
||||
(gnc:option-data option))
|
||||
(gnc:error "Not a currency accounting option")))
|
||||
|
||||
(define (gnc:currency-accounting-option-selected-method option-value)
|
||||
(car option-value))
|
||||
|
||||
(define (gnc:currency-accounting-option-selected-currency option-value)
|
||||
(if (eq? (car option-value) 'book-currency)
|
||||
(cadr option-value)
|
||||
#f))
|
||||
|
||||
(define (gnc:currency-accounting-option-selected-policy option-value)
|
||||
(if (eq? (car option-value) 'book-currency)
|
||||
(caddr option-value)
|
||||
#f))
|
||||
|
||||
(define (gnc:currency-accounting-option-selected-gain-loss-account option-value)
|
||||
(if (eq? (car option-value) 'book-currency)
|
||||
(car (cdddr option-value))
|
||||
#f))
|
||||
|
||||
;; Create a new options database
|
||||
(define (gnc:new-options)
|
||||
(define option-hash (make-hash-table 23))
|
||||
@ -1968,11 +1707,8 @@ the option '~a'."))
|
||||
(default-value (gnc:option-default-value option))
|
||||
(section (gnc:option-section option))
|
||||
(name (gnc:option-name option)))
|
||||
;; (gnc:debug "value: " value "; default: " default-value
|
||||
;; "; section: " section "; name: " name)
|
||||
(if (not (equal? value default-value))
|
||||
(let ((save-fcn (gnc:option-scm->kvp option)))
|
||||
;; (gnc:debug "save-fcn: " save-fcn)
|
||||
(if save-fcn
|
||||
(save-fcn book (list section name)))))))))
|
||||
|
||||
|
@ -12,7 +12,7 @@ set(APP_UTILS_TEST_INCLUDE_DIRS
|
||||
|
||||
set(APP_UTILS_TEST_LIBS gnc-app-utils gnc-test-engine test-core ${GIO_LDFLAGS} ${GUILE_LDFLAGS})
|
||||
|
||||
set(test_app_utils_SOURCES test-app-utils.c test-option-util.cpp test-gnc-ui-util.c)
|
||||
set(test_app_utils_SOURCES test-app-utils.c test-option-util.cpp)
|
||||
|
||||
macro(add_app_utils_test _TARGET _SOURCE_FILES)
|
||||
gnc_add_test(${_TARGET} "${_SOURCE_FILES}" APP_UTILS_TEST_INCLUDE_DIRS APP_UTILS_TEST_LIBS)
|
||||
|
@ -35,7 +35,6 @@ guile_main (void *closure, int argc, char **argv)
|
||||
scm_c_use_module("gnucash app-utils");
|
||||
|
||||
test_suite_option_util ();
|
||||
test_suite_gnc_ui_util ();
|
||||
retval = g_test_run ();
|
||||
|
||||
exit (retval);
|
||||
|
@ -1,262 +0,0 @@
|
||||
/********************************************************************
|
||||
* test-gnc-ui-util.c: GLib g_test test suite for gnc-ui-util.c. *
|
||||
* Copyright 2015 Alex Aycinena <alex.aycinena@gmail.com> *
|
||||
* *
|
||||
* 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, you can retrieve it from *
|
||||
* https://www.gnu.org/licenses/old-licenses/gpl-2.0.html *
|
||||
* or 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 *
|
||||
********************************************************************/
|
||||
|
||||
#include <config.h>
|
||||
#include <glib.h>
|
||||
#include <unittest-support.h>
|
||||
#include <qof.h>
|
||||
#include "test-engine-stuff.h"
|
||||
|
||||
#include "../gnc-ui-util.h"
|
||||
|
||||
static const gchar *suitename = "/app-utils/gnc-ui-util";
|
||||
void test_suite_gnc_ui_util (void);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
QofBook *book;
|
||||
GSList *hdlrs;
|
||||
} Fixture;
|
||||
|
||||
/* Expose a mostly-private QofInstance function to load options into
|
||||
* the Book.
|
||||
*/
|
||||
/*extern KvpFrame *qof_instance_get_slots (const QofInstance*); */
|
||||
|
||||
static void
|
||||
setup (Fixture *fixture, gconstpointer pData)
|
||||
{
|
||||
fixture->book = qof_book_new ();
|
||||
fixture->hdlrs = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
teardown (Fixture *fixture, gconstpointer pData)
|
||||
{
|
||||
qof_book_destroy (fixture->book);
|
||||
g_slist_free_full (fixture->hdlrs, test_free_log_handler);
|
||||
test_clear_error_list();
|
||||
}
|
||||
|
||||
static void
|
||||
test_book_use_book_currency( Fixture *fixture, gconstpointer pData )
|
||||
{
|
||||
const gchar *cur;
|
||||
const gchar *pol;
|
||||
Account *acct, *acc;
|
||||
|
||||
g_test_message( "Testing with no currency accounting method selected" );
|
||||
cur = gnc_book_get_book_currency_name( fixture-> book );
|
||||
g_assert_cmpstr( cur, == , NULL );
|
||||
pol = gnc_book_get_default_gains_policy( fixture-> book );
|
||||
g_assert_cmpstr( pol, == , NULL );
|
||||
acct = gnc_book_get_default_gain_loss_acct ( fixture-> book );
|
||||
g_assert (acct == NULL );
|
||||
g_assert( !gnc_book_use_book_currency ( fixture-> book ));
|
||||
|
||||
g_test_message( "Testing with trading accounts set to true - t" );
|
||||
qof_book_begin_edit (fixture->book);
|
||||
qof_instance_set (QOF_INSTANCE (fixture->book),
|
||||
"trading-accts", "t",
|
||||
NULL);
|
||||
cur = gnc_book_get_book_currency_name( fixture-> book );
|
||||
g_assert_cmpstr( cur, == , NULL );
|
||||
pol = gnc_book_get_default_gains_policy( fixture-> book );
|
||||
g_assert_cmpstr( pol, == , NULL );
|
||||
acct = gnc_book_get_default_gain_loss_acct ( fixture-> book );
|
||||
g_assert (acct == NULL );
|
||||
g_assert( !gnc_book_use_book_currency ( fixture-> book ));
|
||||
qof_book_commit_edit (fixture->book);
|
||||
|
||||
qof_book_destroy( fixture->book );
|
||||
fixture->book = qof_book_new();
|
||||
|
||||
g_test_message( "Testing with valid book-currency but default-gains-policy set to nonsense and default-gain-loss-account-guid set to random valid acct" );
|
||||
qof_book_begin_edit (fixture->book);
|
||||
qof_instance_set (QOF_INSTANCE (fixture->book),
|
||||
"book-currency", "USD",
|
||||
NULL);
|
||||
qof_instance_set (QOF_INSTANCE (fixture->book),
|
||||
"default-gains-policy", "random",
|
||||
NULL);
|
||||
acc = get_random_account( fixture-> book );
|
||||
qof_instance_set (QOF_INSTANCE (fixture->book),
|
||||
"default-gain-loss-account-guid", qof_entity_get_guid(QOF_INSTANCE(acc)),
|
||||
NULL);
|
||||
cur = gnc_book_get_book_currency_name( fixture-> book );
|
||||
g_assert_cmpstr( cur, == , NULL );
|
||||
pol = gnc_book_get_default_gains_policy( fixture-> book );
|
||||
g_assert_cmpstr( pol, == , NULL );
|
||||
acct = gnc_book_get_default_gain_loss_acct ( fixture-> book );
|
||||
g_assert (acct == NULL );
|
||||
g_assert( !gnc_book_use_book_currency ( fixture-> book ));
|
||||
qof_book_commit_edit (fixture->book);
|
||||
|
||||
qof_book_destroy( fixture->book );
|
||||
fixture->book = qof_book_new();
|
||||
|
||||
/* g_test_message( "Testing with valid default-gains-policy but book-currency set to nonsense and default-gain-loss-account-guid set to random valid acct" );
|
||||
qof_book_begin_edit (fixture->book);
|
||||
qof_instance_set (QOF_INSTANCE (fixture->book),
|
||||
"book-currency", "myMoney",
|
||||
NULL);
|
||||
qof_instance_set (QOF_INSTANCE (fixture->book),
|
||||
"default-gains-policy", "fifo",
|
||||
NULL);
|
||||
acc = get_random_account( fixture-> book );
|
||||
qof_instance_set (QOF_INSTANCE (fixture->book),
|
||||
"default-gain-loss-account-guid", qof_entity_get_guid(QOF_INSTANCE(acc)),
|
||||
NULL);
|
||||
cur = gnc_book_get_book_currency_name( fixture-> book );
|
||||
g_assert_cmpstr( cur, == , NULL );
|
||||
pol = gnc_book_get_default_gains_policy( fixture-> book );
|
||||
g_assert_cmpstr( pol, == , NULL );
|
||||
acct = gnc_book_get_default_gain_loss_acct ( fixture-> book );
|
||||
g_assert (acct == NULL );
|
||||
g_assert( !gnc_book_use_book_currency ( fixture-> book ));
|
||||
qof_book_commit_edit (fixture->book);
|
||||
|
||||
qof_book_destroy( fixture->book );
|
||||
fixture->book = qof_book_new();
|
||||
|
||||
g_test_message( "Testing with book-currency and default-gains-policy set to nonsense and default-gain-loss-account-guid set to random valid acct" );
|
||||
qof_book_begin_edit (fixture->book);
|
||||
qof_instance_set (QOF_INSTANCE (fixture->book),
|
||||
"book-currency", "myMoney",
|
||||
NULL);
|
||||
qof_instance_set (QOF_INSTANCE (fixture->book),
|
||||
"default-gains-policy", "random",
|
||||
NULL);
|
||||
acc = get_random_account( fixture-> book );
|
||||
qof_instance_set (QOF_INSTANCE (fixture->book),
|
||||
"default-gain-loss-account-guid", qof_entity_get_guid(QOF_INSTANCE(acc)),
|
||||
NULL);
|
||||
cur = gnc_book_get_book_currency_name( fixture-> book );
|
||||
g_assert_cmpstr( cur, == , NULL );
|
||||
pol = gnc_book_get_default_gains_policy( fixture-> book );
|
||||
g_assert_cmpstr( pol, == , NULL );
|
||||
acct = gnc_book_get_default_gain_loss_acct ( fixture-> book );
|
||||
g_assert (acct == NULL );
|
||||
g_assert( !gnc_book_use_book_currency ( fixture-> book ));
|
||||
qof_book_commit_edit (fixture->book);
|
||||
|
||||
qof_book_destroy( fixture->book );
|
||||
fixture->book = qof_book_new();
|
||||
|
||||
g_test_message( "Testing with book-currency set and no default-gains-policy and default-gain-loss-account-guid set to random valid acct" );
|
||||
qof_book_begin_edit (fixture->book);
|
||||
qof_instance_set (QOF_INSTANCE (fixture->book),
|
||||
"book-currency", "USD",
|
||||
NULL);
|
||||
acc = get_random_account( fixture-> book );
|
||||
qof_instance_set (QOF_INSTANCE (fixture->book),
|
||||
"default-gain-loss-account-guid", qof_entity_get_guid(QOF_INSTANCE(acc)),
|
||||
NULL);
|
||||
cur = gnc_book_get_book_currency_name( fixture-> book );
|
||||
g_assert_cmpstr( cur, == , NULL );
|
||||
pol = gnc_book_get_default_gains_policy( fixture-> book );
|
||||
g_assert_cmpstr( pol, == , NULL );
|
||||
acct = gnc_book_get_default_gain_loss_acct ( fixture-> book );
|
||||
g_assert (acct == NULL );
|
||||
g_assert( !gnc_book_use_book_currency ( fixture-> book ));
|
||||
qof_book_commit_edit (fixture->book);
|
||||
|
||||
qof_book_destroy( fixture->book );
|
||||
fixture->book = qof_book_new();
|
||||
|
||||
g_test_message( "Testing with default-gains-policy set and no book-currency and default-gain-loss-account-guid set to random valid acct" );
|
||||
qof_book_begin_edit (fixture->book);
|
||||
qof_instance_set (QOF_INSTANCE (fixture->book),
|
||||
"default-gains-policy", "fifo",
|
||||
NULL);
|
||||
acc = get_random_account( fixture-> book );
|
||||
qof_instance_set (QOF_INSTANCE (fixture->book),
|
||||
"default-gain-loss-account-guid", qof_entity_get_guid(QOF_INSTANCE(acc)),
|
||||
NULL);
|
||||
cur = gnc_book_get_book_currency_name( fixture-> book );
|
||||
g_assert_cmpstr( cur, == , NULL );
|
||||
pol = gnc_book_get_default_gains_policy( fixture-> book );
|
||||
g_assert_cmpstr( pol, == , NULL );
|
||||
acct = gnc_book_get_default_gain_loss_acct ( fixture-> book );
|
||||
g_assert (acct == NULL );
|
||||
g_assert( !gnc_book_use_book_currency ( fixture-> book ));
|
||||
qof_book_commit_edit (fixture->book);
|
||||
|
||||
qof_book_destroy( fixture->book );
|
||||
fixture->book = qof_book_new();
|
||||
|
||||
g_test_message( "Testing with book-currency, default-gains-policy and default-gain-loss-account-guid set to valid values and with trading accounts set to true - t" );
|
||||
qof_book_begin_edit (fixture->book);
|
||||
qof_instance_set (QOF_INSTANCE (fixture->book),
|
||||
"trading-accts", "t",
|
||||
NULL);
|
||||
qof_instance_set (QOF_INSTANCE (fixture->book),
|
||||
"book-currency", "USD",
|
||||
NULL);
|
||||
qof_instance_set (QOF_INSTANCE (fixture->book),
|
||||
"default-gains-policy", "fifo",
|
||||
NULL);
|
||||
acc = get_random_account( fixture-> book );
|
||||
qof_instance_set (QOF_INSTANCE (fixture->book),
|
||||
"default-gain-loss-account-guid", qof_entity_get_guid(QOF_INSTANCE(acc)),
|
||||
NULL);
|
||||
cur = gnc_book_get_book_currency_name( fixture-> book );
|
||||
g_assert_cmpstr( cur, == , NULL );
|
||||
pol = gnc_book_get_default_gains_policy( fixture-> book );
|
||||
g_assert_cmpstr( pol, == , NULL );
|
||||
acct = gnc_book_get_default_gain_loss_acct ( fixture-> book );
|
||||
g_assert (acct == NULL );
|
||||
g_assert( !gnc_book_use_book_currency ( fixture-> book ));
|
||||
qof_book_commit_edit (fixture->book);
|
||||
|
||||
qof_book_destroy( fixture->book );
|
||||
fixture->book = qof_book_new();
|
||||
|
||||
g_test_message( "Testing with book-currency, default-gains-policy and default-gain-loss-account-guid set to valid values and no trading accounts flag" );
|
||||
qof_book_begin_edit (fixture->book);
|
||||
qof_instance_set (QOF_INSTANCE (fixture->book),
|
||||
"book-currency", "USD",
|
||||
NULL);
|
||||
qof_instance_set (QOF_INSTANCE (fixture->book),
|
||||
"default-gains-policy", "fifo",
|
||||
NULL);
|
||||
qof_instance_set (QOF_INSTANCE (fixture->book),
|
||||
"default-gain-loss-account-guid", qof_entity_get_guid(QOF_INSTANCE(acc)),
|
||||
NULL);
|
||||
cur = gnc_book_get_book_currency_name( fixture-> book );
|
||||
g_assert_cmpstr( cur, == , "USD" );
|
||||
pol = gnc_book_get_default_gains_policy( fixture-> book );
|
||||
g_assert_cmpstr( pol, == , "fifo" );
|
||||
acct = gnc_book_get_default_gain_loss_acct ( fixture-> book );
|
||||
g_assert ( xaccAccountEqual(acct, acc, TRUE) );
|
||||
g_assert( gnc_book_use_book_currency ( fixture-> book ));
|
||||
qof_book_commit_edit (fixture->book); */
|
||||
}
|
||||
|
||||
void
|
||||
test_suite_gnc_ui_util (void)
|
||||
{
|
||||
GNC_TEST_ADD( suitename, "use book-currency", Fixture, NULL, setup, test_book_use_book_currency, teardown );
|
||||
|
||||
}
|
@ -188,22 +188,6 @@ gnc_book_option_num_field_source_change (gboolean num_action)
|
||||
g_hook_list_invoke(bo_final_hook_list, TRUE);
|
||||
}
|
||||
|
||||
/** Calls registered callbacks when book_currency book option changes so that
|
||||
* registers/reports can update themselves */
|
||||
void
|
||||
gnc_book_option_book_currency_selected (gboolean use_book_currency)
|
||||
{
|
||||
GHookList *hook_list;
|
||||
const gchar *key = OPTION_NAME_BOOK_CURRENCY;
|
||||
|
||||
g_once(&bo_init_once, bo_init, NULL);
|
||||
|
||||
hook_list = g_hash_table_lookup(bo_callback_hash, key);
|
||||
if (hook_list != NULL)
|
||||
g_hook_list_marshal(hook_list, TRUE, bo_call_hook, &use_book_currency);
|
||||
g_hook_list_invoke(bo_final_hook_list, TRUE);
|
||||
}
|
||||
|
||||
void
|
||||
gnc_book_option_register_cb (gchar *key, GncBOCb func, gpointer user_data)
|
||||
{
|
||||
|
@ -74,11 +74,6 @@ void gnc_set_num_action (Transaction *trans, Split *split,
|
||||
void
|
||||
gnc_book_option_num_field_source_change (gboolean num_action);
|
||||
|
||||
/** Calls registered callbacks when book_currency book option changes so that
|
||||
* registers/reports can update themselves */
|
||||
void
|
||||
gnc_book_option_book_currency_selected (gboolean use_book_currency);
|
||||
|
||||
/** Registers callbacks to be called when the book option changes for the
|
||||
* specified book option key */
|
||||
void
|
||||
|
@ -44,7 +44,6 @@ static gncFeature known_features[] =
|
||||
{ GNC_FEATURE_CREDIT_NOTES, "Customer and vendor credit notes (requires at least GnuCash 2.5.0)" },
|
||||
{ GNC_FEATURE_NUM_FIELD_SOURCE, "User specifies source of 'num' field'; either transaction number or split action (requires at least GnuCash 2.5.0)" },
|
||||
{ GNC_FEATURE_KVP_EXTRA_DATA, "Extra data for addresses, jobs or invoice entries (requires at least GnuCash 2.6.4)" },
|
||||
{ GNC_FEATURE_BOOK_CURRENCY, "User specifies a 'book-currency'; costs of other currencies/commodities tracked in terms of book-currency (requires at least GnuCash 2.7.0)" },
|
||||
{ GNC_FEATURE_GUID_BAYESIAN, "Use account GUID as key for Bayesian data (requires at least GnuCash 2.6.12)" },
|
||||
{ GNC_FEATURE_GUID_FLAT_BAYESIAN, "Use account GUID as key for bayesian data and store KVP flat (requires at least Gnucash 2.6.19)" },
|
||||
{ GNC_FEATURE_SQLITE3_ISO_DATES, "Use ISO formatted date-time strings in SQLite3 databases (requires at least GnuCash 2.6.20)"},
|
||||
|
@ -48,7 +48,6 @@ extern "C" {
|
||||
#define GNC_FEATURE_CREDIT_NOTES "Credit Notes"
|
||||
#define GNC_FEATURE_NUM_FIELD_SOURCE "Number Field Source"
|
||||
#define GNC_FEATURE_KVP_EXTRA_DATA "Extra data in addresses, jobs or invoice entries"
|
||||
#define GNC_FEATURE_BOOK_CURRENCY "Use a Book-Currency"
|
||||
#define GNC_FEATURE_GUID_BAYESIAN "Account GUID based Bayesian data"
|
||||
#define GNC_FEATURE_GUID_FLAT_BAYESIAN "Account GUID based bayesian with flat KVP"
|
||||
#define GNC_FEATURE_SQLITE3_ISO_DATES "ISO-8601 formatted date strings in SQLite3 databases."
|
||||
|
@ -63,9 +63,6 @@
|
||||
|
||||
struct gncpolicy_s
|
||||
{
|
||||
char *name;
|
||||
char *description;
|
||||
char *hint;
|
||||
GNCLot * (*PolicyGetLot) (GNCPolicy *, Split *split);
|
||||
Split * (*PolicyGetSplit) (GNCPolicy *, GNCLot *lot);
|
||||
void (*PolicyGetLotOpening) (GNCPolicy *, GNCLot *lot,
|
||||
|
@ -63,47 +63,6 @@
|
||||
|
||||
//static QofLogModule log_module = GNC_MOD_LOT;
|
||||
|
||||
GList *
|
||||
gnc_get_valid_policy_list (void)
|
||||
{
|
||||
GList *return_list = NULL;
|
||||
|
||||
/* return_list = g_list_prepend (return_list, xaccGetManualPolicy());
|
||||
return_list = g_list_prepend (return_list, xaccGetAveragePolicy()); */
|
||||
return_list = g_list_prepend (return_list, xaccGetLIFOPolicy());
|
||||
return_list = g_list_prepend (return_list, xaccGetFIFOPolicy());
|
||||
|
||||
return return_list;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gnc_valid_policy_name (const gchar *policy_name)
|
||||
{
|
||||
GList *list_of_policies = NULL;
|
||||
gboolean ret_val = FALSE;
|
||||
|
||||
if (!policy_name)
|
||||
return ret_val;
|
||||
|
||||
list_of_policies = gnc_get_valid_policy_list();
|
||||
if (!list_of_policies)
|
||||
{
|
||||
return ret_val;
|
||||
}
|
||||
else
|
||||
{
|
||||
GList *l = NULL;
|
||||
for (l = list_of_policies; l != NULL; l = l->next)
|
||||
{
|
||||
GNCPolicy *list_pcy = l->data;
|
||||
if (g_strcmp0(PolicyGetName (list_pcy), policy_name) == 0)
|
||||
ret_val = TRUE;
|
||||
}
|
||||
g_list_free(list_of_policies);
|
||||
return ret_val;
|
||||
}
|
||||
}
|
||||
|
||||
static Split *
|
||||
DirectionPolicyGetSplit (GNCPolicy *pcy, GNCLot *lot, short reverse)
|
||||
{
|
||||
@ -189,26 +148,6 @@ donext:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *
|
||||
PolicyGetName (const GNCPolicy *pcy)
|
||||
{
|
||||
if(!pcy) return NULL;
|
||||
return pcy->name;
|
||||
}
|
||||
|
||||
const char *
|
||||
PolicyGetDescription (const GNCPolicy *pcy)
|
||||
{
|
||||
if(!pcy) return NULL;
|
||||
return pcy->description;
|
||||
}
|
||||
const char *
|
||||
PolicyGetHint (const GNCPolicy *pcy)
|
||||
{
|
||||
if(!pcy) return NULL;
|
||||
return pcy->hint;
|
||||
}
|
||||
|
||||
/* ============================================================== */
|
||||
|
||||
static GNCLot *
|
||||
@ -255,9 +194,6 @@ xaccGetFIFOPolicy (void)
|
||||
if (!pcy)
|
||||
{
|
||||
pcy = g_new (GNCPolicy, 1);
|
||||
pcy->name = FIFO_POLICY;
|
||||
pcy->description = FIFO_POLICY_DESC;
|
||||
pcy->hint = FIFO_POLICY_HINT;
|
||||
pcy->PolicyGetLot = FIFOPolicyGetLot;
|
||||
pcy->PolicyGetSplit = FIFOPolicyGetSplit;
|
||||
pcy->PolicyGetLotOpening = FIFOPolicyGetLotOpening;
|
||||
@ -304,23 +240,4 @@ LIFOPolicyIsOpeningSplit (GNCPolicy *pcy, GNCLot *lot, Split *split)
|
||||
return (split == opening_split);
|
||||
}
|
||||
|
||||
GNCPolicy *
|
||||
xaccGetLIFOPolicy (void)
|
||||
{
|
||||
static GNCPolicy *pcy = NULL;
|
||||
|
||||
if (!pcy)
|
||||
{
|
||||
pcy = g_new (GNCPolicy, 1);
|
||||
pcy->name = LIFO_POLICY;
|
||||
pcy->description = LIFO_POLICY_DESC;
|
||||
pcy->hint = LIFO_POLICY_HINT;
|
||||
pcy->PolicyGetLot = LIFOPolicyGetLot;
|
||||
pcy->PolicyGetSplit = LIFOPolicyGetSplit;
|
||||
pcy->PolicyGetLotOpening = LIFOPolicyGetLotOpening;
|
||||
pcy->PolicyIsOpeningSplit = LIFOPolicyIsOpeningSplit;
|
||||
}
|
||||
return pcy;
|
||||
}
|
||||
|
||||
/* =========================== END OF FILE ======================= */
|
||||
|
@ -43,24 +43,6 @@ extern "C" {
|
||||
|
||||
typedef struct gncpolicy_s GNCPolicy;
|
||||
|
||||
/** Valid Policy List
|
||||
* Provides a glist of implemented policies.
|
||||
*
|
||||
* List must be freed with g_list_free().
|
||||
*/
|
||||
GList * gnc_get_valid_policy_list (void);
|
||||
|
||||
/** Valid Policy Name
|
||||
* Uses the Valid Policy List to determine if a policy name is valid.
|
||||
*/
|
||||
gboolean gnc_valid_policy_name (const gchar *policy_name);
|
||||
|
||||
const char *PolicyGetName (const GNCPolicy *pcy);
|
||||
|
||||
const char *PolicyGetDescription (const GNCPolicy *pcy);
|
||||
|
||||
const char *PolicyGetHint (const GNCPolicy *pcy);
|
||||
|
||||
/** First-in, First-out Policy
|
||||
* This policy will create FIFO Lots. FIFO Lots have the following
|
||||
* properties:
|
||||
@ -69,24 +51,10 @@ const char *PolicyGetHint (const GNCPolicy *pcy);
|
||||
* -- Splits are added to the lot in date order, with earliest splits
|
||||
* added first.
|
||||
* -- All splits in the lot share the same transaction currency as
|
||||
* the split that opened the lot (if book-currency book option
|
||||
* selected, this will always be book currency).
|
||||
* the split that opened the lot
|
||||
*/
|
||||
GNCPolicy *xaccGetFIFOPolicy (void);
|
||||
|
||||
/** Last-in, Last-out Policy
|
||||
* This policy will create LIFO Lots. LIFO Lots have the following
|
||||
* properties:
|
||||
* -- The lot is started with the latest posted split that isn't
|
||||
* a part of another lot already.
|
||||
* -- Splits are added to the lot in date order, with latest splits
|
||||
* added first.
|
||||
* -- All splits in the lot share the same transaction currency as
|
||||
* the split that opened the lot (if book-currency book option
|
||||
* selected, this will always be book currency).
|
||||
*/
|
||||
GNCPolicy *xaccGetLIFOPolicy (void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
@ -70,22 +70,7 @@ enum
|
||||
PROP_0,
|
||||
// PROP_ROOT_ACCOUNT, /* Table */
|
||||
// PROP_ROOT_TEMPLATE, /* Table */
|
||||
/* keep trading accounts property, while adding book-currency, default gains
|
||||
policy and default gains account properties, so that files prior to 2.7 can
|
||||
be read/processed; GUI changed to use all four properties as of 2.7.
|
||||
Trading accounts, on the one hand, and book-currency plus default-gains-
|
||||
policy, and optionally, default gains account, on the other, are mutually
|
||||
exclusive */
|
||||
PROP_OPT_TRADING_ACCOUNTS, /* KVP */
|
||||
/* Book currency and default gains policy properties only apply if currency
|
||||
accounting method selected in GUI is 'book-currency'; both required and
|
||||
both are exclusive with trading accounts */
|
||||
PROP_OPT_BOOK_CURRENCY, /* KVP */
|
||||
PROP_OPT_DEFAULT_GAINS_POLICY, /* KVP */
|
||||
/* Default gains account property only applies if currency accounting method
|
||||
selected in GUI is 'book-currency'; its use is optional but exclusive with
|
||||
trading accounts */
|
||||
PROP_OPT_DEFAULT_GAINS_ACCOUNT_GUID, /* KVP */
|
||||
PROP_OPT_AUTO_READONLY_DAYS, /* KVP */
|
||||
PROP_OPT_NUM_FIELD_SOURCE, /* KVP */
|
||||
PROP_OPT_DEFAULT_BUDGET, /* KVP */
|
||||
@ -186,18 +171,6 @@ qof_book_get_property (GObject* object,
|
||||
qof_instance_get_path_kvp (QOF_INSTANCE (book), value, {str_KVP_OPTION_PATH,
|
||||
str_OPTION_SECTION_ACCOUNTS, str_OPTION_NAME_TRADING_ACCOUNTS});
|
||||
break;
|
||||
case PROP_OPT_BOOK_CURRENCY:
|
||||
qof_instance_get_path_kvp (QOF_INSTANCE (book), value, {str_KVP_OPTION_PATH,
|
||||
str_OPTION_SECTION_ACCOUNTS, OPTION_NAME_BOOK_CURRENCY});
|
||||
break;
|
||||
case PROP_OPT_DEFAULT_GAINS_POLICY:
|
||||
qof_instance_get_path_kvp (QOF_INSTANCE (book), value, {str_KVP_OPTION_PATH,
|
||||
str_OPTION_SECTION_ACCOUNTS, OPTION_NAME_DEFAULT_GAINS_POLICY});
|
||||
break;
|
||||
case PROP_OPT_DEFAULT_GAINS_ACCOUNT_GUID:
|
||||
qof_instance_get_path_kvp (QOF_INSTANCE (book), value, {str_KVP_OPTION_PATH,
|
||||
str_OPTION_SECTION_ACCOUNTS, OPTION_NAME_DEFAULT_GAINS_LOSS_ACCT_GUID});
|
||||
break;
|
||||
case PROP_OPT_AUTO_READONLY_DAYS:
|
||||
qof_instance_get_path_kvp (QOF_INSTANCE (book), value, {str_KVP_OPTION_PATH,
|
||||
str_OPTION_SECTION_ACCOUNTS, str_OPTION_NAME_AUTO_READONLY_DAYS});
|
||||
@ -241,18 +214,6 @@ qof_book_set_property (GObject *object,
|
||||
qof_instance_set_path_kvp (QOF_INSTANCE (book), value, {str_KVP_OPTION_PATH,
|
||||
str_OPTION_SECTION_ACCOUNTS, str_OPTION_NAME_TRADING_ACCOUNTS});
|
||||
break;
|
||||
case PROP_OPT_BOOK_CURRENCY:
|
||||
qof_instance_set_path_kvp (QOF_INSTANCE (book), value, {str_KVP_OPTION_PATH,
|
||||
str_OPTION_SECTION_ACCOUNTS, OPTION_NAME_BOOK_CURRENCY});
|
||||
break;
|
||||
case PROP_OPT_DEFAULT_GAINS_POLICY:
|
||||
qof_instance_set_path_kvp (QOF_INSTANCE (book), value, {str_KVP_OPTION_PATH,
|
||||
str_OPTION_SECTION_ACCOUNTS, OPTION_NAME_DEFAULT_GAINS_POLICY});
|
||||
break;
|
||||
case PROP_OPT_DEFAULT_GAINS_ACCOUNT_GUID:
|
||||
qof_instance_set_path_kvp (QOF_INSTANCE (book), value, {str_KVP_OPTION_PATH,
|
||||
str_OPTION_SECTION_ACCOUNTS, OPTION_NAME_DEFAULT_GAINS_LOSS_ACCT_GUID});
|
||||
break;
|
||||
case PROP_OPT_AUTO_READONLY_DAYS:
|
||||
qof_instance_set_path_kvp (QOF_INSTANCE (book), value, {str_KVP_OPTION_PATH,
|
||||
str_OPTION_SECTION_ACCOUNTS, str_OPTION_NAME_AUTO_READONLY_DAYS});
|
||||
@ -297,41 +258,6 @@ qof_book_class_init (QofBookClass *klass)
|
||||
NULL,
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property
|
||||
(gobject_class,
|
||||
PROP_OPT_BOOK_CURRENCY,
|
||||
g_param_spec_string("book-currency",
|
||||
"Select Book Currency",
|
||||
"The reference currency used to manage multiple-currency "
|
||||
"transactions when 'book-currency' currency accounting method "
|
||||
"selected; requires valid default gains/loss policy.",
|
||||
NULL,
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property
|
||||
(gobject_class,
|
||||
PROP_OPT_DEFAULT_GAINS_POLICY,
|
||||
g_param_spec_string("default-gains-policy",
|
||||
"Select Default Gains Policy",
|
||||
"The default policy to be used to calculate gains/losses on "
|
||||
"dispositions of currencies/commodities other than "
|
||||
"'book-currency' when 'book-currency' currency accounting "
|
||||
"method selected; requires valid book-currency.",
|
||||
NULL,
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property
|
||||
(gobject_class,
|
||||
PROP_OPT_DEFAULT_GAINS_ACCOUNT_GUID,
|
||||
g_param_spec_boxed("default-gain-loss-account-guid",
|
||||
"Select Default Gain/Loss Account",
|
||||
"The default account to be used for calculated gains/losses on "
|
||||
"dispositions of currencies/commodities other than "
|
||||
"'book-currency' when 'book-currency' currency accounting "
|
||||
"method selected; requires valid book-currency.",
|
||||
GNC_TYPE_GUID,
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property
|
||||
(gobject_class,
|
||||
PROP_OPT_NUM_FIELD_SOURCE,
|
||||
@ -982,52 +908,6 @@ qof_book_normalize_counter_format_internal(const gchar *p,
|
||||
return normalized_str;
|
||||
}
|
||||
|
||||
/** Returns pointer to book-currency name for book, if one exists in the
|
||||
* KVP, or NULL; does not validate contents nor determine if there is a valid
|
||||
* default gain/loss policy, both of which are required, for the
|
||||
* 'book-currency' currency accounting method to apply. Use instead
|
||||
* 'gnc_book_get_book_currency_name' which does these validations. */
|
||||
const gchar *
|
||||
qof_book_get_book_currency_name (QofBook *book)
|
||||
{
|
||||
const gchar *opt = NULL;
|
||||
qof_instance_get (QOF_INSTANCE (book),
|
||||
"book-currency", &opt,
|
||||
NULL);
|
||||
return opt;
|
||||
}
|
||||
|
||||
/** Returns pointer to default gain/loss policy for book, if one exists in the
|
||||
* KVP, or NULL; does not validate contents nor determine if there is a valid
|
||||
* book-currency, both of which are required, for the 'book-currency'
|
||||
* currency accounting method to apply. Use instead
|
||||
* 'gnc_book_get_default_gains_policy' which does these validations. */
|
||||
const gchar *
|
||||
qof_book_get_default_gains_policy (QofBook *book)
|
||||
{
|
||||
const gchar *opt = NULL;
|
||||
qof_instance_get (QOF_INSTANCE (book),
|
||||
"default-gains-policy", &opt,
|
||||
NULL);
|
||||
return opt;
|
||||
}
|
||||
|
||||
/** Returns pointer to default gain/loss account GUID for book, if one exists in
|
||||
* the KVP, or NULL; does not validate contents nor determine if there is a
|
||||
* valid book-currency, both of which are required, for the 'book-currency'
|
||||
* currency accounting method to apply. Use instead
|
||||
* 'gnc_book_get_default_gain_loss_acct' which does these validations. */
|
||||
GncGUID *
|
||||
qof_book_get_default_gain_loss_acct_guid (QofBook *book)
|
||||
{
|
||||
GncGUID *guid = NULL;
|
||||
qof_instance_get (QOF_INSTANCE (book),
|
||||
"default-gain-loss-account-guid", &guid,
|
||||
NULL);
|
||||
return guid;
|
||||
|
||||
}
|
||||
|
||||
/* Determine whether this book uses trading accounts */
|
||||
gboolean
|
||||
qof_book_use_trading_accounts (const QofBook *book)
|
||||
|
@ -267,27 +267,6 @@ gboolean qof_book_empty(const QofBook *book);
|
||||
/** Returns flag indicating whether this book uses trading accounts */
|
||||
gboolean qof_book_use_trading_accounts (const QofBook *book);
|
||||
|
||||
/** Returns pointer to book-currency name for book, if one exists in the
|
||||
* KVP, or NULL; does not validate contents nor determine if there is a valid
|
||||
* default gain/loss policy, both of which are required, for the
|
||||
* 'book-currency' currency accounting method to apply. Use instead
|
||||
* 'gnc_book_get_book_currency_name' which does these validations. */
|
||||
const gchar * qof_book_get_book_currency_name (QofBook *book);
|
||||
|
||||
/** Returns pointer to default gain/loss policy for book, if one exists in the
|
||||
* KVP, or NULL; does not validate contents nor determine if there is a valid
|
||||
* book-currency, both of which are required, for the 'book-currency'
|
||||
* currency accounting method to apply. Use instead
|
||||
* 'gnc_book_get_default_gains_policy' which does these validations. */
|
||||
const gchar * qof_book_get_default_gains_policy (QofBook *book);
|
||||
|
||||
/** Returns pointer to default gain/loss account GUID for book, if one exists in
|
||||
* the KVP, or NULL; does not validate contents nor determine if there is a
|
||||
* valid book-currency, both of which are required, for the 'book-currency'
|
||||
* currency accounting method to apply. Use instead
|
||||
* 'gnc_book_get_default_gain_loss_acct' which does these validations. */
|
||||
GncGUID * qof_book_get_default_gain_loss_acct_guid (QofBook *book);
|
||||
|
||||
/** Returns TRUE if the auto-read-only feature should be used, otherwise
|
||||
* FALSE. This is just a wrapper on qof_book_get_num_days_autoreadonly() == 0. */
|
||||
gboolean qof_book_uses_autoreadonly (const QofBook *book);
|
||||
|
@ -64,10 +64,6 @@
|
||||
|
||||
#define OPTION_SECTION_ACCOUNTS N_("Accounts")
|
||||
#define OPTION_NAME_TRADING_ACCOUNTS N_("Use Trading Accounts")
|
||||
#define OPTION_NAME_CURRENCY_ACCOUNTING N_("Currency Accounting")
|
||||
#define OPTION_NAME_BOOK_CURRENCY N_("Book Currency")
|
||||
#define OPTION_NAME_DEFAULT_GAINS_POLICY N_("Default Gains Policy")
|
||||
#define OPTION_NAME_DEFAULT_GAINS_LOSS_ACCT_GUID N_("Default Gain or Loss Account")
|
||||
#define OPTION_NAME_AUTO_READONLY_DAYS N_("Day Threshold for Read-Only Transactions (red line)")
|
||||
#define OPTION_NAME_NUM_FIELD_SOURCE N_("Use Split Action Field for Number")
|
||||
|
||||
@ -80,11 +76,6 @@
|
||||
* KVP-OPTION-PATH
|
||||
* OPTION-SECTION-ACCOUNTS
|
||||
* OPTION-NAME-TRADING-ACCOUNTS
|
||||
* OPTION-NAME-CURRENCY-ACCOUNTING
|
||||
* OPTION-NAME-BOOK-CURRENCY
|
||||
* OPTION_NAME_DEFAULT_GAINS_POLICY
|
||||
* OPTION_NAME_DEFAULT_GAINS_LOSS_ACCT_GUID
|
||||
* OPTION-NAME-AUTO-READONLY-DAYS
|
||||
* OPTION-NAME_NUM-FIELD-SOURCE
|
||||
* OPTION-SECTION-BUDGETING
|
||||
* OPTION-NAME-DEFAULT-BUDGET
|
||||
|
@ -453,111 +453,6 @@ test_book_use_trading_accounts( Fixture *fixture, gconstpointer pData )
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
test_book_use_book_currency( Fixture *fixture, gconstpointer pData )
|
||||
{
|
||||
const gchar *cur;
|
||||
const gchar *pol;
|
||||
GncGUID *acct;
|
||||
const GncGUID *acct2;
|
||||
|
||||
cur = qof_book_get_book_currency_name( fixture-> book );
|
||||
g_assert_cmpstr( cur, == , NULL );
|
||||
pol = qof_book_get_default_gains_policy( fixture-> book );
|
||||
g_assert_cmpstr( pol, == , NULL );
|
||||
acct2 = qof_book_get_default_gain_loss_acct_guid( fixture-> book );
|
||||
g_assert (acct2 == NULL );
|
||||
|
||||
g_test_message( "Testing with existing trading accounts set to true - t" );
|
||||
qof_book_begin_edit (fixture->book);
|
||||
qof_instance_set (QOF_INSTANCE (fixture->book),
|
||||
"trading-accts", "t",
|
||||
NULL);
|
||||
cur = qof_book_get_book_currency_name( fixture-> book );
|
||||
g_assert_cmpstr( cur, == , NULL );
|
||||
pol = qof_book_get_default_gains_policy( fixture-> book );
|
||||
g_assert_cmpstr( pol, == , NULL );
|
||||
acct2 = qof_book_get_default_gain_loss_acct_guid( fixture-> book );
|
||||
g_assert (acct2 == NULL );
|
||||
qof_book_commit_edit (fixture->book);
|
||||
|
||||
qof_book_destroy( fixture->book );
|
||||
fixture->book = qof_book_new();
|
||||
|
||||
g_test_message( "Testing with book-currency set and no default-gains-policy or account" );
|
||||
qof_book_begin_edit (fixture->book);
|
||||
qof_instance_set (QOF_INSTANCE (fixture->book),
|
||||
"book-currency", "USD",
|
||||
NULL);
|
||||
cur = qof_book_get_book_currency_name( fixture-> book );
|
||||
g_assert_cmpstr( cur, == , "USD" );
|
||||
pol = qof_book_get_default_gains_policy( fixture-> book );
|
||||
g_assert_cmpstr( pol, == , NULL );
|
||||
acct2 = qof_book_get_default_gain_loss_acct_guid( fixture-> book );
|
||||
g_assert (acct2 == NULL );
|
||||
qof_book_commit_edit (fixture->book);
|
||||
|
||||
qof_book_destroy( fixture->book );
|
||||
fixture->book = qof_book_new();
|
||||
|
||||
g_test_message( "Testing with default-gains-policy set and no book-currency" );
|
||||
qof_book_begin_edit (fixture->book);
|
||||
qof_instance_set (QOF_INSTANCE (fixture->book),
|
||||
"default-gains-policy", "fifo",
|
||||
NULL);
|
||||
cur = qof_book_get_book_currency_name( fixture-> book );
|
||||
g_assert_cmpstr( cur, == , NULL );
|
||||
pol = qof_book_get_default_gains_policy( fixture-> book );
|
||||
g_assert_cmpstr( pol, == , "fifo" );
|
||||
acct2 = qof_book_get_default_gain_loss_acct_guid( fixture-> book );
|
||||
g_assert (acct2 == NULL );
|
||||
qof_book_commit_edit (fixture->book);
|
||||
|
||||
qof_book_destroy( fixture->book );
|
||||
fixture->book = qof_book_new();
|
||||
|
||||
g_test_message( "Testing with book-currency and default-gains-policy set to nonsense" );
|
||||
qof_book_begin_edit (fixture->book);
|
||||
qof_instance_set (QOF_INSTANCE (fixture->book),
|
||||
"book-currency", "myMoney",
|
||||
NULL);
|
||||
qof_instance_set (QOF_INSTANCE (fixture->book),
|
||||
"default-gains-policy", "random",
|
||||
NULL);
|
||||
cur = qof_book_get_book_currency_name( fixture-> book );
|
||||
g_assert_cmpstr( cur, == , "myMoney" );
|
||||
pol = qof_book_get_default_gains_policy( fixture-> book );
|
||||
g_assert_cmpstr( pol, == , "random" );
|
||||
acct2 = qof_book_get_default_gain_loss_acct_guid( fixture-> book );
|
||||
g_assert (acct2 == NULL );
|
||||
qof_book_commit_edit (fixture->book);
|
||||
|
||||
qof_book_destroy( fixture->book );
|
||||
fixture->book = qof_book_new();
|
||||
|
||||
g_test_message( "Testing with book-currency, default-gains-policy and default-gains-account set to valid values" );
|
||||
qof_book_begin_edit (fixture->book);
|
||||
qof_instance_set (QOF_INSTANCE (fixture->book),
|
||||
"book-currency", "USD",
|
||||
NULL);
|
||||
qof_instance_set (QOF_INSTANCE (fixture->book),
|
||||
"default-gains-policy", "fifo",
|
||||
NULL);
|
||||
acct = guid_new();
|
||||
qof_instance_set (QOF_INSTANCE (fixture->book),
|
||||
"default-gain-loss-account-guid", acct,
|
||||
NULL);
|
||||
cur = qof_book_get_book_currency_name( fixture-> book );
|
||||
g_assert_cmpstr( cur, == , "USD" );
|
||||
pol = qof_book_get_default_gains_policy( fixture-> book );
|
||||
g_assert_cmpstr( pol, == , "fifo" );
|
||||
acct2 = qof_book_get_default_gain_loss_acct_guid( fixture-> book );
|
||||
g_assert_cmpstr( guid_to_string (acct), == , guid_to_string (acct2) );
|
||||
g_assert (guid_equal(acct, acct2));
|
||||
guid_free (acct);
|
||||
qof_book_commit_edit (fixture->book);
|
||||
}
|
||||
|
||||
static void
|
||||
test_book_get_num_days_autofreeze( Fixture *fixture, gconstpointer pData )
|
||||
{
|
||||
@ -931,7 +826,6 @@ test_suite_qofbook ( void )
|
||||
GNC_TEST_ADD( suitename, "get counter format", Fixture, NULL, setup, test_book_get_counter_format, teardown );
|
||||
GNC_TEST_ADD( suitename, "increment and format counter", Fixture, NULL, setup, test_book_increment_and_format_counter, teardown );
|
||||
GNC_TEST_ADD( suitename, "use trading accounts", Fixture, NULL, setup, test_book_use_trading_accounts, teardown );
|
||||
GNC_TEST_ADD( suitename, "use book-currency", Fixture, NULL, setup, test_book_use_book_currency, teardown );
|
||||
GNC_TEST_ADD( suitename, "get autofreeze days", Fixture, NULL, setup, test_book_get_num_days_autofreeze, teardown );
|
||||
GNC_TEST_ADD( suitename, "use split action for num field", Fixture, NULL, setup, test_book_use_split_action_for_num_field, teardown );
|
||||
GNC_TEST_ADD( suitename, "mark session dirty", Fixture, NULL, setup, test_book_mark_session_dirty, teardown );
|
||||
|
Loading…
Reference in New Issue
Block a user