GnuCash
5.6-150-g038405b370+
|
Data scrubbing, repairing and forward migration routines. More...
Files | |
file | Scrub.h |
convert single-entry accounts to clean double-entry | |
file | Scrub2.h |
Utilities to Convert Stock Accounts to use Lots. | |
file | Scrub3.h |
High-Level API for imposing Lot constraints. | |
file | ScrubBusiness.h |
Cleanup functions for business objects. | |
Double-Entry Scrubbing | |
Convert single-entry accounts to clean double-entry Provides a set of functions and utilities for checking and repairing (formerly called 'scrubbing clean') single-entry accounts so that they can be promoted into self-consistent, clean double-entry accounts. Basically and additionally, this file collects all functions that turn old (deprecated) data structures into the current new data model. The ScrubOrphans() methods search for transacations that contain splits that do not have a parent account. These "orphaned splits" are placed into an "orphan account" which the user will have to go into and clean up. Kind of like the unix "Lost+Found" directory for orphaned inodes. | |
void | gnc_set_abort_scrub (gboolean abort) |
The gnc_set_abort_scrub () method causes a currently running scrub operation to stop, if abort is TRUE; gnc_set_abort_scrub(FALSE) must be called before any scrubbing operation. | |
gboolean | gnc_get_abort_scrub (void) |
gboolean | gnc_get_ongoing_scrub (void) |
The gnc_get_ongoing_scrub () method returns TRUE if a scrub operation is ongoing. | |
void | xaccTransScrubOrphans (Transaction *trans) |
The xaccTransScrubOrphans() method scrubs only the splits in the given transaction. | |
void | xaccAccountScrubOrphans (Account *acc, QofPercentageFunc percentagefunc) |
The xaccAccountScrubOrphans() method performs this scrub only for the indicated account, and not for any of its children. | |
void | xaccAccountTreeScrubOrphans (Account *acc, QofPercentageFunc percentagefunc) |
The xaccAccountTreeScrubOrphans() method performs this scrub for the indicated account and its children. | |
void | xaccSplitScrub (Split *split) |
The xaccSplitScrub method ensures that if this split has the same commodity and currency, then it will have the same amount and value. More... | |
void | xaccTransScrubSplits (Transaction *trans) |
The xacc*ScrubSplits() calls xaccSplitScrub() on each split in the respective structure: transaction, account, account & it's children, account-group. | |
void | xaccAccountScrubSplits (Account *account) |
void | xaccAccountTreeScrubSplits (Account *account) |
void | xaccTransScrubImbalance (Transaction *trans, Account *root, Account *parent) |
The xaccScrubImbalance() method searches for transactions that do not balance to zero. More... | |
void | xaccAccountScrubImbalance (Account *acc, QofPercentageFunc percentagefunc) |
void | xaccAccountTreeScrubImbalance (Account *acc, QofPercentageFunc percentagefunc) |
void | xaccTransScrubCurrency (Transaction *trans) |
The xaccTransScrubCurrency method fixes transactions without a common_currency by looking for the most commonly used currency among all the splits in the transaction. More... | |
void | xaccAccountScrubCommodity (Account *account) |
The xaccAccountScrubCommodity method fixed accounts without a commodity by using the old account currency and security. More... | |
void | xaccAccountTreeScrubCommodities (Account *acc) |
The xaccAccountTreeScrubCommodities will scrub the currency/commodity of all accounts & transactions in the specified account or any child account. More... | |
void | xaccAccountTreeScrubQuoteSources (Account *root, gnc_commodity_table *table) |
This routine will migrate the information about price quote sources from the account data structures to the commodity data structures. More... | |
void | xaccAccountScrubKvp (Account *account) |
Removes empty "notes", "placeholder", and "hbci" KVP slots from Accounts. More... | |
void | xaccAccountScrubColorNotSet (QofBook *book) |
Remove color slots that have a "Not Set" value, since 2.4.0, fixed in 3.4 This should only be run once on a book. | |
void | xaccTransScrubPostedDate (Transaction *trans) |
Changes Transaction date_posted timestamps from 00:00 local to 11:00 UTC. More... | |
Lot Management Routines | |
Provides the low-level API for checking and repairing ('scrubbing clean') the usage of Lots and lot balances in stock and commodity accounts. Broken lots are repaired using a first-in, first-out (FIFO) accounting schedule. This is a 'low-level' API in the sense that each routine accomplishes only one particular task needed to clean up a Lot. To clean up a Lot as a whole, you almost certainly want to use one of the high-level API routines from the Scrub3.h file. | |
void | xaccAccountAssignLots (Account *acc) |
The xaccAccountAssignLots() routine will walk over all of the splits in an account, and make sure that each belongs to a lot. More... | |
void | xaccLotFill (GNCLot *lot) |
The xaccLotFill() routine attempts to assign splits to the indicated lot until the lot balance goes to zero, or until there are no suitable (i.e. More... | |
void | xaccLotScrubDoubleBalance (GNCLot *lot) |
The xaccLotScrubDoubleBalance() routine examines the indicated lot. More... | |
gboolean | xaccScrubMergeSubSplits (Split *split, gboolean strict) |
The xaccScrubMergeSubSplits() routine will merge together all of the splits that were at one time split off from this split, but are no longer needed to be kept separate. More... | |
gboolean | xaccScrubMergeLotSubSplits (GNCLot *lot, gboolean strict) |
The xaccScrubMergeLotSubSplits() routine does the same as the xaccScrubMergSubSplits, except that it does it for all of the splits in the lot. | |
High-Level Lot Constraint | |
Provides the high-level API for checking and repairing ('scrubbing clean') the usage of Lots and Cap Gains transactions in stock and commodity accounts. | |
gboolean | xaccScrubLot (GNCLot *lot) |
The xaccScrubLot() routine makes sure that the indicated lot is self-consistent and properly balanced, and fixes it if its not. More... | |
void | xaccAccountScrubLots (Account *acc) |
The xaccAccountScrubLots() routine makes sure that every split in the account is assigned to a lot, and that then, every lot is self-consistent (by calling xaccScrubLot() on each lot). More... | |
void | xaccAccountTreeScrubLots (Account *acc) |
Cleanup functions for business objects | |
Provides the high-level API for checking and repairing ('scrubbing clean') the various data objects used by the business functions. | |
gboolean | gncScrubBusinessLot (GNCLot *lot) |
The gncScrubBusinessLot() function makes sure that the indicated lot has all the correct properties required for a lot used in the business features. More... | |
gboolean | gncScrubBusinessSplit (Split *split) |
The gncScrubBusinessSplit() function will fix all issues found with the given split. More... | |
void | gncScrubBusinessAccountLots (Account *acc, QofPercentageFunc percentagefunc) |
The gncScrubBusinessAccountLots() function will call gncScrubBusinessLot() on each lot in the given account. More... | |
void | gncScrubBusinessAccountSplits (Account *acc, QofPercentageFunc percentagefunc) |
The gncScrubBusinessAccountSplits() function will call gncScrubBusinessSplit() on each split in the given account. | |
void | gncScrubBusinessAccount (Account *acc, QofPercentageFunc percentagefunc) |
The gncScrubBusinessAccount() function will call all scrub functions relevant for a given account on condition the account is a business related account (Accounts Receivable or Accounts Payable type). More... | |
void | gncScrubBusinessAccountTree (Account *acc, QofPercentageFunc percentagefunc) |
The gncScrubBusinessAccountTreeLots() function will call gncScrubBusinessAccount() on the given account and its sub accounts. | |
Data scrubbing, repairing and forward migration routines.
These routines check and repair data, making sure that it is in a format that the current version of the GnuCash Engine likes. These routines serve both to provide backwards compatibility with older versions of GnuCash, and to fix or at least paper over possible current problems.
It is typically expected that the scrub routines are run over newly imported data, as well as during data file input.
In some cases, it is entirely appropriate to invoke these routines from the GUI, to validate that the user input through the GUI is in a format that the system likes. This includes things like balancing individual transactions, or assigning splits to lots, so that capital gains can be computed.
void gncScrubBusinessAccount | ( | Account * | acc, |
QofPercentageFunc | percentagefunc | ||
) |
The gncScrubBusinessAccount() function will call all scrub functions relevant for a given account on condition the account is a business related account (Accounts Receivable or Accounts Payable type).
This routine is the primary routine for fixing all (known) issues in a business account.
Definition at line 736 of file ScrubBusiness.c.
void gncScrubBusinessAccountLots | ( | Account * | acc, |
QofPercentageFunc | percentagefunc | ||
) |
The gncScrubBusinessAccountLots() function will call gncScrubBusinessLot() on each lot in the given account.
This routine is the primary routine for ensuring that the lot structure of every lot of a business account is in good order.
Definition at line 620 of file ScrubBusiness.c.
gboolean gncScrubBusinessLot | ( | GNCLot * | lot | ) |
The gncScrubBusinessLot() function makes sure that the indicated lot has all the correct properties required for a lot used in the business features.
Currently this function only does one thing: eliminate lot link transactions between invoice lots and payment lots (which were generated by GnuCash versions 2.6.0-2.6.3). Lot links between invoices and credit notes will still remain.
Scrubbing the lot may cause subsplits to be merged together, i.e. for splits to be deleted. This routine returns true if any splits were modified or deleted.
Definition at line 467 of file ScrubBusiness.c.
gboolean gncScrubBusinessSplit | ( | Split * | split | ) |
The gncScrubBusinessSplit() function will fix all issues found with the given split.
Current checks are:
Definition at line 529 of file ScrubBusiness.c.
void xaccAccountAssignLots | ( | Account * | acc | ) |
The xaccAccountAssignLots() routine will walk over all of the splits in an account, and make sure that each belongs to a lot.
Currently, the default (and only implemented) assignment policy is a FIFO policy: Any splits that are not in a lot will be used to close the oldest open lot(s). If there are no open lots, a new lot will be started. By trying to close the oldest lots, this effectively implements a FIFO accounting policy.
The xaccAccountAssignLots() routine will walk over all of the splits in an account, and make sure that each belongs to a lot.
If a split does not belong to any lots, poke it into one.
Definition at line 59 of file Scrub2.cpp.
void xaccAccountScrubCommodity | ( | Account * | account | ) |
The xaccAccountScrubCommodity method fixed accounts without a commodity by using the old account currency and security.
Definition at line 1222 of file Scrub.cpp.
void xaccAccountScrubKvp | ( | Account * | account | ) |
Removes empty "notes", "placeholder", and "hbci" KVP slots from Accounts.
Definition at line 1368 of file Scrub.cpp.
void xaccAccountScrubLots | ( | Account * | acc | ) |
The xaccAccountScrubLots() routine makes sure that every split in the account is assigned to a lot, and that then, every lot is self-consistent (by calling xaccScrubLot() on each lot).
This routine is the primary routine for ensuring that the lot structure, and the cap-gains for an account are in good order.
Most GUI routines will want to use one of these xacc[*]ScrubLots() routines, instead of the various component routines, since it will usually makes sense to work only with these high-level routines.
Definition at line 159 of file Scrub3.cpp.
void xaccAccountTreeScrubCommodities | ( | Account * | acc | ) |
The xaccAccountTreeScrubCommodities will scrub the currency/commodity of all accounts & transactions in the specified account or any child account.
Definition at line 1287 of file Scrub.cpp.
void xaccAccountTreeScrubQuoteSources | ( | Account * | root, |
gnc_commodity_table * | table | ||
) |
This routine will migrate the information about price quote sources from the account data structures to the commodity data structures.
It first checks to see if this is necessary since, for the time being, the quote information will still be written out as part of the account. Just in case anyone needs to fall back from CVS to a production version of code.
root | A pointer to the root account containing all accounts in the current book. |
table | A pointer to the commodity table for the current book. |
Definition at line 1345 of file Scrub.cpp.
void xaccLotFill | ( | GNCLot * | lot | ) |
The xaccLotFill() routine attempts to assign splits to the indicated lot until the lot balance goes to zero, or until there are no suitable (i.e.
unassigned) splits left in the account. It uses the default accounting policy to choose the splits to fill out the lot.
Definition at line 92 of file Scrub2.cpp.
void xaccLotScrubDoubleBalance | ( | GNCLot * | lot | ) |
The xaccLotScrubDoubleBalance() routine examines the indicated lot.
If it is open, it does nothing. If it is closed, it then verifies that the lot is 'double balanced'. By 'double balance', we mean that both the sum of the split amounts is zero, and that the sum of the split values is zero. If the lot is closed and the sum of the values is not zero, the lot is considered to have a 'realized gain or loss' that hadn't been correctly handled. This routine then creates a balancing transaction to so as to record the realized gain/loss, adds it to the lot, and adds it to a gain/loss account. If there is no default gain/loss account, it creates one.
Definition at line 160 of file Scrub2.cpp.
gboolean xaccScrubLot | ( | GNCLot * | lot | ) |
The xaccScrubLot() routine makes sure that the indicated lot is self-consistent and properly balanced, and fixes it if its not.
This is an important routine to call if the amount of any split in the lot is changed. That's because (obviously) changing split values is guaranteed to throw off lot balances. This routine may end up closing the lot, or at least trying to. It will also cause cap gains to be recomputed.
Scrubbing the lot may cause subsplits to be merged together, i.e. for splits to be deleted. This routine returns true if any splits were deleted.
Definition at line 85 of file Scrub3.cpp.
gboolean xaccScrubMergeSubSplits | ( | Split * | split, |
gboolean | strict | ||
) |
The xaccScrubMergeSubSplits() routine will merge together all of the splits that were at one time split off from this split, but are no longer needed to be kept separate.
Splits might be split up if they need to be divided over multiple lots; they can be merged back together if the lots change. In particular, two sub-splits may be merged if they are in the same lot, or in no lot. Note that, by definition, all subsplits belong to the same transaction.
There are two ways to find matching subsplits. The first way will consider splits to be subsplits only if they are explicitly marked as such while splitting the original split. Set strict to TRUE for this matching algorithm.
The second way is more relaxed. It will consider any two splits that happen to be part of the same lot and the same transaction to be subsplits. Set strict to FALSE for this matching algorithm.
The routine returns TRUE if a merger was performed, else it returns FALSE.
Definition at line 318 of file Scrub2.cpp.
void xaccSplitScrub | ( | Split * | split | ) |
The xaccSplitScrub method ensures that if this split has the same commodity and currency, then it will have the same amount and value.
If the commodity is the currency, the split->amount is set to the split value. In addition, if this split is an orphan, that is fixed first. If the split account doesn't have a commodity declared, an attempt is made to fix that first.
void xaccTransScrubCurrency | ( | Transaction * | trans | ) |
The xaccTransScrubCurrency method fixes transactions without a common_currency by looking for the most commonly used currency among all the splits in the transaction.
If this fails it falls back to using the old account currency and security fields of the parent accounts of the transaction's splits.
Definition at line 1105 of file Scrub.cpp.
The xaccScrubImbalance() method searches for transactions that do not balance to zero.
If any such transactions are found, a split is created to offset this amount and is added to an "imbalance" account.
The xaccScrubImbalance() method searches for transactions that do not balance to zero.
trans | The Transaction |
root | The (hidden) root account, for the book default currency. |
account | The account whose currency in which to balance. |
Definition at line 829 of file Scrub.cpp.
void xaccTransScrubPostedDate | ( | Transaction * | trans | ) |
Changes Transaction date_posted timestamps from 00:00 local to 11:00 UTC.
11:00 UTC is the same day local time in almost all timezones, the exceptions being the -12, +13, and +14 timezones along the International Date Line. If Local time is set to one of these timezones then the new date_posted time will be adjusted as needed to ensure that the date doesn't change there. This change was made for v2.6.14 to partially resolve bug 137017.
Definition at line 1527 of file Scrub.cpp.