Skip to content

Commit

Permalink
Bug 796955 - Import CSV - Single-line two-currency transactions can't…
Browse files Browse the repository at this point in the history
… be imported

Calculation using price from csv data was still backwards.
This commit fixes it.
  • Loading branch information
gjanssens committed Feb 7, 2023
1 parent 2776490 commit fb8c0ab
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
15 changes: 7 additions & 8 deletions gnucash/import-export/csv-imp/gnc-imp-props-tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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.");
Expand Down
6 changes: 4 additions & 2 deletions gnucash/import-export/import-backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit fb8c0ab

Please sign in to comment.