Reorder the create price procedure.

This commit is contained in:
Robert Fewell 2017-12-01 11:56:25 +00:00
parent 62bbe4f951
commit 644a0aa06f

View File

@ -362,32 +362,10 @@ Result GncImportPrice::create_price (QofBook* book, GNCPriceDB *pdb, bool over)
bool rev = false; bool rev = false;
auto amount = *m_amount; auto amount = *m_amount;
Result ret_val = ADDED;
GNCPrice *old_price = gnc_pricedb_lookup_day (pdb, *m_from_commodity, *m_to_currency, date); 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 // Should old price be over writen
if ((old_price != nullptr) && (over == true)) if ((old_price != nullptr) && (over == true))
{ {
@ -398,6 +376,26 @@ Result GncImportPrice::create_price (QofBook* book, GNCPriceDB *pdb, bool over)
ret_val = REPLACED; 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 // Create the new price
if (old_price == nullptr) if (old_price == nullptr)
{ {