From f7f42bf6fbadde06bce40c506c0fb75eea09f3bb Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Thu, 16 May 2024 12:18:08 +0200 Subject: [PATCH] Bug 799279 - Import Matcher (CSV) does not compute correctly the share amount based on security price - part 2 Do proper conversion based on entered exchange rate. --- gnucash/import-export/import-main-matcher.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/gnucash/import-export/import-main-matcher.cpp b/gnucash/import-export/import-main-matcher.cpp index 9f1997fe00..bcbb1d7469 100644 --- a/gnucash/import-export/import-main-matcher.cpp +++ b/gnucash/import-export/import-main-matcher.cpp @@ -1138,8 +1138,17 @@ gnc_gen_trans_set_price_to_selection_cb (GtkMenuItem *menuitem, if (!gnc_xfer_dialog_run_until_done(xfer)) break; /* If the user cancels, return to the payment dialog without changes */ - gnc_import_TransInfo_set_price (row.get_trans_info (), exch); - refresh_model_row (info, model, row.get_iter(), row.get_trans_info()); + + /* Note the exchange rate we received is backwards from what we really need: + * it converts value to amount, but the remainder of the code expects + * an exchange rate that converts from amount to value. So let's invert + * the result (though only if that doesn't result in a division by 0). */ + if (!gnc_numeric_zero_p(exch)) + { + gnc_import_TransInfo_set_price (row.get_trans_info (), + gnc_numeric_invert(exch)); + refresh_model_row (info, model, row.get_iter(), row.get_trans_info()); + } } g_list_free_full (selected_rows, (GDestroyNotify)gtk_tree_path_free); LEAVE("");