diff --git a/gnucash/import-export/csv-imp/gnc-price-import.cpp b/gnucash/import-export/csv-imp/gnc-price-import.cpp index 705d37ccb4..61c876de90 100644 --- a/gnucash/import-export/csv-imp/gnc-price-import.cpp +++ b/gnucash/import-export/csv-imp/gnc-price-import.cpp @@ -649,15 +649,13 @@ void GncPriceImport::update_price_props (uint32_t row, uint32_t col, GncPricePro return; /* Only deal with price related properties. */ auto price_props = std::make_shared (*(std::get<2>(m_parsed_lines[row])).get()); - auto value = std::string(); - if (col < std::get<0>(m_parsed_lines[row]).size()) - value = std::get<0>(m_parsed_lines[row]).at(col); - - if (value.empty()) - price_props->reset (prop_type); + if (col >= std::get<0>(m_parsed_lines[row]).size()) + price_props->reset (prop_type); //reset errors else { + auto value = std::get<0>(m_parsed_lines[row]).at(col); + bool enable_test_empty = true; try { // set the from_commodity based on combo so we can test for same. @@ -665,14 +663,20 @@ void GncPriceImport::update_price_props (uint32_t row, uint32_t col, GncPricePro { if (m_settings.m_from_commodity) price_props->set_from_commodity (m_settings.m_from_commodity); + + if (m_settings.m_to_currency) + enable_test_empty = false; } // set the to_currency based on combo so we can test for same. if (prop_type == GncPricePropType::FROM_COMMODITY) { if (m_settings.m_to_currency) price_props->set_to_currency (m_settings.m_to_currency); + + if (m_settings.m_from_commodity) + enable_test_empty = false; } - price_props->set(prop_type, value); + price_props->set(prop_type, value, enable_test_empty); } catch (const std::exception& e) { diff --git a/gnucash/import-export/csv-imp/gnc-price-props.cpp b/gnucash/import-export/csv-imp/gnc-price-props.cpp index 1ccd6e50af..151bd38ad2 100644 --- a/gnucash/import-export/csv-imp/gnc-price-props.cpp +++ b/gnucash/import-export/csv-imp/gnc-price-props.cpp @@ -135,13 +135,17 @@ gnc_commodity* parse_commodity_price_comm (const std::string& comm_str) return comm; } -void GncImportPrice::set (GncPricePropType prop_type, const std::string& value) +void GncImportPrice::set (GncPricePropType prop_type, const std::string& value, bool enable_test_empty) { try { // Drop any existing error for the prop_type we're about to set m_errors.erase(prop_type); + // conditional test for empty values + if (value.empty() && enable_test_empty) + throw std::invalid_argument (_("Column value can not be empty.")); + gnc_commodity *comm = nullptr; switch (prop_type) { @@ -207,7 +211,8 @@ void GncImportPrice::reset (GncPricePropType prop_type) { try { - set (prop_type, std::string()); + // set enable_test_empty to false to allow empty values + set (prop_type, std::string(), false); } catch (...) { diff --git a/gnucash/import-export/csv-imp/gnc-price-props.hpp b/gnucash/import-export/csv-imp/gnc-price-props.hpp index 77e39dc689..3a358612af 100644 --- a/gnucash/import-export/csv-imp/gnc-price-props.hpp +++ b/gnucash/import-export/csv-imp/gnc-price-props.hpp @@ -86,7 +86,7 @@ public: GncImportPrice (int date_format, int currency_format) : m_date_format{date_format}, m_currency_format{currency_format}{}; - void set (GncPricePropType prop_type, const std::string& value); + void set (GncPricePropType prop_type, const std::string& value, bool enable_test_empty); void set_date_format (int date_format) { m_date_format = date_format ;} void set_currency_format (int currency_format) { m_currency_format = currency_format ;} void reset (GncPricePropType prop_type);