mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Bug 796955 - Import CSV - Single-line two-currency transactions can't be imported
Calculation using price from csv data was still backwards. This commit fixes it.
This commit is contained in:
parent
27764908e6
commit
fb8c0ab039
@ -720,9 +720,9 @@ void GncPreSplit::create_split (std::shared_ptr<DraftTransaction> draft_trans)
|
||||
auto trans_curr = xaccTransGetCurrency(draft_trans->trans);
|
||||
auto acct_comm = xaccAccountGetCommodity(taccount);
|
||||
if (gnc_commodity_equiv(trans_curr, acct_comm))
|
||||
tamount = -amount;
|
||||
tamount = tvalue;
|
||||
else if (m_price)
|
||||
tamount = -amount * *m_price;
|
||||
tamount = tvalue * m_price->inv();
|
||||
else
|
||||
{
|
||||
QofBook* book = xaccTransGetBook (draft_trans->trans);
|
||||
@ -733,14 +733,13 @@ void GncPreSplit::create_split (std::shared_ptr<DraftTransaction> draft_trans)
|
||||
acct_comm, trans_curr, time);
|
||||
if (nprice)
|
||||
{
|
||||
/* Found a usable price. Let's check if the conversion direction is right */
|
||||
GncNumeric rate;
|
||||
/* Found a usable price. Let's check if the conversion direction is right
|
||||
* Reminder: value = amount * price, or amount = value / price */
|
||||
GncNumeric rate = gnc_price_get_value(nprice);
|
||||
if (gnc_commodity_equiv(gnc_price_get_currency(nprice), trans_curr))
|
||||
rate = gnc_price_get_value(nprice);
|
||||
tamount = tvalue * rate.inv();
|
||||
else
|
||||
rate = static_cast<GncNumeric>(gnc_price_get_value(nprice)).inv();
|
||||
|
||||
tamount = -amount * rate;
|
||||
tamount = tvalue * rate;
|
||||
}
|
||||
else
|
||||
PWARN("No price found, defer creation of second split to generic import matcher.");
|
||||
|
@ -1117,9 +1117,11 @@ static void trans_info_calculate_dest_amount (GNCImportTransInfo *info)
|
||||
}
|
||||
else if (gnc_numeric_check(info->lsplit_price) == 0)
|
||||
{
|
||||
/* We are in a multi currency situation and have a valid price */
|
||||
/* We are in a multi currency situation and have a valid price
|
||||
* Reminder: value = amount * price => amount = value / price */
|
||||
gnc_numeric inv_price = gnc_numeric_invert (info->lsplit_price);
|
||||
info->lsplit_amount = gnc_numeric_mul (info->lsplit_value,
|
||||
info->lsplit_price,
|
||||
inv_price,
|
||||
GNC_DENOM_AUTO,
|
||||
GNC_HOW_RND_ROUND_HALF_UP);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user