mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Bug#333532: Add multi-commodity SX support.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13509 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
2f97e55f9f
commit
3ffc0a28a5
@ -1,5 +1,8 @@
|
||||
2006-03-06 Joshua Sled <jsled@asynchronous.org>
|
||||
|
||||
* src/gnome/dialog-sxsincelast.c (create_each_transaction_helper):
|
||||
Add multi-commodity SX support. Bug#333532.
|
||||
|
||||
* packaging/gnucash-1.9.x.ebuild (SRC_URI): Mods for ebuild to be
|
||||
used as an SVN ebuild.
|
||||
|
||||
|
@ -2449,7 +2449,7 @@ create_each_transaction_helper( Transaction *t, void *d )
|
||||
gboolean errFlag;
|
||||
createData *createUD;
|
||||
toCreateInstance *tci;
|
||||
gnc_commodity *commonCommodity = NULL;
|
||||
gnc_commodity *first_cmdty = NULL;
|
||||
GHashTable *actualVars;
|
||||
gnc_numeric *varIValue;
|
||||
|
||||
@ -2506,6 +2506,7 @@ create_each_transaction_helper( Transaction *t, void *d )
|
||||
for ( ; sList && osList; sList = sList->next, osList = osList->next)
|
||||
{
|
||||
Account *acct;
|
||||
gnc_commodity *split_cmdty = NULL;
|
||||
|
||||
split = (Split*)sList->data;
|
||||
|
||||
@ -2548,20 +2549,13 @@ create_each_transaction_helper( Transaction *t, void *d )
|
||||
break;
|
||||
}
|
||||
|
||||
if ( commonCommodity != NULL ) {
|
||||
if ( commonCommodity != xaccAccountGetCommodity( acct ) ) {
|
||||
GString *err = g_string_new("");
|
||||
g_string_printf(err, "Common-commodity difference for SX [%s]: old=[%s], new=[%s]\n",
|
||||
xaccSchedXactionGetName(createUD->tci->parentTCT->sx),
|
||||
gnc_commodity_get_mnemonic(commonCommodity),
|
||||
gnc_commodity_get_mnemonic(xaccAccountGetCommodity(acct)));
|
||||
*createUD->creation_errors = g_list_append(*createUD->creation_errors, err);
|
||||
}
|
||||
}
|
||||
else
|
||||
split_cmdty = xaccAccountGetCommodity(acct);
|
||||
if (first_cmdty == NULL)
|
||||
{
|
||||
commonCommodity = xaccAccountGetCommodity( acct );
|
||||
first_cmdty = split_cmdty;
|
||||
xaccTransSetCurrency(newT, first_cmdty);
|
||||
}
|
||||
|
||||
xaccAccountBeginEdit(acct);
|
||||
xaccAccountInsertSplit(acct, split);
|
||||
}
|
||||
@ -2626,10 +2620,46 @@ create_each_transaction_helper( Transaction *t, void *d )
|
||||
final = gnc_numeric_create(0, 1);
|
||||
}
|
||||
|
||||
xaccSplitSetValue( split, final );
|
||||
xaccSplitSetValue(split, final);
|
||||
if (! gnc_commodity_equal(split_cmdty, first_cmdty))
|
||||
{
|
||||
GNCPriceDB *price_db = gnc_pricedb_get_db(gnc_get_current_book());
|
||||
GNCPrice *price;
|
||||
gnc_numeric exchange, amt;
|
||||
|
||||
price = gnc_pricedb_lookup_latest(price_db, first_cmdty, split_cmdty);
|
||||
if (price == NULL)
|
||||
{
|
||||
price = gnc_pricedb_lookup_latest(price_db, split_cmdty, first_cmdty);
|
||||
if (price == NULL)
|
||||
{
|
||||
GString *err = g_string_new("");
|
||||
g_string_printf(err, "could not find pricedb entry for commodity-pair (%s, %s).",
|
||||
gnc_commodity_get_mnemonic(first_cmdty),
|
||||
gnc_commodity_get_mnemonic(split_cmdty));
|
||||
exchange = gnc_numeric_create(1, 1);
|
||||
*createUD->creation_errors = g_list_append(*createUD->creation_errors, err);
|
||||
}
|
||||
else
|
||||
{
|
||||
exchange = gnc_numeric_div(gnc_numeric_create(1,1),
|
||||
gnc_price_get_value(price),
|
||||
1000, GNC_HOW_RND_ROUND);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
exchange = gnc_price_get_value(price);
|
||||
}
|
||||
|
||||
amt = gnc_numeric_mul(final,
|
||||
exchange,
|
||||
1000,
|
||||
GNC_HOW_RND_ROUND);
|
||||
xaccSplitSetAmount(split, amt);
|
||||
}
|
||||
xaccSplitScrub( split );
|
||||
}
|
||||
|
||||
xaccAccountCommitEdit( acct );
|
||||
}
|
||||
|
||||
@ -2642,15 +2672,6 @@ create_each_transaction_helper( Transaction *t, void *d )
|
||||
actualVars = NULL;
|
||||
}
|
||||
|
||||
if (commonCommodity == NULL) {
|
||||
GString *err = g_string_new("");
|
||||
g_string_printf(err, "Unable to find common currency/commodity for SX [%s]; using default.",
|
||||
xaccSchedXactionGetName(createUD->tci->parentTCT->sx));
|
||||
*createUD->creation_errors = g_list_append(*createUD->creation_errors, err);
|
||||
commonCommodity = gnc_default_currency();
|
||||
}
|
||||
xaccTransSetCurrency(newT, commonCommodity);
|
||||
|
||||
if (errFlag) {
|
||||
PERR("Some error in new transaction creation...");
|
||||
xaccTransDestroy(newT);
|
||||
|
Loading…
Reference in New Issue
Block a user