Commit Graph

22 Commits

Author SHA1 Message Date
Christian Stimming
c8f1244fff Re-indentation of source code.
This re-indentation was done using astyle-1.24 using the following options:

  astyle --indent=spaces=4 --brackets=break --pad-oper --pad-header --suffix=none

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@20163 57a11ea4-9604-0410-9ed3-97b8803252fd
2011-01-24 14:10:09 +00:00
John Ralls
886da7638d Add a read-only attribute to QofBook and check of same to
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
2011-01-14 23:25:27 +00:00
J. Alex Aycinena
f70cb1fe2f Fix typo
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@20058 57a11ea4-9604-0410-9ed3-97b8803252fd
2011-01-11 00:15:02 +00:00
Christian Stimming
10b45bf554 Bug #638543: Validate counter format strings before using them.
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
2011-01-10 21:39:29 +00:00
Christian Stimming
e1c6d28eac Bug #638543: Make the various counter formats configurable.
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
2011-01-10 21:39:18 +00:00
Christian Stimming
aa151f0ae0 Bug #638543: Centralize the counter formatting in qofbook.
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
2011-01-10 21:39:06 +00:00
Christian Stimming
670b3b63da Bug #638543: Split the qof_book_get_counter function.
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
2011-01-10 21:38:54 +00:00
Christian Stimming
d565bdb982 Bug #638543: Remove the counter() method from the backends.
Patch by Matthijs Kooijman:

This method is not implemented by either of the backends and removing it
makes the subsequent commits possible.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@20052 57a11ea4-9604-0410-9ed3-97b8803252fd
2011-01-10 21:38:43 +00:00
Christian Stimming
449df116d8 Bug #612212: Provide a method to set the default budget
Patch by Jeff Kletsky.

(Cstim: Accepted even though string freeze is in effect because it was
submitted before the freeze. Also, the string additions are very minor.)

Summary of Changes:

* Initial story related to providing default budget control
  * Add a "Budgeting" tab to the book-level preferences dialog
  * Add a "Default Budget" selector to the "Budgeting" tab
  * Modify gnc_budget_get_default() to
    * Respect the new KVP, if present
    * Fall back to 2.2.x behavior, if not present
  * Modify gnc:make-budget-option
    * Reformatted for readability with additional comments
    * Default is now "#f" so that selected value is always saved
      Otherwise, if selection happened to be the current default
      and the default was later changed, the report would change
    * getter, setter, and generate-restore-form all now consistent
      * setter now always takes a budget object
      * generate-restore-form does not rely on "hack" in setter that
          previously allowed either a budget object or a GUID string
          This is a different fix for 603215 -- see Known Issues

* Provide translation support for "Trading Acccounts" (and "Budgeting")
  * Refactor #define names for consistency and extensibility
    * KVP_OPTION_PATH for consistency with Guile usage
    * OPTION_SECTION_blahblah
    * OPTION_NAME_blahblah
  * Modify qofbookslots.h to be "SWIG-aware"
  * Pick up qofbookslots.h in make-gnucash-potfiles.in and po/POTFILES.in

Known Issues:

* There is no selection (yet) for "Use default budget" so changing the
  default budget and reloading a report does not change the budget used

* setter is no more robust to "bad" values than in previous code

* Budget reports created with 2.3.x after r18528 (between 2.3.8 and
  2.3.9) may not load or re-render as they relied on the setter taking
  either a budget object or a GUID as a string This should not impact
  any 2.2.x users as nothing was saved under 2.2.x related to the
  default budget. This can be resolved through removing the option
  restore code in ~/.gnucash/saved-reports-2.4 and, if affected reports
  were open, in ~/.gnucash/books/<name_of_book>

* Budget reports prior to r18528 did not save budget selection (603215)

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@19123 57a11ea4-9604-0410-9ed3-97b8803252fd
2010-05-06 09:01:46 +00:00
Phil Longstaff
ac1cf031f5 When updating book counters for business objects (in book slots), ensure they're saved.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@19038 57a11ea4-9604-0410-9ed3-97b8803252fd
2010-04-19 16:56:40 +00:00
Christian Stimming
b7b34b87c9 Rename GNCBook into QofBook everywhere and remove separate header gnc-book.h.
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
2010-03-03 20:47:10 +00:00
Christian Stimming
a824e611e2 Re-indentation of source code, next batch.
This also strips trailing whitespaces from lines where they existed.
This re-indentation was done using astyle-1.24 using the following options:

astyle --indent=spaces=4 --brackets=break --pad-oper --pad-header

Discussed at http://lists.gnucash.org/pipermail/gnucash-devel/2009-August/026121.html

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18675 57a11ea4-9604-0410-9ed3-97b8803252fd
2010-02-18 05:31:54 +00:00
Phil Longstaff
6ed568ab77 Create routines qof_book_get_string_option() and qof_book_set_string_option() to get/set a kvp string, respectively.
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
2010-01-31 20:03:23 +00:00
Phil Longstaff
791bdfbd20 Create qof_book_begin_edit()/qof_book_commit_edit() routines. These need to be added around lines which set kvp
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
2010-01-30 22:59:37 +00:00
Christian Stimming
61c16a06dd Re-indentation of source code, next batch.
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

Discussed at http://lists.gnucash.org/pipermail/gnucash-devel/2009-August/026121.html

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18535 57a11ea4-9604-0410-9ed3-97b8803252fd
2009-12-29 20:12:48 +00:00
Phil Longstaff
75e1094cfd Free memory leaks
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18489 57a11ea4-9604-0410-9ed3-97b8803252fd
2009-12-12 00:15:50 +00:00
Christian Stimming
a699183ae5 Bug #537476: Fix currency trading account preference lookup
Patch by Mike Alexander:

There are a few values related to the trading accounts preference that are
needed in both Scheme and C code.  Since one of them was already defined in
Scheme before I started, I defined all of them there and tried to import them
to C.  This is obviously not a good idea, especially since the make check tests
don't even fire up Guile so Scheme code isn't available.  This patch changes
things around to define the values in C and import them to Scheme.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18464 57a11ea4-9604-0410-9ed3-97b8803252fd
2009-12-04 20:26:48 +00:00
Phil Longstaff
58f05266fb Temporarily disable currency trading accounts so that 'make check' will pass so that
2.3.8 can be released.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18449 57a11ea4-9604-0410-9ed3-97b8803252fd
2009-11-29 19:48:21 +00:00
Christian Stimming
812c02be0b Temporary workaround for crash at startup after r18429.
Before this change, gnucash crashes on start-up with Backtrace:
In unknown file:
   ?: 0* gnc:*book-label*

<unnamed port>: In expression gnc:*book-label*:
<unnamed port>: Unbound variable: gnc:*book-label*

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18430 57a11ea4-9604-0410-9ed3-97b8803252fd
2009-11-20 21:12:21 +00:00
Christian Stimming
b578c56b27 Bug #537476: Implement currency trading accounts optionally, to be enabled per-book.
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
2009-11-20 20:11:03 +00:00
Christian Stimming
c5077e259f Re-indentation of source code, first try, only in the libqof directory so far.
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
2009-09-18 19:40:57 +00:00
Phil Longstaff
89bfcce989 Rename lib/libqof -> src/libqof
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18029 57a11ea4-9604-0410-9ed3-97b8803252fd
2009-04-07 00:48:53 +00:00