add code to make sure that split amount and value are valid numbers.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@10174 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 2004-07-07 02:59:28 +00:00
parent 8ac1f54b9f
commit 922d18d706

View File

@ -198,13 +198,22 @@ xaccAccountScrubSplits (Account *account)
void void
xaccTransScrubSplits (Transaction *trans) xaccTransScrubSplits (Transaction *trans)
{ {
gnc_commodity *currency;
GList *node; GList *node;
if (!trans) if (!trans) return;
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) for (node = trans->splits; node; node = node->next)
{
xaccSplitScrub (node->data); xaccSplitScrub (node->data);
}
} }
void void
@ -212,7 +221,7 @@ xaccSplitScrub (Split *split)
{ {
Account *account; Account *account;
Transaction *trans; Transaction *trans;
gnc_numeric value; gnc_numeric value, amount;
gnc_commodity *currency; gnc_commodity *currency;
int scu; int scu;
@ -243,6 +252,21 @@ xaccSplitScrub (Split *split)
return; return;
} }
/* Split amounts and values should be valid numbers */
value = xaccSplitGetValue (split);
if (gnc_numeric_check (value))
{
value = gnc_numeric_zero();
xaccSplitSetValue (split, value);
}
amount = xaccSplitGetAmount (split);
if (gnc_numeric_check (amount))
{
amount = gnc_numeric_zero();
xaccSplitSetAmount (split, amount);
}
currency = xaccTransGetCurrency (trans); currency = xaccTransGetCurrency (trans);
/* If the account doesn't have a commodity, /* If the account doesn't have a commodity,
@ -262,10 +286,7 @@ xaccSplitScrub (Split *split)
scu = MIN (xaccAccountGetCommoditySCU (account), scu = MIN (xaccAccountGetCommoditySCU (account),
gnc_commodity_get_fraction (currency)); gnc_commodity_get_fraction (currency));
value = xaccSplitGetValue (split); if (gnc_numeric_same (amount, value, scu, GNC_HOW_RND_ROUND))
if (gnc_numeric_same (xaccSplitGetAmount (split),
value, scu, GNC_HOW_RND_ROUND))
{ {
return; return;
} }