mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Bug 798292 - csv Import Transactions Ignores Multi-Splits
This requires GncPreTrans objects to be aware of the multi_split preference to be able to estimate whether empty date or description fields should be flagged as error or not.
This commit is contained in:
parent
7670068778
commit
4e6637e67e
@ -218,7 +218,12 @@ void GncPreTrans::set (GncTransPropType prop_type, const std::string& value)
|
||||
|
||||
case GncTransPropType::DATE:
|
||||
m_date = boost::none;
|
||||
m_date = GncDate(value, GncDate::c_formats[m_date_format].m_fmt); // Throws if parsing fails
|
||||
if (!value.empty())
|
||||
m_date = GncDate(value, GncDate::c_formats[m_date_format].m_fmt); // Throws if parsing fails
|
||||
else if (!m_multi_split)
|
||||
throw std::invalid_argument (
|
||||
(bl::format (std::string{_("Date field can not be empty if 'Multi-split' option is unset.\n")}) %
|
||||
std::string{_(gnc_csv_col_type_strs[prop_type])}).str());
|
||||
break;
|
||||
|
||||
case GncTransPropType::NUM:
|
||||
@ -231,6 +236,10 @@ void GncPreTrans::set (GncTransPropType prop_type, const std::string& value)
|
||||
m_desc = boost::none;
|
||||
if (!value.empty())
|
||||
m_desc = value;
|
||||
else if (!m_multi_split)
|
||||
throw std::invalid_argument (
|
||||
(bl::format (std::string{_("Description field can not be empty if 'Multi-split' option is unset.\n")}) %
|
||||
std::string{_(gnc_csv_col_type_strs[prop_type])}).str());
|
||||
break;
|
||||
|
||||
case GncTransPropType::NOTES:
|
||||
|
@ -108,10 +108,12 @@ GncNumeric parse_monetary (const std::string &str, int currency_format);
|
||||
struct GncPreTrans
|
||||
{
|
||||
public:
|
||||
GncPreTrans(int date_format) : m_date_format{date_format} {};
|
||||
GncPreTrans(int date_format, bool multi_split)
|
||||
: m_date_format{date_format}, m_multi_split{multi_split} {};
|
||||
|
||||
void set (GncTransPropType prop_type, const std::string& value);
|
||||
void set_date_format (int date_format) { m_date_format = date_format ;}
|
||||
void set_multi_split (bool multi_split) { m_multi_split = multi_split ;}
|
||||
void reset (GncTransPropType prop_type);
|
||||
std::string verify_essentials (void);
|
||||
Transaction *create_trans (QofBook* book, gnc_commodity* currency);
|
||||
@ -136,6 +138,7 @@ public:
|
||||
|
||||
private:
|
||||
int m_date_format;
|
||||
bool m_multi_split;
|
||||
boost::optional<std::string> m_differ;
|
||||
boost::optional<GncDate> m_date;
|
||||
boost::optional<std::string> m_num;
|
||||
|
@ -402,7 +402,7 @@ void GncTxImport::tokenize (bool guessColTypes)
|
||||
auto length = tokenized_line.size();
|
||||
if (length > 0)
|
||||
m_parsed_lines.push_back (std::make_tuple (tokenized_line, std::string(),
|
||||
std::make_shared<GncPreTrans>(date_format()),
|
||||
std::make_shared<GncPreTrans>(date_format(), m_settings.m_multi_split),
|
||||
std::make_shared<GncPreSplit>(date_format(), currency_format()),
|
||||
false));
|
||||
if (length > max_cols)
|
||||
@ -850,6 +850,7 @@ GncTxImport::set_column_type (uint32_t position, GncTransPropType type, bool for
|
||||
* to ensure column updates use the most recent one
|
||||
*/
|
||||
std::get<PL_PRETRANS>(*parsed_lines_it)->set_date_format (m_settings.m_date_format);
|
||||
std::get<PL_PRETRANS>(*parsed_lines_it)->set_multi_split (m_settings.m_multi_split);
|
||||
std::get<PL_PRESPLIT>(*parsed_lines_it)->set_date_format (m_settings.m_date_format);
|
||||
std::get<PL_PRESPLIT>(*parsed_lines_it)->set_currency_format (m_settings.m_currency_format);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user