mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Move one data-validation function from Scrub.c into Transaction.c
One simplification in xaccTransScrubImbalance() to always find the root AccountGroup from the Transaction's book. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13460 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
7bad37599c
commit
dd80eaa743
@ -103,9 +103,7 @@ TransScrubOrphansFast (Transaction *trans, AccountGroup *root)
|
|||||||
orph = xaccScrubUtilityGetOrMakeAccount (root, trans->common_currency, _("Orphan"));
|
orph = xaccScrubUtilityGetOrMakeAccount (root, trans->common_currency, _("Orphan"));
|
||||||
if (!orph) continue;
|
if (!orph) continue;
|
||||||
|
|
||||||
xaccAccountBeginEdit (orph);
|
xaccSplitSetAccount(split, orph);
|
||||||
xaccAccountInsertSplit (orph, split);
|
|
||||||
xaccAccountCommitEdit (orph);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,27 +193,6 @@ xaccAccountScrubSplits (Account *account)
|
|||||||
xaccSplitScrub (node->data);
|
xaccSplitScrub (node->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
xaccTransScrubSplits (Transaction *trans)
|
|
||||||
{
|
|
||||||
gnc_commodity *currency;
|
|
||||||
GList *node;
|
|
||||||
|
|
||||||
if (!trans) return;
|
|
||||||
|
|
||||||
/* The split scrub expects the transaction to have a currency! */
|
|
||||||
currency = xaccTransGetCurrency (trans);
|
|
||||||
if (!currency)
|
|
||||||
{
|
|
||||||
PERR ("Transaction doesn't have a currency!");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (node = trans->splits; node; node = node->next)
|
|
||||||
{
|
|
||||||
xaccSplitScrub (node->data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
xaccSplitScrub (Split *split)
|
xaccSplitScrub (Split *split)
|
||||||
{
|
{
|
||||||
@ -233,7 +210,7 @@ xaccSplitScrub (Split *split)
|
|||||||
|
|
||||||
account = xaccSplitGetAccount (split);
|
account = xaccSplitGetAccount (split);
|
||||||
|
|
||||||
/* If theres no account, this split is an orphan.
|
/* If there's no account, this split is an orphan.
|
||||||
* We need to fix that first, before proceeding.
|
* We need to fix that first, before proceeding.
|
||||||
*/
|
*/
|
||||||
if (!account)
|
if (!account)
|
||||||
@ -421,46 +398,28 @@ xaccTransScrubCurrencyFromSplits(Transaction *trans)
|
|||||||
|
|
||||||
void
|
void
|
||||||
xaccTransScrubImbalance (Transaction *trans, AccountGroup *root,
|
xaccTransScrubImbalance (Transaction *trans, AccountGroup *root,
|
||||||
Account *parent)
|
Account *account)
|
||||||
{
|
{
|
||||||
Split *balance_split = NULL;
|
Split *balance_split = NULL;
|
||||||
QofBook *book = NULL;
|
|
||||||
gnc_numeric imbalance;
|
gnc_numeric imbalance;
|
||||||
Account *account;
|
|
||||||
SplitList *node, *slist;
|
|
||||||
|
|
||||||
if (!trans) return;
|
if (!trans) return;
|
||||||
|
|
||||||
ENTER ("()");
|
ENTER ("()");
|
||||||
xaccTransScrubSplits (trans);
|
|
||||||
|
|
||||||
/* If the transaction is balanced, nothing more to do */
|
/* If the transaction is balanced, nothing more to do */
|
||||||
imbalance = xaccTransGetImbalance (trans);
|
imbalance = xaccTransGetImbalance (trans);
|
||||||
if (gnc_numeric_zero_p (imbalance)) return;
|
if (gnc_numeric_zero_p (imbalance)) return;
|
||||||
|
|
||||||
slist = xaccTransGetSplitList (trans);
|
xaccTransBeginEdit(trans);
|
||||||
if (!slist) return;
|
xaccTransScrubSplits (trans);
|
||||||
|
xaccTransCommitEdit(trans);
|
||||||
|
|
||||||
if (!parent)
|
if (!account)
|
||||||
{
|
{
|
||||||
if (!root)
|
if (!root)
|
||||||
{
|
{
|
||||||
Split *s = slist->data;
|
root = xaccGetAccountGroup (xaccTransGetBook (trans));
|
||||||
if (NULL == s->acc)
|
|
||||||
{
|
|
||||||
/* This should never occur, since xaccTransScrubSplits()
|
|
||||||
* above should have fixed things up. */
|
|
||||||
PERR ("Split is not assigned to any account");
|
|
||||||
}
|
|
||||||
root = xaccAccountGetRoot (s->acc);
|
|
||||||
if (NULL == root)
|
|
||||||
{
|
|
||||||
/* This should never occur, accounts are always
|
|
||||||
* in an account group */
|
|
||||||
PERR ("Can't find root account");
|
|
||||||
book = xaccTransGetBook (trans);
|
|
||||||
root = xaccGetAccountGroup (book);
|
|
||||||
}
|
|
||||||
if (NULL == root)
|
if (NULL == root)
|
||||||
{
|
{
|
||||||
/* This can't occur, things should be in books */
|
/* This can't occur, things should be in books */
|
||||||
@ -470,37 +429,23 @@ xaccTransScrubImbalance (Transaction *trans, AccountGroup *root,
|
|||||||
}
|
}
|
||||||
account = xaccScrubUtilityGetOrMakeAccount (root,
|
account = xaccScrubUtilityGetOrMakeAccount (root,
|
||||||
trans->common_currency, _("Imbalance"));
|
trans->common_currency, _("Imbalance"));
|
||||||
}
|
if (!account) {
|
||||||
else
|
PERR ("Can't get balancing account");
|
||||||
{
|
return;
|
||||||
account = parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!account)
|
|
||||||
{
|
|
||||||
PERR ("Can't get balancing account");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (node = slist; node; node = node->next)
|
|
||||||
{
|
|
||||||
Split *split = node->data;
|
|
||||||
|
|
||||||
if (xaccSplitGetAccount (split) == account)
|
|
||||||
{
|
|
||||||
balance_split = split;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
balance_split = xaccTransFindSplitByAccount(trans, account);
|
||||||
|
|
||||||
/* Put split into account before setting split value */
|
/* Put split into account before setting split value */
|
||||||
if (!balance_split)
|
if (!balance_split)
|
||||||
{
|
{
|
||||||
balance_split = xaccMallocSplit (trans->inst.book);
|
balance_split = xaccMallocSplit (trans->inst.book);
|
||||||
|
|
||||||
xaccAccountBeginEdit (account);
|
xaccTransBeginEdit (trans);
|
||||||
xaccAccountInsertSplit (account, balance_split);
|
xaccSplitSetParent(balance_split, trans);
|
||||||
xaccAccountCommitEdit (account);
|
xaccSplitSetAccount(balance_split, account);
|
||||||
|
xaccTransCommitEdit (trans);
|
||||||
}
|
}
|
||||||
|
|
||||||
PINFO ("unbalanced transaction");
|
PINFO ("unbalanced transaction");
|
||||||
@ -530,7 +475,6 @@ xaccTransScrubImbalance (Transaction *trans, AccountGroup *root,
|
|||||||
xaccSplitSetAmount (balance_split, new_value);
|
xaccSplitSetAmount (balance_split, new_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
xaccTransAppendSplit (trans, balance_split);
|
|
||||||
xaccSplitScrub (balance_split);
|
xaccSplitScrub (balance_split);
|
||||||
xaccTransCommitEdit (trans);
|
xaccTransCommitEdit (trans);
|
||||||
}
|
}
|
||||||
@ -666,7 +610,7 @@ xaccTransScrubCurrency (Transaction *trans)
|
|||||||
|
|
||||||
/* If there are any orphaned splits in a transaction, then the
|
/* If there are any orphaned splits in a transaction, then the
|
||||||
* this routine will fail. Therefore, we want to make sure that
|
* this routine will fail. Therefore, we want to make sure that
|
||||||
* tehre are no orphans (splits without parent account).
|
* there are no orphans (splits without parent account).
|
||||||
*/
|
*/
|
||||||
xaccTransScrubOrphans (trans);
|
xaccTransScrubOrphans (trans);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user