From 644a0aa06f09c49a99dd013f25c74af999f4fc46 Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Fri, 1 Dec 2017 11:56:25 +0000 Subject: [PATCH] Reorder the create price procedure. --- .../import-export/csv-imp/gnc-price-props.cpp | 44 +++++++++---------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/gnucash/import-export/csv-imp/gnc-price-props.cpp b/gnucash/import-export/csv-imp/gnc-price-props.cpp index 0ea21f9773..539f316851 100644 --- a/gnucash/import-export/csv-imp/gnc-price-props.cpp +++ b/gnucash/import-export/csv-imp/gnc-price-props.cpp @@ -362,32 +362,10 @@ Result GncImportPrice::create_price (QofBook* book, GNCPriceDB *pdb, bool over) bool rev = false; auto amount = *m_amount; + Result ret_val = ADDED; GNCPrice *old_price = gnc_pricedb_lookup_day (pdb, *m_from_commodity, *m_to_currency, date); - if (gnc_commodity_is_currency (*m_from_commodity)) // Currency Import - { - // Check for currency in reverse direction. - if (old_price != nullptr) - { - // Check for price in reverse direction. - if (gnc_commodity_equiv (gnc_price_get_currency (old_price), *m_from_commodity)) - rev = true; - - DEBUG("Commodity from is a Currency"); - } - - // Check for price less than 1, reverse if so. - if (*m_amount < GncNumeric(1,1)) - rev = true; - - } - DEBUG("Date is %s, Rev is %d, Commodity from is '%s', Currency is '%s', Amount is %s", gnc_print_date (date), - rev, gnc_commodity_get_fullname (*m_from_commodity), gnc_commodity_get_fullname (*m_to_currency), - amount.to_string().c_str()); - - Result ret_val = ADDED; - // Should old price be over writen if ((old_price != nullptr) && (over == true)) { @@ -398,6 +376,26 @@ Result GncImportPrice::create_price (QofBook* book, GNCPriceDB *pdb, bool over) ret_val = REPLACED; } + if (gnc_commodity_is_currency (*m_from_commodity)) // Currency Import + { + // Check for currency in reverse direction. + if (old_price != nullptr) + { + // Check for price in reverse direction. + if (gnc_commodity_equiv (gnc_price_get_currency (old_price), *m_from_commodity)) + rev = true; + } + DEBUG("Commodity from is a Currency"); + + // Check for price less than 1, reverse if so. + if (*m_amount < GncNumeric(1,1)) + rev = true; + + } + DEBUG("Date is %s, Rev is %d, Commodity from is '%s', Currency is '%s', Amount is %s", gnc_print_date (date), + rev, gnc_commodity_get_fullname (*m_from_commodity), gnc_commodity_get_fullname (*m_to_currency), + amount.to_string().c_str()); + // Create the new price if (old_price == nullptr) {