Eliminates direct KVP access in app-utils, all of which centered around
options.
Beneficial side effect: With all option writes now handled by
qof_book_set_option(), the problem of options not being committed is
eliminated.
The options system is unnecessarily complex, with much back-and-forth
between C and Guile. It needs to be completely rewritten, but that's a
project for its own branch.
Add an option to the File->Properties dialog to select a Currency Accounting Method, and to specify the book-currency and a default gains/loss policy if the 'book-currency' method is selected.
Revert some changes made in prior commits. Other than storing and retrieving the
book-currency and policy in book KVPs, the behavior of gnucash has not been
affected by these changes. The changes made are:
engine/policy.c & .h - define valid policies and their descriptions
and hints; define functions gnc_get_valid_policy_list and
gnc_valid_policy
engine/engine.i - include policy.h; define 'CURRENCY-ACCOUNTING',
'BOOK-CURRENCY', and 'DEFAULT-GAINS-POLICY' as option names
engine/test/utest-Split.cpp - revert prior commit that modified test
function for trading accounts
engine/test/utest-Transaction.c - revert prior commit that modified test
function for trading accounts
libqof/qof/qofbookslots.h - revert prior commit that defined Currency
Accounting Method; modify definitions of Currency Accounting and Book
Currency; add definition of default gains policy; keep the previous
Trading Accounts definition
libqof/qof/qofbook.cpp & .h - reverted function to determine currency
accounting method; add function to get book-currency, revert
previously committed changes to function to determine if book uses
trading accounts; add function to get gains policy; modify gobject
properties accordingly
libqof/qof/test/test-qofbook.c - revert prior modification to test
function for trading accounts; define tests for book-currency and
default gains policies
app-utils/options.scm - define make-currency-accounting-option and
required support functions
app-utils/options-util.c & .h - make support functions of
make-currency-accounting-option available in c code
app-utils/test/test-options-util.c - include tests for using book-currency
app-utils/gnc-ui-util.c & .h - define gnc_book_use_book_currency,
gnc_book_get_book_currency and gnc_book_get_default_gains_policy
functions
app-utils/test/test-gnc-ui-util.c - set up tests for new gnc-ui-util
functions
app-utils/test/test-app-utils.c - include test-gnc-ui-util.c
app-utils/test/Makefile.am - include test-gnc-ui-util.c
app-utils/app-utils.scm - define and export book options for Currency
Accounting, Book-Currency and Default Gains Policy; export required
currency-accounting-option support functions
app-utils/business-prefs.scm - replace the Trading Accounts boolean option
with a currency-accounting-option and rearrange the order of the
options
gnome-utils/dialog-options.c - define functions for set-ui-widget,
set-ui-value, and get-ui-value for 'currency-accounting' option and
various other support functions
Store the book-currency in the book KVP. The changes made are:
libqof/qof/qofbookslots.h - define a Book Currency option in addition to
the Currency Accounting Method option previously defined
libqof/qof/qofbook.cpp & .h - define function to get book-currency and add
gobject properties accordingly
libqof/qof/test/test-qofbook.c - add to test function for book-currency
accounting method to also test for a specified book-currency
The changes made are:
libqof/qof/qofbookslots.h - define Currency Accounting Method option; keep
the current Trading Accounts option (in order to read prior files)
libqof/qof/qofbook.cpp & .h - define function to determine if book uses
book-currency, modify function to determine if book uses trading
accounts and add gobject properties accordingly
libqof/qof/test/test-qofbook.c - define test function to determine if book
uses book-currency and modify test function for trading accounts
engine/test/utest-Split.cpp - modify test function for trading accounts
to use new "currency-accounting" and "trading" book properties
engine/test/utest-Transaction.c - modify test function for trading accounts
to use new "currency-accounting" and "trading" book properties
This was done by branching right before the original merge
and redoing a clean merge of the private-kvp branch again.
This result was then cherry-picked onto master with
git cherry-pick <merge-commit> -m 1
It was done like this because git merge would consider
the private-kvp branch already merged even after a revert
(see git-revert man page) and won't allow to merge a
second time on the same branch.
Resolved conflicts:
README.dependencies
src/app-utils/gnc-sx-instance-model.c
src/engine/cap-gains.c
src/engine/test/Makefile.am
src/gnome/assistant-hierarchy.c
src/import-export/import-match-map.c
src/import-export/import-utilities.c
src/import-export/ofx/gnc-ofx-kvp.c
src/libqof/qof/qofbook.cpp
src/libqof/qof/qofinstance-p.h
src/libqof/qof/qofinstance.cpp
src/libqof/qof/test/test-kvp_frame.c
src/report/report-gnome/gnc-plugin-page-report.c
Makes all kvp operations private to the object of which the kvp is
a member. Access from outside of the object is accomplished via
GObject Properties. A convenience function, qof_instance_set(),
is provided that wraps g_object_set and marks dirty the instance
so that it will be saved. It is still necessary to wrap calls in
begin_edit/commit to accomplish the save to the SQL backend. A
like-named wrapper, qof_instance_get() is provided to balance the API.
Note that the XML backend retains direct access to KVP to avoid having
to catalog the properties.
This is a minimal change to get LibQOF and only LibQOF to compile as C++.
There are no functional changes, just casts to satisfy the rather pickier
C++ compiler and wrapping declarations with extern "C" { } to maintain C
mangling so that the libgncmod_qof will work with the rest of the program.
A note about renaming gnc-numeric.c to gnc-numeric.cpp: Dunno if it's a
clang bug, but it wouldn't link test-math with the -xc++ flag; renaming
the one file got around the problem. We'll likely have to do the same for
other test programs and for gnucash-bin.c.
Turn gnc_option_db_save_to_kvp and …load_from_kvp into callbacks passed to qof_book_(save|load)_options to avoid adding a dependency between qofbook and option-utils.
The changes made are:
1. Implement the new book option to select source for 'num' cell:
libqof/qof/qofbookslots.h - define num source option
engine/engine.i - define 'NUM-FIELD-SOURCE' as an option name and
'SPLIT-ACTION' as a term for sorting queries
app-utils/business-prefs.scm - define book option for num-field-source
app-utils/app-utils.scm - define and export book option for num-field-source
2. Implement functions to get book option setting and to test:
libqof/qof/qofbook.c & .h - define function to get number source book option
libqof/qof/test/test-qofbook.c - test function to get number source book option
3. Implement a notification mechanism for book option changes:
engine/engine-helpers.c & .h - define functions to register callbacks,
define function to remove callbacks and
define function to initiate callbacks on book num-source option changes
core-utils/gnc-features.c & .h - define feature for num-source
app-utils/gnc-ui-util.c & .h - define gnc_book_option_num_field_source_change_cb;
include setting of feature flag on initial use
gnome-utils/gnc-main-window.c - change name of gnc_options_dialog_apply_cb
function to gnc_book_options_dialog_apply_cb and adjust function to
call function gnc_book_option_num_field_source_change_cb when book
option for num-field-source changes; change name of
gnc_options_dialog_close_cb to gnc_book_options_dialog_close_cb
4. Implement 'help' button response on Book Option Dialog:
gnome-utils/gnc-ui.h - define "book-options" section of help manual
gnome-utils/gnc-gnome-utils.c & .h - implement Book Options help callback
gnome-utils/gnc-main-window.c - use gnc_options_dialog_set_book_options_help_cb
to make help button active
5. Implement utility functions to get/set number/action based on book option:
engine/engine-helpers.c & .h - define 'gnc_get_num_action' function
define 'gnc_get_action_num' function
define 'gnc_set_num_action' function
engine/engine.i - make get/set num/action functions available to guile &
allow #f to be used in place of NULL from guile
engine/Transaction.h - add reference to utility functions in comments to
xaccTransSetNum and xaccTransGetNum functions
engine/Split.h - add reference to utility functions in comments to
xaccSplitSetAction and xaccSplitGetAction functions
6. Implement register use of num source book option; for General, Income and Search
Ledgers, since there is no anchor split, always show tran-num in transaction
cursor, but vary label to correspond to book option:
register/ledger-core/split-register.h - define TNUM_CELL
define CURSOR_DOUBLE_LEDGER_NUM_ACTN cursor name to use TNUM_CELL
define CURSOR_DOUBLE_JOURNAL_NUM_ACTN cursor name to use TNUM_CELL
add boolean to split_reg structure to hold num source book option
register/ledger-core/split-register-layout.c -
add logic to define and set up new ledger/journal cursors with TNUM_CELLs
add logic to add the new cursors to a layout
add logic to add TNUM_CELL to a layout
register/ledger-core/split-register-model.c -
define function to get TNUM_CELL label
add logic to recognize ledger/journal cursors with TNUM_CELL
modify function to get NUM_CELL value based on book option and register
type
define function to get TNUM_CELL value
adjust num help text to reflect book option choice
define function to get TNUM_CELL help
modify function to get action help to reflect book option choice
set up handlers for TNUM_CELL
register/ledger-core/split-register-model-save.c -
use 'gnc_set_num_action' function to set num/action for NUM_CELL based
on book option
define function to save TNUM_CELL using 'gnc_set_num_action' function
set save handler for TNUM_CELL
register/ledger-core/split-register-util.c -
modify logic to recognize ledger/journal cursors with tnum_cell
register/ledger-core/split-register.c -
define split_register_book_option_changed function
register split_register_book_option_changed function in register init
initialize register structure setting to book option
remove split_register_book_option_changed function in register destroy
modify gnc_split_register_save_to_scm to handle TNUM_CELL
7. Enhance transaction copy/duplicate logic to accommodate new book option:
gnome/gtkbuilder/gnc-plugin-page-register.glade -
add widgets to handle trans number and/or split action based on book option
gnome-utils/dialog-dup-trans.c & .h -
add capability to display and handle 'Num' field according to book option
gnome/gnc-plugin-page-register.c - define gnc_find_register_by_account
register/ledger-core/split-register.c -
modify gnc_split_register_duplicate_current to accomodate book option
setting
register/ledger-core/Makefile.am - add GNOME_CFLAGS
register/ledger-core/test/Makefile.am - add libgnc-gnome.la
8. Adjust register sort and sort labels related to Num/Action radio buttons to
correspond to book option for clarity:
gnome/gnc-plugin-page-register.c -
define gnc_plugin_page_register_sort_book_option_changed to adjust labels
register function in gnc_plugin_page_register_cmd_view_sort_by
and save num and action radio widgets
initialize radio widget labels to correspond to book option
remove function in gnc_plugin_page_register_sort_response_cb
and clear num and action radio widgets
gnome/gnc-split-reg.c & h. -
create versions of gnc_split_reg_sort and gnc_split_reg_set_sort to force
a re-sort to be used when num-source book option changes
engine/Transaction.c & .h -
modify default sort to use split action in place of tran num per book
option if called from xaccSplitOrder
engine/Split.c -
modify xaccSplitOrder to call xaccTransOrder_num_action to switch use of
split action and tran num per book option
engine/test/utest-Split.c -
modify test_xaccSplitOrder to call xaccTransOrder_num_action based on
book option
9. Adjust transaction find labels related to Num/Action to correspond to book option
for clarity:
gnome/dialog-find-transactions.c - adjust labels in search criteria based
on book option
gnome-search/dialog-search.c -
define gnc_search_dialog_book_option_changed to adjust labels
register function in gnc_search_dialog_init_widgets when searching
for splits
remove function in gnc_search_dialog_close_cb if registered
10. Modify new file process to allow setting of num-source (actually, all) book
option(s) during New Account Hierarchy Setup:
gnome-utils/gtkbuilder/dialog-preferences.glade - add a user preference for
the default setting for 'num-source' for new books
core-utils/gnc-gconf-utils.h - define KEY_NUM_SOURCE
gnome-utils/gnc-gnome-utils.c & h. -
define gnc_options_dialog_set_new_book_option_values to retrieve
preference values
gnome-utils/dialog-options.c & .h - define gnc_options_dialog_new_modal to
surpress apply button
gnome-utils/gnc-main-window.c - define function gnc_book_options_dialog_cb
with arguments so that the window can be called in modal mode and the
title changed and return dialog widget; call gnc_options_dialog_new_modal
instead of gnc_options_dialog_new; call this function from
gnc_main_window_cmd_file_properties with new arguments; for modal mode,
call gnc-options-dialog-set-new-book-option-values to initialize values
from preferences
app-utils/gnc-ui-util.c & h. - create function gnc_is_new_book for
determining when a new book is being created
gnome-utils/dialog-utils.c & h. - define gnc_new_book_option_display to
display book options dialog in modal mode
gnome/gtkbuilder/assistant-hierarchy.glade - add notification about book
options to currency page
gnome/assistant-hierarchy.c - add ability to set book option initialized
from preferences value for new books by using functions gnc_is_new_book
and gnc_new_book_option_display
11. Modify Import QIF process to recognize a new-book situation and allow setting
of book options during first import into a new book; also follow book option
setting for num source in importing number whether new book or not:
import-export/qif-import/assistant-qif-import.glade - add notification about
book options to currency page
import-export/qif-import/assistant-qif-import.c - using function
gnc_is_new_book to identify 'new book' situation and set flag; add
logic to handle 'new-book' situation by calling
gnc_new_book_option_display function
import-export/qif-import/qif-to-gnc.scm - use 'gnc_set_num_action' function
to import number to correct field based on book option
12. Modify Import OFX/QFX process to recognize a new-book situation and allow setting
of book options during first import into a new book; also follow book option
setting for num source in importing number whether new book or not:
import-export/ofx/gnc-ofx-import.c - use 'gnc_set_num_action' function to import
number based on book option; identify 'new book' situation using function
gnc_is_new_book and set flag; add logic to handle 'new-book' situation
by raising book options dialog by calling gnc_new_book_option_display
function
import-export/import-backend.c - use 'gnc_get_num_action' function to
retrieve number from transactions to be matched based on book option
13. Modify Import AqBanking process to recognize a new-book situation and allow
setting of book options during first import into a new book; also follow
book option setting for num source in importing number:
import-export/aqbanking/gnc-file-aqb-import.c - identify 'new book'
situation using function gnc_is_new_book and handle by raising book
options dialog by calling gnc_new_book_option_display function
import-export/aqbanking/gnc-ab-utils.c - use 'gnc_set_num_action' function
to set number based on book option
14. Modify Import Transactions from CSV process to recognize a new-book situation
and allow setting of book options during first import into a new book; also
follow book option setting for num source in importing number whether new
book or not:
import-export/csv-import/assistant-csv-trans-import.glade - modify
commments to alert user of raising book options dialog in cases of csv
import into a new book
import-export/csv-import/gnc-csv-model.c & h. - use 'gnc_set_num_action'
function to import number based on book option
import-export/csv-import/assistant-csv-trans-import.c - add logic to handle
'new-book' situation by raising book options dialog by calling
gnc_new_book_option_display function; identify 'new book' situation
using function gnc_is_new_book and set flag
15. Modify Import Accounts from CSV process to recognize a new-book situation
and allow setting of book options during first import into a new book
import-export/csv-import/assistant-csv-account-import.c & .h - add logic to
handle 'new-book' situation by raising book options dialog by calling
gnc_new_book_option_display function; identify 'new book' situation
using function gnc_is_new_book and set flag
16. Modify Export Transactions to CSV process to follow book option setting
for num source in exporting transactions:
import-export/csv-export/csv-transactions-export.c - modify headings to
reflect num-source book option and use 'gnc_get_num_action' function
to retrieve number and action
17. Modify register reporting to reflect book option setting for num source:
gnome/gnc-plugin-page-register.c - determine and pass along ledger-type?
argument to gnc:register-report-create function
gnome/gnc-plugin-page-register2.c - determine and pass along ledger-type?
argument to gnc:register-report-create function
report/standard-reports/standard-reports.scm - add ledger-type? argument
to gnc:register-report-create function; pass it along to
gnc:register-report-create-internal function
report/standard-reports/register.scm - add ledger-type? argument to
gnc:register-report-create-internal function; use 'gnc-get-num-action'
function in place of xaccTransGetNum and 'gnc-get-action-num' function
in place of xaccSplitGetAction and modify report headings and option
text accordingly
18. Modify all places that use xaccTransSetNum and/or xaccSplitSetAction to use
'gnc_set_num_action' function to set number based on book option except
engine/Transaction.c & .h, engine/test-core/test-engine-stuff.c,
engine/Split.c & .h, engine/test/utest-Split.c, engine/engine-helpers.c & .h,
engine/engine-interface.scm, backend/xml/gnc-transaction-xml-v2.c,
backend/xml/io-gncxml-v1.c, import-export/log-replay/gnc-log-replay.c:
engine/gncOwner.c - use 'gnc_set_num_action' function to set number based
on book option
engine/gncInvoice.c - use 'gnc_set_num_action' function to set number based
on book option
engine/SchedXaction.c - use 'gnc_set_num_action' function to set number and
action
engine/cap-gains.c - use 'gnc_set_num_action' function to set split-action
gnome-utils/dialog-transfer.c - use 'gnc_set_num_action' function to set
number based on book option
gnome-utils/gnc-tree-view-split-reg.c - use 'gnc_set_num_action' function
to set number/action based on book option
gnome/assistant-stock-split.c - use 'gnc_set_num_action' function to set
split-action
19. Modify all places that use xaccTransGetNum and/or xaccSplitGetAction to use
'gnc_get_num_action' or 'gnc_get_action_num' functions to get number based
on book option except engine/Transaction.c & .h,
engine/test-core/test-engine-stuff.c, engine/Split.c & h.,
engine/test/utest-Split.c, engine/engine-helpers.c,
engine/engine-interface.scm, backend/xml/gnc-transaction-xml-v2.c,
backend/xml/test/test-xml-transaction.c:
gnome/dialog-lot-viewer.c - use 'gnc_get_num_action' function to retrieve
number based on book option
gnome/dialog-sx-from-trans.c - use 'gnc_get_num_action' function to
retrieve number and action
gnome/dialog-print-check.c - use 'gnc_get_num_action' function to
retrieve number and 'gnc_get_action_num' function to retrieve action
register/ledger-core/split-register-model.c - use 'gnc_get_num_action'
function to retrieve number based on book option
register/ledger-core/split-register-load.c - use 'gnc_get_num_action'
function to retrieve number based on book option
register/ledger-core/split-register-control.c - use 'gnc_get_num_action'
function to retrieve action
register/ledger-core/split-register.c - use 'gnc_get_num_action'
function to retrieve transaction-num
engine/cap-gains.c - use 'gnc_get_num_action' function to get split-action
gnome-utils/gnc-tree-view-split-reg.c - use 'gnc_get_num_action' function
to retrieve number and 'gnc_get_action_num' function to retrieve action
gnome-utils/gnc-tree-model-split-reg.c - use 'gnc_get_num_action' function
to retrieve transaction-number but may not be getting what is expected
if book option to use split-action for 'num' is set
report/locale-specific/us/taxtxf.scm - use 'gnc-get-num-action' function in
place of xaccTransGetNum and 'gnc-get-action-num' function in place of
xaccSplitGetAction and modify report headings and option text accordingly
report/standard-reports/transaction.scm - use 'gnc-get-num-action' function
in place of xaccTransGetNum, adjust sorting based on book option and
modify report headings and option text accordingly; add 'SPLIT-ACTION'
as a term for sorting queries
report/business-reports/customer-summary.scm - use 'gnc-get-num-action'
function in place of xaccTransGetNum
report/business-reports/owner-report.scm - use 'gnc-get-num-action'
function in place of xaccTransGetNum
report/business-reports/job-report.scm - use 'gnc-get-num-action' function
in place of xaccTransGetNum
business/business-gnome/dialog-payment.c - use 'gnc_get_num_action'
function to retrieve number based on book option
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22681 57a11ea4-9604-0410-9ed3-97b8803252fd
(Initially I thought there were a relation to the "freeze" state of a
transaction, but this turned out to be not the case.)
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22118 57a11ea4-9604-0410-9ed3-97b8803252fd
The number of days for this read-only threshold can be chosen.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22107 57a11ea4-9604-0410-9ed3-97b8803252fd
Separate the two uses of QofBook::dirty -- indicating that the book object
itself has been edited and indicating that some object in the dataset has
been changed -- into two separate variables with separate getters & setters.
The latter purpose, indicating that some object has been changed, is moved
to a new member variable of QofBook, session_dirty. Its new setter
qof_book_mark_session_dirty() and canceler qof_book_mark_session_saved()
are called only from the xml backend or gnc-autosave(). Its tester,
qof_book_session_not_saved() is used to check for the need to autosave
and to activate FileSaveAction.
BP
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@21832 57a11ea4-9604-0410-9ed3-97b8803252fd
qof_instance_begin_edit. Add qof_session_safe_save. Add unit tests for
these changes.
QofBook read-only attribute is to prevent starting an edit when the
version of Gnucash which created a dataset is newer than the one
currently running. This is to prevent writing records of an old format
into an existing data set. The user can use File>Save As to create a new
QofSession which will write a completely new dataset in the current
format. This is an important safety feature for future versions of
Gnucash which will not bring all of a dataset into memory, instead
loading only what is immediately needed.
Safe-save is the Qof access to allow writing out a dataset to an
existing server database (i.e., postgresql or mysql) while maintaining
the ability to both transaction-protect saving individual records while
maintaining the ability to rollback the entire save if something goes
wrong.
The unit test framework is added to enable testing these components.
More tests will be added in a later commit.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@20103 57a11ea4-9604-0410-9ed3-97b8803252fd
Patch by Matthijs Kooijman:
The validation function is a very simple "parser" that simply checks for
a single gint64 conversion specification, allowing all modifiers and
flags that printf(3) specifies (except for the * width and precision,
which need an extra argument).
The validation function returns an error message that is used to log a
warning and can be used by the GUI later on.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@20056 57a11ea4-9604-0410-9ed3-97b8803252fd
Patch by Matthijs Kooijman:
This retrieves the counter formats from the kvp slots in the book. The
defaults are unchanged, so this should not affect existing books at all.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@20055 57a11ea4-9604-0410-9ed3-97b8803252fd
Patch by Matthijs Kooijman:
Instead of querying qofbook for the next counter number and then doing
the formatting in all the different business modules (all using the same
format string), the formatting is now moved inside
qof_book_increment_and_get_counter (which is renamed to
qof_book_increment_and_format_counter).
This changes the return value of a bunch of helper functions from gint64
(the counter value) to gchar* (the formatted counter value), but does
not have any user-visible changes.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@20054 57a11ea4-9604-0410-9ed3-97b8803252fd
Patch by Matthijs Kooijman:
The qof_book_get_counter function now only gets the current counter
value. The new qof_book_get_and_increment_counter function now does the
incrementing.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@20053 57a11ea4-9604-0410-9ed3-97b8803252fd
Note that only the type was renamed, but not any enums or function names.
Hence, the scheme wrappers should be unchanged completely (hopefully).
Discussed at http://lists.gnucash.org/pipermail/gnucash-devel/2010-March/027679.html
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18969 57a11ea4-9604-0410-9ed3-97b8803252fd
MSVC doesn't accept the syntax with an inlined block,
x = ({ foo; bar; value;}). Hence, this is being replaced
by actual function definitions, and the body of those functions
is defined by the new macro.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18851 57a11ea4-9604-0410-9ed3-97b8803252fd
The former was already #define'd on the latter, so its removal gets
rid of one level of indirection which makes function lookup easier.
Also, the macro (!) qof_book_get_slots was turned into a normal
function again because that's what functions are for (and otherwise
the additional declaration in engine.i would break).
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18800 57a11ea4-9604-0410-9ed3-97b8803252fd
qof_book_set_string_option() also handles saving the book so that the kvp is updated in the db.
In the future, qof_book_set_<type>_option() and qof_book_get_<type>_option() should be created, where type is
boolean, int, double, ... In addition, other places which handle options in the book should use these routines.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18594 57a11ea4-9604-0410-9ed3-97b8803252fd
values for the book, and the dirty flag does *not* need to be set.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18590 57a11ea4-9604-0410-9ed3-97b8803252fd
report. Instead compute unrealized gains and losses only if the current book
does not use trading accounts.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18552 57a11ea4-9604-0410-9ed3-97b8803252fd
Patch by Mike Alexander:
This patch implements trading accounts somewhat as described in Peter
Selinger's document at
<http://www.mathstat.dal.ca/~selinger/accounting/gnucash.html>. Although he
describes it as a multiple currency problem, it really applies to any
transactions involving multiple commodities (for example buying or selling a
stock) Hence I've called the trading accounts "commodity exchange accounts"
which seems more descriptive.
In summary these patches add an option to use commodity exchange accounts and
if it is on a transaction must be balanced both in value (in the transaction
currency) and in each commodity or currency used in any split in the
transaction. If a transaction only contains splits in the transaction currency
then this is the same rule as Gnucash has always enforced.
In this patch, the option to use trading accounts has been moved from
Edit->Preferences to File->Properties and is now associated with the active
book instead of being a global option. If you have set the global value on in
a previous version you will need to set it on again in each file for which you
want trading accounts, the previous global setting will be ignored.
A more detailed list of changes follows:
1. Added a "Use commodity exchange accounts" per-book option.
2. Added gnc_monetary and MonetaryList data types.
3. Renamed xaccTransGetImbalance to xaccTransGetImbalanceValue and added a new
xaccTransGetImbalance that returns a MonetaryList. Also added
xaccTransIsBalanced to see if the transaction is balanced without returning a
GList that needs to be freed. It calls both xaccTransGetImbalance and
xaccTransGetImbalanceValue since a transaction may be unbalanced with regard to
either without being unbalanced with regard to the other.
4. Changed gnc_split_register_get_debcred_bg_color to use xaccTransIsBalanced.
5. Changed gnc_split_register_balance_trans to not offer to adjust an existing
split if there imbalances in multiple currencies. Because of bugs in the
register code this is rarely called.
6. Changed importers to use xaccTransGetImbalanceValue to check for imbalance,
assuming that they won't create multiple currency trasactions.
7. Changed xaccTransScrubImbalance to create a balancing split for each
imbalanced commodity in the transaction. Also balances the transaction value.
The commodity balancing splits go into accounts in the hierarchy
Trading:NAMESPACE:COMMODITY. The value balancing splits go into
Imbalance-CURRENCY as before.
8. Changed xaccSplitConvertAmount to use xaccTransIsBalanced instead of
xaccTransGetImbalance.
9. Changed gnc_split_register_get_debcred_entry to sometimes use the split
amount instead of value if using currency accounts.
If the register is a stock register (i.e., shows shares and prices), it uses
the value if the split is in the register commodity (i.e. is for the stock) and
the amount otherwise. It shows the currency symbol unless the commodity is the
default currency.
If the register is not a stock register it always uses the amount and shows the
currency symbol if the split is not in the register commodity.
Also changed it to not return a value for a null split unless the transaction
is unbalanced in exactly one currency. This is what goes in a blank split as
the proposed value.
10. Changed refresh_model_row to use xaccTransGetImbalanceValue to get the
imbalance, assuming that importers don't create transactions in multiple
currencies. Also same change in gnc_import_process_trans_item,
downloaded_transaction_append, and gnc_import_TransInfo_is_balanced.
11. Changed the TRANS_IMBALANCE accessor method in xaccTransRegister to use
xaccTransGetImbalanceValue. As far as I can tell this is only used by the
"pd-balance" query type in gnc_scm2query_term_query_v1() defined in
engine-helpers.c. This query type only tests the result for zero/non-zero.
12. Changed xaccTransGetAccountConvRate to accept any split into the correct
commodity instead of insisting on one into the provided account. Then can use
it in xaccTransScrubImbalance to set the value of the imbalance split from its
amount, however later changed xaccTransScrubImbalance to not use it. Instead
it sets the value for the new split correctly to keep the value of the whole
transaction balanced.
13. Changed the balance sheet report to include a new option to not compute
unrealized gains and losses.
14. Related to 9 above, changed gnc_split_register_auto_calc to not do anything
if given a stock register where the value cell doesn't contain the value.
15. Also related to 9, changed gnc_split_register_save_amount_values to set the
amount and value fields in the split correctly when using trading accounts.
16. Changed the new account and edit account dialogs to allow any commodity or
currency for an income account if using trading accounts. It would be better
to add a new account type for trading accounts, but that's a big deal and I'll
leave that for later after we see whether this set of changes is going to be
accepted or rejected.
17. Change gnc_xfer_dialog_run_exchange_dialog to understand that the new value
is really the split's amount if using trading accounts.
18. Changed xaccSplitGetOtherSplit to ignore trading splits if using commodity
exchange accounts.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18429 57a11ea4-9604-0410-9ed3-97b8803252fd
This also strips trailing whitespaces from lines where they existed.
This re-indentation was done using astyle-1.23 using the following options:
astyle --indent=spaces=4 --brackets=break --pad-oper
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18319 57a11ea4-9604-0410-9ed3-97b8803252fd