mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Add a test for empty values
Some csv values are allowed to be empty based on options selected so add a test for this otherwise all values are required.
This commit is contained in:
parent
16714a8c5b
commit
288563c25e
@ -649,15 +649,13 @@ void GncPriceImport::update_price_props (uint32_t row, uint32_t col, GncPricePro
|
|||||||
return; /* Only deal with price related properties. */
|
return; /* Only deal with price related properties. */
|
||||||
|
|
||||||
auto price_props = std::make_shared<GncImportPrice> (*(std::get<2>(m_parsed_lines[row])).get());
|
auto price_props = std::make_shared<GncImportPrice> (*(std::get<2>(m_parsed_lines[row])).get());
|
||||||
auto value = std::string();
|
|
||||||
|
|
||||||
if (col < std::get<0>(m_parsed_lines[row]).size())
|
if (col >= std::get<0>(m_parsed_lines[row]).size())
|
||||||
value = std::get<0>(m_parsed_lines[row]).at(col);
|
price_props->reset (prop_type); //reset errors
|
||||||
|
|
||||||
if (value.empty())
|
|
||||||
price_props->reset (prop_type);
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
auto value = std::get<0>(m_parsed_lines[row]).at(col);
|
||||||
|
bool enable_test_empty = true;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// set the from_commodity based on combo so we can test for same.
|
// 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)
|
if (m_settings.m_from_commodity)
|
||||||
price_props->set_from_commodity (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.
|
// set the to_currency based on combo so we can test for same.
|
||||||
if (prop_type == GncPricePropType::FROM_COMMODITY)
|
if (prop_type == GncPricePropType::FROM_COMMODITY)
|
||||||
{
|
{
|
||||||
if (m_settings.m_to_currency)
|
if (m_settings.m_to_currency)
|
||||||
price_props->set_to_currency (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)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
|
@ -135,13 +135,17 @@ gnc_commodity* parse_commodity_price_comm (const std::string& comm_str)
|
|||||||
return comm;
|
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
|
try
|
||||||
{
|
{
|
||||||
// Drop any existing error for the prop_type we're about to set
|
// Drop any existing error for the prop_type we're about to set
|
||||||
m_errors.erase(prop_type);
|
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;
|
gnc_commodity *comm = nullptr;
|
||||||
switch (prop_type)
|
switch (prop_type)
|
||||||
{
|
{
|
||||||
@ -207,7 +211,8 @@ void GncImportPrice::reset (GncPricePropType prop_type)
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
set (prop_type, std::string());
|
// set enable_test_empty to false to allow empty values
|
||||||
|
set (prop_type, std::string(), false);
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
|
@ -86,7 +86,7 @@ public:
|
|||||||
GncImportPrice (int date_format, int currency_format) : m_date_format{date_format},
|
GncImportPrice (int date_format, int currency_format) : m_date_format{date_format},
|
||||||
m_currency_format{currency_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_date_format (int date_format) { m_date_format = date_format ;}
|
||||||
void set_currency_format (int currency_format) { m_currency_format = currency_format ;}
|
void set_currency_format (int currency_format) { m_currency_format = currency_format ;}
|
||||||
void reset (GncPricePropType prop_type);
|
void reset (GncPricePropType prop_type);
|
||||||
|
Loading…
Reference in New Issue
Block a user