Commit Graph

435 Commits

Author SHA1 Message Date
Mike Alexander
6ed3bfa6a3 Better detection of unbalanced transactions with trading accounts.
A transaction's value should be balanced independently in trading and
non-trading splits to be considered balanced.  Incorrect adjustment
of exchange rates on existing splits can cause this to be an issue.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22645 57a11ea4-9604-0410-9ed3-97b8803252fd
2012-12-13 05:13:42 +00:00
John Ralls
7694f858d1 Convert all time_t to time64: engine
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22621 57a11ea4-9604-0410-9ed3-97b8803252fd
2012-12-01 22:44:53 +00:00
Geert Janssens
3f5eae6d8e Further register rewrite work.
This patch is an updated patch which I have been fighting with the sort
model on. It allows you to add, delete and modify basic transactions
and splits with the toolbar buttons. Jump and move to blank are
also working.

Visual indication of read only and future transactions are
also implemented.

As before, do not open same account in old and new register.

Tab key works manually but needs more work, cell editable value does not
seem to be reliable which was the way I was going to auto step over
uneditable cells.

There is another problem if you enter the debit/credit value before the
account, you will get an error in the trace file but entries
are recorded, not sure of answer.

New transactions are not added in date order at the moment, this was
going to be done by the sort model or the existing method of reload
register via the commented out watchers in ledger-display.

All the numeric functions are the existing ones from the rewrite and as
such I have not proved they are correct but a basic transaction seems to
work.

Author: Robert Fewell <14ubobit@gmail.com>

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22448 57a11ea4-9604-0410-9ed3-97b8803252fd
2012-10-18 08:15:21 +00:00
Mike Alexander
e1bd508f61 Add xaccTransDump back, it is very useful when debugging.
It was removed in SVN r21579, "Cruft Reduction"< but it's not cruft.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22382 57a11ea4-9604-0410-9ed3-97b8803252fd
2012-09-11 03:29:39 +00:00
Geert Janssens
c5e2adcb7a Refactor safe_strcmp into the glib standard g_strcmp0
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22290 57a11ea4-9604-0410-9ed3-97b8803252fd
2012-08-07 17:24:55 +00:00
Geert Janssens
a54e7149bf Initial code for a new register.
This is very incomplete, but at the same time well isolated from the
rest of the code, so it is easy to disable should it not get functional
and stable before the next major release.
I decided to include it in trunk to give it more visibility and prevent
bitrot in the patch.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22289 57a11ea4-9604-0410-9ed3-97b8803252fd
2012-08-07 17:24:33 +00:00
John Ralls
b391754ff6 Correct -Wunused warnings
The actual change to configure.ac (at line 1106) to enable -Wunused -- or rather to un-disable it -- is not included in order to not break the build for folks with buggy versions of swig.
(For example, https://sourceforge.net/tracker/?func=detail&aid=3530021&group_id=1645&atid=101645)

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22203 57a11ea4-9604-0410-9ed3-97b8803252fd
2012-05-26 23:47:34 +00:00
Phil Longstaff
d1fcb82ad0 Fix some g-object parameter types
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22181 57a11ea4-9604-0410-9ed3-97b8803252fd
2012-05-20 21:18:45 +00:00
Christian Stimming
b208b06b00 Fix segfault after behaviour change of qof_book_get_autoreadonly_gdate() in r22118.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22122 57a11ea4-9604-0410-9ed3-97b8803252fd
2012-03-25 19:13:16 +00:00
Christian Stimming
176fba9b9f Rename internal function names for read-only option of r22107 also to "auto-read-only".
(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
2012-03-24 22:34:59 +00:00
Christian Stimming
ed581152b9 Take read-only setting of QofBook into account for the transaction deletion as well.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22117 57a11ea4-9604-0410-9ed3-97b8803252fd
2012-03-24 22:34:44 +00:00
Christian Stimming
3fcdf59adf Re-indentation of source code.
As usual, 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@21816 57a11ea4-9604-0410-9ed3-97b8803252fd
2012-01-01 20:36:46 +00:00
Geert Janssens
7f40be5302 Fix some static warnings and errors as a result of Eclipse's static code
analysis.
As a result, some unused functions and function prototypes are removed.

It did expose one real bug in Transaction.c so far.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@21687 57a11ea4-9604-0410-9ed3-97b8803252fd
2011-12-08 17:11:21 +00:00
John Ralls
eeaa897be1 [Cruft Reduction] Remove unused functions from src/engine
Nothing in gnc-session-scm.c was being used, so deleted it and its corresponding header.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@21579 57a11ea4-9604-0410-9ed3-97b8803252fd
2011-11-18 21:04:01 +00:00
Christian Stimming
3365baa7ed Take into account the read-only flag of the book to update the buttons in the register accordingly.
Also, the register itself must be read-only.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@21569 57a11ea4-9604-0410-9ed3-97b8803252fd
2011-11-14 21:28:32 +00:00
Mike Alexander
9369eae6d7 Avoid double free of capital gains transactions when quitting
If an register is open on an account that has capital gains transactions
created by the lot scrubber when you quit Gnucash, a capital gains
transaction may be freed twice since it is freed when the associated
sale is freed and again when it is encountered on the list of
transactions to be freed.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@21495 57a11ea4-9604-0410-9ed3-97b8803252fd
2011-10-28 03:22:41 +00:00
John Ralls
1ed80def56 Formatting Fixes with astyle --indent=spaces=4 --brackets=break --pad-oper --pad-header --suffix=none
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@20936 57a11ea4-9604-0410-9ed3-97b8803252fd
2011-07-17 17:35:30 +00:00
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
Phil Longstaff
55865d2e1b Fix more memory leaks. Also, when closing a book (to open a new one, not year end), free objects.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@20042 57a11ea4-9604-0410-9ed3-97b8803252fd
2011-01-09 18:01:47 +00:00
Derek Atkins
3f70c99002 Add APIs to get/set a flag signifying that a transaction is a book-closing txn.
This is necessary for Bug #570042 but doesn't completely solve it until
the reports are updated to use the new API.  This is backwards-compatible
with the slot data inserted by the book closing since 2010-03-02.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@19945 57a11ea4-9604-0410-9ed3-97b8803252fd
2010-12-16 02:11:53 +00:00
Geert Janssens
a0c19b4c71 Bug #502853 - Incorrent tax rounding in invoice (rounding of .5)
This patch changes the default rounding behaviour in GnuCash from
"Round to nearest even" to "Round away to infinity". See the bugreport
for more details on these different rounding methods.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@19695 57a11ea4-9604-0410-9ed3-97b8803252fd
2010-10-23 10:38:48 +00:00
Geert Janssens
8c4fa3a192 Spelling fixes in comments
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@19545 57a11ea4-9604-0410-9ed3-97b8803252fd
2010-09-04 13:24:46 +00:00
Geert Janssens
081b91fd64 Refactoring: replace all GNC_RND_* and GNC_DENOM_* occurences with their GNC_HOW_RND_* and GNC_HOW_DENOM_* equivalents
And then remove the deprecated definitions.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@19476 57a11ea4-9604-0410-9ed3-97b8803252fd
2010-08-26 17:22:06 +00:00
Christian Stimming
88d3b83579 Re-indentation of source code.
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 --suffix=none

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18970 57a11ea4-9604-0410-9ed3-97b8803252fd
2010-03-27 21:01:56 +00:00
Christian Stimming
a322015eb8 Rename the type GUID into GncGUID because on Windows, the system headers have a type GUID which clashes with ours.
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
2010-03-27 21:01:21 +00:00
Phil Longstaff
962512ab7d Extend xaccXXXXXEqual() routines so that they can compare objects in different books to see if they have the same contents.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18962 57a11ea4-9604-0410-9ed3-97b8803252fd
2010-03-25 18:32:40 +00:00
Christian Stimming
59be2dc692 Add getter/setter for transaction posted-date as a GDate.
In addition to the known timespec, the date is also stored
as a kvp_value of TYPE_GDATE so that we know afterwards this
date has really been set as a date.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18925 57a11ea4-9604-0410-9ed3-97b8803252fd
2010-03-17 19:23:40 +00:00
Christian Stimming
e42a405785 Some more const-correctness in engine functions.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18873 57a11ea4-9604-0410-9ed3-97b8803252fd
2010-03-07 21:28:15 +00:00
Christian Stimming
44b63315df Decrease compiler warnings by removing unused variables.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18799 57a11ea4-9604-0410-9ed3-97b8803252fd
2010-03-03 20:46:41 +00:00
Christian Stimming
763e4c3d15 Re-indentation of source code, next batch: src/engine/*
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 --suffix=none

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18788 57a11ea4-9604-0410-9ed3-97b8803252fd
2010-03-02 21:40:28 +00:00
Phil Longstaff
b491220bf9 Add more gobject property definitions to GNCPrice, Transaction, SchedXaction and Split.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18767 57a11ea4-9604-0410-9ed3-97b8803252fd
2010-03-01 16:46:49 +00:00
Phil Longstaff
181286c970 Add a few gobject properties to some engine object types. This adds more of the gobject infrastructure to Transaction, Split, SchedXaction and GNCPrice. Gobject properties provides a standardized interface to the engine objects which should allow standard and simplified read/write mechanisms. For the sql backend, for example, db columns can be mapped to properties. In a generalized csv importer, csv columns can be mapped to properties.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18762 57a11ea4-9604-0410-9ed3-97b8803252fd
2010-02-28 17:35:53 +00:00
Phil Longstaff
46c071490b Don't include gnc-lot-p.h where not needed
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18758 57a11ea4-9604-0410-9ed3-97b8803252fd
2010-02-28 13:13:27 +00:00
Christian Stimming
1ddcb88d0c MSVC compatibility: Microsoft doesn't have C99 "designated initializers".
Those were introduced in r17724, bug#539957, but apparently this
C99 is not supported by MSVC and won't be for some time to come.
Hence, for MSVC we need the workaround to define a macro that will
shadow the member names. However, the initialization itself works
fine and non-MSVC code is unchanged, so I think we can live with that.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18755 57a11ea4-9604-0410-9ed3-97b8803252fd
2010-02-27 18:41:49 +00:00
Phil Longstaff
a3ca714396 Convert GNCLot to use more gobject features. Removes all direct access to lot object fields, which are now accessed through functions or property names (for backend sql load).
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18745 57a11ea4-9604-0410-9ed3-97b8803252fd
2010-02-27 15:54:20 +00:00
Christian Stimming
82b8b99c9d More minor MSVC code fixes.
However, this code doesn't compile with MSVC9.0 for a few reasons:

1. libguile.h comes with its own scmconfig.h which contains HAVE_STDINT_H
whereas MSVC doesn't have that. This is stupid guile which doesn't accept
the fact that the user uses a different compiler than how they compiled guile.

2. Some initializations are not supported: Account.c:3312 etc.

3. The C99 "designated initializers" of e.g. Account.c:4661 ff. (r17724,
bug#539957) are not supported by MSVC9.0 - this is the hardest problem
of these all.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18738 57a11ea4-9604-0410-9ed3-97b8803252fd
2010-02-25 17:42:43 +00:00
Phil Longstaff
fbdcd66a91 Revert 18490/18491/18527 - I'm not sure it's actually deleting the objects without affecting the database.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18589 57a11ea4-9604-0410-9ed3-97b8803252fd
2010-01-30 22:57:55 +00:00
Phil Longstaff
7bbb8888a7 Free accounts/lots/splits/transactions when closing a book
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18527 57a11ea4-9604-0410-9ed3-97b8803252fd
2009-12-18 19:45:57 +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
Phil Longstaff
f6eaab3238 Mark transaction dirty when setting enter-date
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18163 57a11ea4-9604-0410-9ed3-97b8803252fd
2009-06-28 22:54:47 +00:00
Andreas Köhler
526ee85f93 Bug #566352: Remove printf("%s", NULL) in xaccTransSetDateInternal() when val=={-1,0}.
BP


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@17836 57a11ea4-9604-0410-9ed3-97b8803252fd
2009-01-18 23:43:02 +00:00
Christian Stimming
35129a333c Bug #539957: Replace struct named assignments by C99 "designated initializers"
Patch by Halton Huo.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@17724 57a11ea4-9604-0410-9ed3-97b8803252fd
2008-11-26 14:35:36 +00:00
Phil Longstaff
2d151f9fcf Add a callback to gnc-engine which will be called when a qof commit
fails.  Most engine objects catch the qof commit but then just log the 
problem to the trace log.  Now, the engine objects will invoke this 
callback.  gnc-main-window registers a callback and opens a dialog box 
to inform the user.  This is necessary because with an sql backend, 
commits happen whenever an object is created or modified, not just 
synchronously when the user selects to save the file.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@17667 57a11ea4-9604-0410-9ed3-97b8803252fd
2008-10-27 23:42:01 +00:00
Joshua Sled
62e8bdb0ef "trans" and "t" aren't good variable names… try "from" and "to".
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@16653 57a11ea4-9604-0410-9ed3-97b8803252fd
2007-12-15 20:57:19 +00:00
Andreas Köhler
dcfda18f7c Revert some qof_instance_get_guid() calls to qof_entity_get_guid().
Those two functions were merged into one, qof_instance_get_guid(), in
r15773, but they returned different values if the parameter was NULL.
Some code depends on the return value being guid_null(), or maybe even
NULL, so revert the changes entity->instance, where the entity is not
guaranteed to be non-NULL.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@16212 57a11ea4-9604-0410-9ed3-97b8803252fd
2007-06-25 17:18:28 +00:00
David Hampton
9ec864163d Collapse the various "idata" fields into a single field attached to
the QofInstance object.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@16042 57a11ea4-9604-0410-9ed3-97b8803252fd
2007-05-03 03:56:31 +00:00
David Hampton
cad2164810 Collapse the various "version" and "version_check" fields into a
single pair of fields attached to the QofInstance object.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@16041 57a11ea4-9604-0410-9ed3-97b8803252fd
2007-05-03 02:56:56 +00:00
David Hampton
285a5216b3 Move QofInstance guid property from its public data structure to its
private data structure.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@16039 57a11ea4-9604-0410-9ed3-97b8803252fd
2007-05-02 05:42:41 +00:00
David Hampton
4f6fd1b090 Move QofInstance book properties from its public data structure to its
private data structure.



git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@16038 57a11ea4-9604-0410-9ed3-97b8803252fd
2007-05-02 03:18:46 +00:00
David Hampton
ce65024722 Start putting an API in place for access to the members of the
QofInstance object.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@16025 57a11ea4-9604-0410-9ed3-97b8803252fd
2007-04-30 05:33:33 +00:00