Book-Currency Feature step 6

Modify File->Properties dialog to maintain a default gain/loss account in a book KVP.

The changes made are:

	app-utils/app-utils.scm - define items related to book default gain/loss
        acct
	app-utils/business-prefs.scm - define items related to book default
        gain/loss acct;re-arrange sequence of options to make default (neither)
        first
    app-utils/gnc-ui-util.c - refine gnc_book_get_default_gains_policy to check
        for hidden and/or placeholder status
	app-utils/option-util.c & h - define items related to book default gain/loss
        acct
	app-utils/options.scm - add functionality related to book default gain/loss
        acct
    app-utils/test/test-gnc-ui-util.c - for gnc_book_get_default_gains_policy,
        add tests to check for hidden and/or placeholder status
	app-utils/test/test-option-util.cpp - add tests related to book default
        gain/loss acct
	engine/engine.i - define item related to book default gain/loss acct
	gnome-utils/dialog-options.c & h - add functionality related to book default
        gain/loss acct and rearrange dialog layout; make gain/loss acct widget
        refresh on account maintenance
    gnome-utils/gnc-main-window.c - only allow one book-option dialog if called
        from file->properties
	gnome-utils/gtkbuilder/dialog-options.glade - increase dialog height to
        accomodate book default gain/loss acct widget; add tooltip text for
        dialog buttons
    gnome/assistant-hierarchy.c - change sequence of pages: book options before
        currency selection; if book currency selected, currency also selected
    gnome/gtkbuilder/assistant-hierarchy.glade - increase dialog height to
        accomodate book default gain/loss acct widget
This commit is contained in:
Alex Aycinena
2017-07-09 12:19:36 -07:00
parent a7f1f9cdd7
commit 2020bee03b
15 changed files with 1207 additions and 385 deletions

View File

@@ -123,9 +123,11 @@
(export gnc:currency-accounting-option-get-default-curr)
(export gnc:currency-accounting-option-get-policy-doc-string)
(export gnc:currency-accounting-option-get-default-policy)
(export gnc:currency-accounting-option-get-gain-loss-account-doc-string)
(export gnc:currency-accounting-option-selected-method)
(export gnc:currency-accounting-option-selected-currency)
(export gnc:currency-accounting-option-selected-policy)
(export gnc:currency-accounting-option-selected-gain-loss-account)
(export gnc:color->html)
(export gnc:color-option->html)
@@ -350,12 +352,14 @@
(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-name-auto-readonly-days* OPTION-NAME-AUTO-READONLY-DAYS)
(define gnc:*option-name-num-field-source* OPTION-NAME-NUM-FIELD-SOURCE)
(export gnc:*option-section-accounts* gnc:*option-name-trading-accounts*
gnc:*option-name-currency-accounting*
gnc:*option-name-book-currency* gnc:*option-name-default-gains-policy*
gnc:*option-name-currency-accounting* gnc:*option-name-book-currency*
gnc:*option-name-default-gains-policy*
gnc:*option-name-default-gain-loss-account*
gnc:*option-name-auto-readonly-days* gnc:*option-name-num-field-source*)
(define gnc:*option-section-budgeting* OPTION-SECTION-BUDGETING)

View File

@@ -151,19 +151,21 @@
(N_ "Select the currency accounting method to use for transactions involving more than one currency or commodity.")
'neither
(list
(vector 'neither
(N_ "Use neither Trading Accounts nor a Book Currency")
(N_ "Check to use neither trading accounts nor a book-currency for transactions involving more than one currency or commodity."))
(vector 'trading
(N_ "Use Trading Accounts")
(N_ "Check to have trading accounts used for transactions involving more than one currency or commodity."))
(vector 'book-currency
(N_ "Use a Book-Currency")
(N_ "Check to use a book-currency for transactions involving more than one currency or commodity."))
(vector 'neither
(N_ "Use neither Trading Accounts nor a Book-Currency")
(N_ "Check to use neither trading accounts nor a book-currency for transactions involving more than one currency or commodity.")))
(N_ "Use a Book Currency")
(N_ "Check to use a book-currency for transactions involving more than one currency or commodity.")))
(N_ "Select the book-currency which is to be used to track costs of transactions involving currencies or commodities other than the book-currency.")
(gnc-default-currency)
(N_ "Select the default gains policy; this policy will be used unless over-ridden at the account level.")
'fifo))
'fifo
(N_ "Select the default gains/loss account (income or expense account, in book-currency, neither placeholder nor hidden); this account will be used unless over-ridden at the account level. If one is not selected, an account will be created as needed."))
)
;; Budgeting Tab

View File

@@ -368,7 +368,8 @@ 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. */
* 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)
{
@@ -380,7 +381,20 @@ gnc_book_get_default_gain_loss_acct (QofBook *book)
gains_account = xaccAccountLookup
(qof_book_get_default_gain_loss_acct_guid (book), book);
return gains_account;
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 *

View File

@@ -114,9 +114,11 @@ struct _Getters
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;
};
@@ -608,12 +610,16 @@ initialize_getters(void)
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;
}
@@ -2788,6 +2794,26 @@ gnc_currency_accounting_option_get_default_policy(GNCOption *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 *
@@ -2837,6 +2863,25 @@ gnc_currency_accounting_option_value_get_default_policy (SCM option_value)
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);
}
/*******************************************************************\
* gnc_option_db_set_option_selectable_by_name *
* set the sensitivity of the option widget *

View File

@@ -258,9 +258,11 @@ 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,

View File

@@ -1401,6 +1401,7 @@
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)
@@ -1433,6 +1434,38 @@
(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)))
(hidden? (if account
(xaccAccountIsHidden account)
#t))
(placeholder? (if account
(xaccAccountGetPlaceholder account)
#t))
(account-type (if account
(xaccAccountGetType account)
#f))
(income-or-expense? (if (and account account-type)
(or (= ACCT-TYPE-INCOME account-type)
(= ACCT-TYPE-EXPENSE account-type))
#f))
(commodity-eq-book-curr? (if account
(gnc-commodity-equal
(currency-lookup book-currency)
(xaccAccountGetCommodity account))
#f))
)
(if (and account
(not hidden?)
(not placeholder?)
income-or-expense?
commodity-eq-book-curr?)
#t
#f)))
(let* ((value (if (eq? 'book-currency default-radiobutton-value)
(cons default-radiobutton-value
(cons default-book-currency-value
@@ -1446,22 +1479,25 @@
(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*)))
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)
(lambda () value) ;; getter
(lambda (x)
(if (legal-val (car x) ok-radiobutton-values)
(set! value x)
(gnc:error "Illegal Radiobutton option set")))
(gnc:error "Illegal Radiobutton option set"))) ;;setter
(lambda () (if (eq? 'book-currency default-radiobutton-value)
(cons default-radiobutton-value
(cons default-book-currency-value
(cons default-cap-gains-policy-value '())))
(cons default-radiobutton-value '())))
(cons default-cap-gains-policy-value
(cons '() '()))))
(cons default-radiobutton-value '()))) ;; default-getter
(gnc:restore-form-generator value->string)
(lambda (b p)
(lambda (b p) ;; scm->kvp
(if (eq? 'book-currency (car value))
(begin
;; Currency = selected currency
@@ -1473,11 +1509,17 @@
(qof-book-set-option
b
(symbol->string (caddr value))
gains-policy-path))
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)))
(if (eq? 'trading (car value))
;; Use Trading Accounts = "t"
(qof-book-set-option b "t" trading-accounts-path))))
(lambda (b p)
(lambda (b p) ;; kvp->scm
(let* ((trading-option-path-kvp?
(qof-book-get-option
b trading-accounts-path))
@@ -1487,6 +1529,7 @@
#f))
(book-currency #f)
(cap-gains-policy #f)
(gains-loss-account-guid #f)
(v (if trading?
'trading
(let* ((book-currency-option-path-kvp?
@@ -1495,6 +1538,9 @@
(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?
@@ -1513,24 +1559,37 @@
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)))
#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))
'())))
(set! value (cons 'neither '())))))
(lambda (x)
(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 (cons 'neither '())))))
(lambda (x) ;; value validator
(if (list? x)
(if (legal-val (car x) ok-radiobutton-values)
(if (eq? 'book-currency (car x))
(if (currency? (currency->scm (cadr x)))
(if (gnc-valid-policy-name (symbol->string (caddr x)))
(list #t x)
(if (car(cdddr x))
(if (valid-gains-loss-account?
(currency->scm (cadr x))
(car(cdddr x)))
(list #t x)
(list #f "gains-loss-account-option: illegal value"))
(list #t x)) ;; must be valid if specified, otherwise OK
(list #f "cap-gains-policy-option: illegal value"))
(list #f "currency-option: illegal value"))
(list #t x))
@@ -1539,7 +1598,8 @@
(vector book-currency-documentation-string
default-book-currency-value
default-cap-gains-policy-documentation-string
default-cap-gains-policy-value)
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))
@@ -1561,6 +1621,9 @@
(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
@@ -1585,6 +1648,12 @@
(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))
@@ -1598,6 +1667,11 @@
(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))
@@ -1731,11 +1805,11 @@
(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)
;; (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)
;; (gnc:debug "save-fcn: " save-fcn)
(if save-fcn
(save-fcn book (list section name)))))))))

View File

@@ -65,6 +65,8 @@ test_book_use_book_currency( Fixture *fixture, gconstpointer pData )
const gchar *cur;
const gchar *pol;
Account *acct, *acc;
gnc_commodity *com = gnc_commodity_new(fixture-> book, NULL, NULL, "USD",
NULL, NULL);
g_test_message( "Testing with no currency accounting method selected" );
cur = gnc_book_get_book_currency_name( fixture-> book );
@@ -233,7 +235,7 @@ test_book_use_book_currency( Fixture *fixture, gconstpointer pData )
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" );
g_test_message( "Testing with book-currency and default-gains-policy set to valid values but default-gain-loss-account-guid set to valid but placeholder account and no trading accounts flag" );
qof_book_begin_edit (fixture->book);
qof_instance_set (QOF_INSTANCE (fixture->book),
"book-currency", "USD",
@@ -242,6 +244,132 @@ test_book_use_book_currency( Fixture *fixture, gconstpointer pData )
"default-gains-policy", "fifo",
NULL);
acc = get_random_account( fixture-> book );
xaccAccountBeginEdit (acc);
xaccAccountSetType (acc, ACCT_TYPE_INCOME);
xaccAccountSetCommodity (acc, com);
xaccAccountSetPlaceholder (acc, TRUE);
xaccAccountSetHidden (acc, FALSE);
xaccAccountCommitEdit (acc);
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 (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 valid values but default-gain-loss-account-guid set to valid but hidden account 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);
acc = get_random_account( fixture-> book );
xaccAccountBeginEdit (acc);
xaccAccountSetType (acc, ACCT_TYPE_INCOME);
xaccAccountSetCommodity (acc, com);
xaccAccountSetPlaceholder (acc, FALSE);
xaccAccountSetHidden (acc, TRUE);
xaccAccountCommitEdit (acc);
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 (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 valid values but default-gain-loss-account-guid set to valid but asset account 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);
acc = get_random_account( fixture-> book );
xaccAccountBeginEdit (acc);
xaccAccountSetType (acc, ACCT_TYPE_ASSET);
xaccAccountSetCommodity (acc, com);
xaccAccountSetPlaceholder (acc, FALSE);
xaccAccountSetHidden (acc, FALSE);
xaccAccountCommitEdit (acc);
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 (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 valid values but default-gain-loss-account-guid set to valid but not book-currency account and no trading accounts flag" );
qof_book_begin_edit (fixture->book);
qof_instance_set (QOF_INSTANCE (fixture->book),
"book-currency", "GBP",
NULL);
qof_instance_set (QOF_INSTANCE (fixture->book),
"default-gains-policy", "fifo",
NULL);
acc = get_random_account( fixture-> book );
xaccAccountBeginEdit (acc);
xaccAccountSetType (acc, ACCT_TYPE_ASSET);
xaccAccountSetCommodity (acc, com);
xaccAccountSetPlaceholder (acc, FALSE);
xaccAccountSetHidden (acc, FALSE);
xaccAccountCommitEdit (acc);
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, == , "GBP" );
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 (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);
acc = get_random_account( fixture-> book );
xaccAccountBeginEdit (acc);
xaccAccountSetType (acc, ACCT_TYPE_INCOME);
xaccAccountSetCommodity (acc, com);
xaccAccountSetPlaceholder (acc, FALSE);
xaccAccountSetHidden (acc, FALSE);
xaccAccountCommitEdit (acc);
qof_instance_set (QOF_INSTANCE (fixture->book),
"default-gain-loss-account-guid", qof_entity_get_guid(QOF_INSTANCE(acc)),
NULL);

View File

@@ -29,6 +29,7 @@ extern "C"
#include <glib.h>
#include <unittest-support.h>
#include <qofbookslots.h>
#include "test-engine-stuff.h"
#include "../option-util.h"
}
@@ -136,9 +137,18 @@ test_option_load_book_currency (Fixture *fixture, gconstpointer pData)
SCM symbol_value;
const gchar *curr = NULL;
SCM curr_scm;
SCM acct_guid_scm = NULL;
gnc_commodity *commodity;
QofBook *book = fixture->book;
GNCOptionDB *odb = gnc_option_db_new_for_type (QOF_ID_BOOK);
Account *acct, *acc;
qof_book_begin_edit (book);
acc = get_random_account( book );
qof_instance_set (QOF_INSTANCE (book),
"default-gain-loss-account-guid", qof_entity_get_guid(QOF_INSTANCE(acc)),
NULL);
qof_book_commit_edit (book);
qof_book_load_options (book, gnc_option_db_load, odb);
symbol_value = gnc_currency_accounting_option_value_get_method (
@@ -155,6 +165,24 @@ test_option_load_book_currency (Fixture *fixture, gconstpointer pData)
}
}
g_assert_cmpstr (str, ==, "book-currency");
if (str)
g_free (str);
acct_guid_scm = gnc_currency_accounting_option_value_get_default_account (
gnc_option_db_lookup_option (odb,
OPTION_SECTION_ACCOUNTS,
OPTION_NAME_CURRENCY_ACCOUNTING,
SCM_BOOL_F));
if (acct_guid_scm && (scm_is_string(acct_guid_scm)))
{
GncGUID *guid = g_new (GncGUID, 1);
str = scm_to_utf8_string (acct_guid_scm);
if (string_to_guid (str, guid))
acct = xaccAccountLookup( guid, book );
g_free (guid);
}
g_assert ( xaccAccountEqual(acct, acc, TRUE) );
if (str)
g_free (str);
symbol_value = gnc_currency_accounting_option_value_get_default_policy (
@@ -221,15 +249,31 @@ test_option_save_book_currency (Fixture *fixture, gconstpointer pData)
QofBook *book = fixture->book;
GNCOptionDB *odb = gnc_option_db_new_for_type (QOF_ID_BOOK);
KvpFrame *slots = qof_instance_get_slots (QOF_INSTANCE (book));
Account *acct, *acc;
gchar *gain_loss_account_guid_str, *gain_loss_account_guid_str2;
GncGUID *gain_loss_account_guid;
SCM val;
acc = get_random_account( book );
gain_loss_account_guid_str = guid_to_string (xaccAccountGetGUID (acc));
val = scm_from_utf8_string (gain_loss_account_guid_str);
g_assert (gnc_option_db_set_option (odb, OPTION_SECTION_ACCOUNTS,
OPTION_NAME_CURRENCY_ACCOUNTING,
scm_cons (scm_from_locale_symbol("book-currency"),
scm_cons (scm_from_utf8_string("GTQ"),
scm_cons (scm_from_locale_symbol("fifo"), SCM_EOL)))));
scm_cons (scm_from_locale_symbol("fifo"),
scm_cons (val, SCM_EOL))))));
qof_book_save_options (book, gnc_option_db_save, odb, TRUE);
g_assert_cmpstr (slots->get_slot("options/Accounts/Book Currency")->get<const char*>(), == , "GTQ");
g_assert_cmpstr (slots->get_slot("options/Accounts/Default Gains Policy")->get<const char*>(), == , "fifo");
gain_loss_account_guid =
slots->get_slot("options/Accounts/Default Gain or Loss Account")->get<GncGUID*>();
gain_loss_account_guid_str2 = guid_to_string (gain_loss_account_guid);
g_assert_cmpstr (gain_loss_account_guid_str2, == , gain_loss_account_guid_str);
if (gain_loss_account_guid_str)
g_free (gain_loss_account_guid_str);
if (gain_loss_account_guid_str2)
g_free (gain_loss_account_guid_str2);
gnc_option_db_destroy (odb);
}

View File

@@ -368,6 +368,7 @@ void qof_book_set_string_option(QofBook* book, const char* opt_name, const char*
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");

File diff suppressed because it is too large Load Diff

View File

@@ -35,7 +35,8 @@ typedef struct gnc_option_win GNCOptionWin;
typedef void (* GNCOptionWinCallback)(GNCOptionWin *, gpointer data);
GNCOptionWin * gnc_options_dialog_new_modal(gboolean modal, gchar *title);
GNCOptionWin * gnc_options_dialog_new_modal(gboolean modal, gchar *title,
const char *component_class);
GNCOptionWin * gnc_options_dialog_new(gchar *title);
GNCOptionWin * gnc_options_dialog_new_w_dialog(gchar *title, GtkWidget *dialog);
void gnc_options_dialog_destroy(GNCOptionWin * win);

View File

@@ -106,6 +106,7 @@ enum
#define GNC_MAIN_WINDOW_NAME "GncMainWindow"
#define DIALOG_BOOK_OPTIONS_CM_CLASS "dialog-book-options"
/* Static Globals *******************************************************/
@@ -4030,6 +4031,17 @@ gnc_book_options_dialog_close_cb(GNCOptionWin * optionwin,
gnc_option_db_destroy(options);
}
static gboolean
show_handler (const char *class_name, gint component_id,
gpointer user_data, gpointer iter_data)
{
GtkWidget *dialog;
dialog = GTK_WIDGET(user_data);
gtk_window_present(GTK_WINDOW(dialog));
return(TRUE);
}
GtkWidget *
gnc_book_options_dialog_cb (gboolean modal, gchar *title)
{
@@ -4041,8 +4053,16 @@ gnc_book_options_dialog_cb (gboolean modal, gchar *title)
qof_book_load_options (book, gnc_option_db_load, options);
gnc_option_db_clean (options);
/* Only allow one Book Options dialog if called from file->properties
menu */
if (gnc_forall_gui_components(DIALOG_BOOK_OPTIONS_CM_CLASS,
show_handler, NULL))
{
return NULL;
}
optionwin = gnc_options_dialog_new_modal (modal,
(title ? title : _( "Book Options")));
(title ? title : _( "Book Options")),
DIALOG_BOOK_OPTIONS_CM_CLASS);
gnc_options_dialog_build_contents (optionwin, options);
gnc_options_dialog_set_book_options_help_cb (optionwin);

View File

@@ -6,7 +6,7 @@
<property name="can_focus">False</property>
<property name="title" translatable="yes">GnuCash Options</property>
<property name="default_width">400</property>
<property name="default_height">400</property>
<property name="default_height">625</property>
<property name="type_hint">dialog</property>
<signal name="response" handler="gnc_options_dialog_response_cb" swapped="no"/>
<child internal-child="vbox">
@@ -41,6 +41,7 @@
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Close dialog and make no changes.</property>
<property name="use_underline">True</property>
</object>
<packing>
@@ -56,6 +57,7 @@
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Apply changes but do not close dialog.</property>
<property name="use_underline">True</property>
</object>
<packing>
@@ -71,6 +73,7 @@
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Apply changes and close dialog.</property>
<property name="use_underline">True</property>
</object>
<packing>

View File

@@ -68,6 +68,7 @@ static QofLogModule log_module = GNC_MOD_IMPORT;
#define GNC_PREFS_GROUP "dialogs.new-hierarchy"
#define GNC_PREF_SHOW_ON_NEW_FILE "show-on-new-file"
#define DIALOG_BOOK_OPTIONS_CM_CLASS "dialog-book-options"
typedef enum
{
@@ -87,6 +88,7 @@ typedef struct
gboolean next_ok;
GtkWidget *currency_selector;
GtkWidget *currency_selector_label;
GtkTreeView *categories_tree;
GtkTreeRowReference *initial_category;
@@ -124,6 +126,7 @@ void select_all_clicked (GtkButton *button,
void clear_all_clicked (GtkButton *button,
hierarchy_data *data);
void on_final_account_prepare (hierarchy_data *data);
void on_select_currency_prepare (hierarchy_data *data);
void on_cancel (GtkAssistant *gtkassistant, hierarchy_data *data);
void on_finish (GtkAssistant *gtkassistant, hierarchy_data *data);
@@ -487,12 +490,16 @@ account_categories_tree_view_prepare (hierarchy_data *data)
void on_prepare (GtkAssistant *assistant, GtkWidget *page,
hierarchy_data *data)
{
const int currency_page = data->new_book ? 2 : 1;
const int selection_page = data->new_book ? 3 : 2;
const int final_page = data->new_book ? 4 : 3;
const int current_page = gtk_assistant_get_current_page (assistant);
if (current_page == currency_page)
on_select_currency_prepare (data);
if (current_page == selection_page)
on_choose_account_categories_prepare(data);
on_choose_account_categories_prepare (data);
if (current_page == final_page)
on_final_account_prepare (data);
@@ -1074,14 +1081,8 @@ on_finish (GtkAssistant *gtkassistant,
gnc_account_foreach_descendant (data->our_account_tree,
(AccountCb)starting_balance_helper,
data);
}
/* Set book options based on the user's choices */
if (data->new_book)
gnc_book_options_dialog_apply_helper(data->options);
// delete before we suspend GUI events, and then muck with the model,
// because the model doesn't seem to handle this correctly.
if (data->initial_category)
@@ -1112,6 +1113,39 @@ on_finish (GtkAssistant *gtkassistant,
LEAVE (" ");
}
/* If a book currency is selected in prior page, set the currency_selector to
* the book currency, make insensitive and modify text. Otherwise, restore the
* selector to original condition
*/
void
on_select_currency_prepare (hierarchy_data *data)
{
/* Set book options based on the user's choices */
if (data->new_book)
{
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);
}
}
}
/********************************************************
* For a new book the assistant will also allow the user
* to set default book options, because this impacts how
@@ -1139,7 +1173,7 @@ book_options_dialog_close_cb(GNCOptionWin * optionwin,
}
static void
assistant_instert_book_options_page (hierarchy_data *data)
assistant_insert_book_options_page (hierarchy_data *data)
{
GtkWidget *options, *parent;
GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
@@ -1150,7 +1184,8 @@ assistant_instert_book_options_page (hierarchy_data *data)
gnc_option_db_load, data->options);
gnc_option_db_clean (data->options);
data->optionwin = gnc_options_dialog_new_modal (TRUE, _("New Book Options"));
data->optionwin = gnc_options_dialog_new_modal (TRUE, _("New Book Options"),
DIALOG_BOOK_OPTIONS_CM_CLASS);
gnc_options_dialog_build_contents_full (data->optionwin, data->options, FALSE);
gnc_options_dialog_set_close_cb (data->optionwin,
@@ -1171,7 +1206,7 @@ assistant_instert_book_options_page (hierarchy_data *data)
#endif
gtk_widget_show_all (vbox);
gtk_assistant_insert_page (GTK_ASSISTANT(data->dialog), vbox, 2);
gtk_assistant_insert_page (GTK_ASSISTANT(data->dialog), vbox, 1);
gtk_assistant_set_page_title (GTK_ASSISTANT(data->dialog), vbox, _("New Book Options"));
gtk_assistant_set_page_complete (GTK_ASSISTANT(data->dialog), vbox, TRUE);
@@ -1224,9 +1259,12 @@ gnc_create_hierarchy_assistant (gboolean use_defaults, GncHierarchyAssistantFini
/* Currency Page */
data->currency_selector = gnc_currency_edit_new();
gnc_currency_edit_set_currency (GNC_CURRENCY_EDIT(data->currency_selector), gnc_default_currency());
gnc_currency_edit_set_currency (GNC_CURRENCY_EDIT(data->currency_selector),
gnc_default_currency());
gtk_widget_show (data->currency_selector);
box = GTK_WIDGET(gtk_builder_get_object (builder, "currency_chooser_hbox"));
data->currency_selector_label = GTK_WIDGET(gtk_builder_get_object (builder,
"choose_currency_label"));
gtk_box_pack_start(GTK_BOX(box), data->currency_selector, TRUE, TRUE, 0);
/* Categories Page */
@@ -1243,7 +1281,7 @@ gnc_create_hierarchy_assistant (gboolean use_defaults, GncHierarchyAssistantFini
/* Book options page - only on new books */
if (data->new_book)
assistant_instert_book_options_page (data);
assistant_insert_book_options_page (data);
/* Final Accounts Page */
data->final_account_tree_container = GTK_WIDGET(gtk_builder_get_object (builder, "final_account_tree_box"));

View File

@@ -6,7 +6,7 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">12</property>
<property name="default_height">550</property>
<property name="default_height">800</property>
<signal name="cancel" handler="on_cancel" swapped="no"/>
<signal name="close" handler="on_finish" swapped="no"/>
<signal name="prepare" handler="on_prepare" swapped="no"/>