From 4e6637e67e34e917a923cc0f19508dc99c8cb2ff Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Tue, 31 Jan 2023 23:56:22 +0100 Subject: [PATCH] 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. --- gnucash/import-export/csv-imp/gnc-imp-props-tx.cpp | 11 ++++++++++- gnucash/import-export/csv-imp/gnc-imp-props-tx.hpp | 5 ++++- gnucash/import-export/csv-imp/gnc-import-tx.cpp | 3 ++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/gnucash/import-export/csv-imp/gnc-imp-props-tx.cpp b/gnucash/import-export/csv-imp/gnc-imp-props-tx.cpp index da246b0fdd..af07873ad8 100644 --- a/gnucash/import-export/csv-imp/gnc-imp-props-tx.cpp +++ b/gnucash/import-export/csv-imp/gnc-imp-props-tx.cpp @@ -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: diff --git a/gnucash/import-export/csv-imp/gnc-imp-props-tx.hpp b/gnucash/import-export/csv-imp/gnc-imp-props-tx.hpp index 5c6b73393b..29e97fe4ef 100644 --- a/gnucash/import-export/csv-imp/gnc-imp-props-tx.hpp +++ b/gnucash/import-export/csv-imp/gnc-imp-props-tx.hpp @@ -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 m_differ; boost::optional m_date; boost::optional m_num; diff --git a/gnucash/import-export/csv-imp/gnc-import-tx.cpp b/gnucash/import-export/csv-imp/gnc-import-tx.cpp index 0797b45cd4..6e93823ed0 100644 --- a/gnucash/import-export/csv-imp/gnc-import-tx.cpp +++ b/gnucash/import-export/csv-imp/gnc-import-tx.cpp @@ -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(date_format()), + std::make_shared(date_format(), m_settings.m_multi_split), std::make_shared(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(*parsed_lines_it)->set_date_format (m_settings.m_date_format); + std::get(*parsed_lines_it)->set_multi_split (m_settings.m_multi_split); std::get(*parsed_lines_it)->set_date_format (m_settings.m_date_format); std::get(*parsed_lines_it)->set_currency_format (m_settings.m_currency_format);