mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
clean up test generator to produce self-consistent data.
I make these changes with some trepidation, since this puts a whole lot less stress on the 'scrub' infrastructure. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@10167 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
5ac7a28aa8
commit
a069fe265f
@ -1005,24 +1005,47 @@ set_tran_random_string(Transaction* trn,
|
|||||||
static void
|
static void
|
||||||
add_random_splits(QofBook *book, Transaction *trn, GList *account_list)
|
add_random_splits(QofBook *book, Transaction *trn, GList *account_list)
|
||||||
{
|
{
|
||||||
Account *account;
|
Account *acc, *bcc;
|
||||||
Split *s;
|
Split *s;
|
||||||
|
|
||||||
|
/* Gotta have at least two different accounts */
|
||||||
|
if (1 >= g_list_length (account_list)) return;
|
||||||
|
|
||||||
/* Set up two splits whose values really are opposites. */
|
/* Set up two splits whose values really are opposites. */
|
||||||
gnc_commodity *com = xaccTransGetCurrency (trn);
|
gnc_commodity *com = xaccTransGetCurrency (trn);
|
||||||
int scu = gnc_commodity_get_fraction(com);
|
int scu = gnc_commodity_get_fraction(com);
|
||||||
gnc_numeric num = get_random_gnc_numeric();
|
gnc_numeric num = get_random_gnc_numeric();
|
||||||
num = gnc_numeric_convert (num, scu, GNC_HOW_RND_ROUND);
|
num = gnc_numeric_convert (num, scu, GNC_HOW_RND_ROUND);
|
||||||
|
|
||||||
account = get_random_list_element (account_list);
|
acc = get_random_list_element (account_list);
|
||||||
s = get_random_split(book, account);
|
s = get_random_split(book, acc);
|
||||||
xaccTransAppendSplit(trn, s);
|
xaccTransAppendSplit(trn, s);
|
||||||
xaccSplitSetValue(s, num);
|
xaccSplitSetValue(s, num);
|
||||||
|
|
||||||
account = get_random_list_element (account_list);
|
if (gnc_commodity_equal (xaccTransGetCurrency(trn),
|
||||||
s = get_random_split(book, account);
|
xaccAccountGetCommodity(acc)))
|
||||||
|
{
|
||||||
|
xaccSplitSetAmount(s, num);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Make sure that each side of the transaction is in
|
||||||
|
* a different account; otherwise get weirdness in lot
|
||||||
|
* calculcations. ... Hmm maybe should fix lots in
|
||||||
|
* this case? */
|
||||||
|
do {
|
||||||
|
bcc = get_random_list_element (account_list);
|
||||||
|
} while (bcc == acc);
|
||||||
|
|
||||||
|
s = get_random_split(book, bcc);
|
||||||
xaccTransAppendSplit(trn, s);
|
xaccTransAppendSplit(trn, s);
|
||||||
xaccSplitSetValue(s, gnc_numeric_neg(num));
|
xaccSplitSetValue(s, gnc_numeric_neg(num));
|
||||||
|
|
||||||
|
if (gnc_commodity_equal (xaccTransGetCurrency(trn),
|
||||||
|
xaccAccountGetCommodity(bcc)))
|
||||||
|
{
|
||||||
|
xaccSplitSetAmount(s, num);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
Reference in New Issue
Block a user