mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
more rigorous transaction commit code shows up buglets in the register;
work around one of these. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@9386 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
b7f1c25c2d
commit
2b6830e50d
@ -221,6 +221,16 @@ xaccSplitScrub (Split *split)
|
||||
account = xaccSplitGetAccount (split);
|
||||
}
|
||||
|
||||
/* Grrr... the register gnc_split_register_load() line 203 of
|
||||
* src/register/ledger-core/split-register-load.c will create
|
||||
* free-floating bogus transactions. Ignore these for now ...
|
||||
*/
|
||||
if (!account)
|
||||
{
|
||||
PINFO ("Free Floating Transaction!");
|
||||
return;
|
||||
}
|
||||
|
||||
currency = xaccTransGetCurrency (trans);
|
||||
|
||||
/* If the account doesn't have a commodity,
|
||||
@ -314,21 +324,27 @@ xaccTransScrubImbalance (Transaction *trans, AccountGroup *root,
|
||||
{
|
||||
Split *balance_split = NULL;
|
||||
gnc_numeric imbalance;
|
||||
Account *account;
|
||||
SplitList *node, *slist;
|
||||
|
||||
if (!trans || !root) return;
|
||||
if (!trans) return;
|
||||
|
||||
xaccTransScrubSplits (trans);
|
||||
|
||||
{
|
||||
Account *account;
|
||||
GList *node;
|
||||
|
||||
/* If the transaction is balanced, nothing more to do */
|
||||
imbalance = xaccTransGetImbalance (trans);
|
||||
if (gnc_numeric_zero_p (imbalance))
|
||||
return;
|
||||
if (gnc_numeric_zero_p (imbalance)) return;
|
||||
|
||||
slist = xaccTransGetSplitList (trans);
|
||||
if (!slist) return;
|
||||
|
||||
if (!parent)
|
||||
{
|
||||
if (!root)
|
||||
{
|
||||
Split *s = slist->data;
|
||||
root = xaccAccountGetRoot (s->acc);
|
||||
}
|
||||
account = xaccScrubUtilityGetOrMakeAccount (root,
|
||||
trans->common_currency, _("Imbalance"));
|
||||
}
|
||||
@ -338,9 +354,12 @@ xaccTransScrubImbalance (Transaction *trans, AccountGroup *root,
|
||||
}
|
||||
|
||||
if (!account)
|
||||
{
|
||||
PERR ("Can't get balancing account");
|
||||
return;
|
||||
}
|
||||
|
||||
for (node = xaccTransGetSplitList (trans); node; node = node->next)
|
||||
for (node = slist; node; node = node->next)
|
||||
{
|
||||
Split *split = node->data;
|
||||
|
||||
@ -351,40 +370,32 @@ xaccTransScrubImbalance (Transaction *trans, AccountGroup *root,
|
||||
}
|
||||
}
|
||||
|
||||
/* put split into account before setting split value */
|
||||
/* Put split into account before setting split value */
|
||||
if (!balance_split)
|
||||
{
|
||||
balance_split = xaccMallocSplit (root->book);
|
||||
balance_split = xaccMallocSplit (trans->book);
|
||||
|
||||
xaccAccountBeginEdit (account);
|
||||
xaccAccountInsertSplit (account, balance_split);
|
||||
xaccAccountCommitEdit (account);
|
||||
}
|
||||
}
|
||||
|
||||
PINFO ("unbalanced transaction");
|
||||
|
||||
{
|
||||
const gnc_commodity *currency;
|
||||
const gnc_commodity *commodity;
|
||||
gboolean trans_was_open;
|
||||
gnc_numeric new_value;
|
||||
Account *account;
|
||||
gnc_numeric old_value, new_value;
|
||||
|
||||
trans_was_open = xaccTransIsOpen (trans);
|
||||
|
||||
if (!trans_was_open)
|
||||
xaccTransBeginEdit (trans);
|
||||
|
||||
currency = xaccTransGetCurrency (trans);
|
||||
account = xaccSplitGetAccount (balance_split);
|
||||
|
||||
new_value = xaccSplitGetValue (balance_split);
|
||||
old_value = xaccSplitGetValue (balance_split);
|
||||
|
||||
/* Note: We have to round for the commodity's fraction, NOT any
|
||||
* already existing denominator (bug #104343), because either one
|
||||
* of the denominators might already be reduced. */
|
||||
new_value = gnc_numeric_sub (new_value, imbalance,
|
||||
new_value = gnc_numeric_sub (old_value, imbalance,
|
||||
gnc_commodity_get_fraction(currency),
|
||||
GNC_RND_ROUND);
|
||||
|
||||
@ -392,20 +403,12 @@ xaccTransScrubImbalance (Transaction *trans, AccountGroup *root,
|
||||
|
||||
commodity = xaccAccountGetCommodity (account);
|
||||
if (gnc_commodity_equiv (currency, commodity))
|
||||
xaccSplitSetAmount (balance_split, new_value);
|
||||
|
||||
if (!parent && gnc_numeric_zero_p (new_value))
|
||||
{
|
||||
xaccSplitDestroy (balance_split);
|
||||
balance_split = NULL;
|
||||
xaccSplitSetAmount (balance_split, new_value);
|
||||
}
|
||||
|
||||
if (balance_split)
|
||||
xaccTransAppendSplit (trans, balance_split);
|
||||
|
||||
xaccSplitScrub (balance_split);
|
||||
|
||||
if (!trans_was_open)
|
||||
xaccTransCommitEdit (trans);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user