diff --git a/src/import-export/csv-imp/gnc-trans-props.cpp b/src/import-export/csv-imp/gnc-trans-props.cpp index 54a534d549..df2781a2f6 100644 --- a/src/import-export/csv-imp/gnc-trans-props.cpp +++ b/src/import-export/csv-imp/gnc-trans-props.cpp @@ -209,12 +209,12 @@ static boost::optional parse_amount (const std::string &str, int cu } -void GncPreTrans::set_property (GncTransPropType prop_type, const std::string& value, int date_format) +void GncPreTrans::set_property (GncTransPropType prop_type, const std::string& value) { switch (prop_type) { case GncTransPropType::DATE: - m_date = parse_date (value.c_str(), date_format); // Throws if parsing fails + m_date = parse_date (value, m_date_format); // Throws if parsing fails break; case GncTransPropType::NUM: @@ -297,7 +297,7 @@ bool GncPreTrans::is_part_of (std::shared_ptr parent) (!m_differ || m_differ == parent->m_differ); } -void GncPreSplit::set_property (GncTransPropType prop_type, const std::string& value, int currency_format) +void GncPreSplit::set_property (GncTransPropType prop_type, const std::string& value) { Account *acct = nullptr; switch (prop_type) @@ -347,13 +347,13 @@ void GncPreSplit::set_property (GncTransPropType prop_type, const std::string& v break; case GncTransPropType::BALANCE: - m_balance = parse_amount (value, currency_format); // Will throw if parsing fails + m_balance = parse_amount (value, m_currency_format); // Will throw if parsing fails break; case GncTransPropType::DEPOSIT: - m_deposit = parse_amount (value, currency_format); // Will throw if parsing fails + m_deposit = parse_amount (value, m_currency_format); // Will throw if parsing fails break; case GncTransPropType::WITHDRAWAL: - m_withdrawal = parse_amount (value, currency_format); // Will throw if parsing fails + m_withdrawal = parse_amount (value, m_currency_format); // Will throw if parsing fails break; default: diff --git a/src/import-export/csv-imp/gnc-trans-props.hpp b/src/import-export/csv-imp/gnc-trans-props.hpp index 253144c4e7..41b4c7d978 100644 --- a/src/import-export/csv-imp/gnc-trans-props.hpp +++ b/src/import-export/csv-imp/gnc-trans-props.hpp @@ -92,7 +92,9 @@ time64 parse_date (const std::string &date_str, int format); struct GncPreTrans { public: - void set_property (GncTransPropType prop_type, const std::string& value, int date_format = 0); + GncPreTrans(int date_format) : m_date_format{date_format} {}; + + void set_property (GncTransPropType prop_type, const std::string& value); std::string verify_essentials (void); Transaction *create_trans (QofBook* book, gnc_commodity* currency); @@ -113,6 +115,7 @@ public: bool is_part_of (std::shared_ptr parent); private: + int m_date_format; boost::optional m_date; boost::optional m_num; boost::optional m_desc; @@ -124,7 +127,9 @@ private: struct GncPreSplit { public: - void set_property (GncTransPropType prop_type, const std::string& value, int currency_format = 0); + GncPreSplit (int date_format, int currency_format) : m_date_format{date_format}, + m_currency_format{currency_format}{}; + void set_property (GncTransPropType prop_type, const std::string& value); std::string verify_essentials (void); boost::optional create_split(Transaction* trans); @@ -132,6 +137,8 @@ public: void set_account (Account* acct) { if (acct) m_account = acct; else m_account = boost::none; } private: + int m_date_format; + int m_currency_format; boost::optional m_action; boost::optional m_account; boost::optional m_deposit; diff --git a/src/import-export/csv-imp/gnc-tx-import.cpp b/src/import-export/csv-imp/gnc-tx-import.cpp index e35172a7d8..fd894aa10c 100644 --- a/src/import-export/csv-imp/gnc-tx-import.cpp +++ b/src/import-export/csv-imp/gnc-tx-import.cpp @@ -174,7 +174,7 @@ void GncTxImport::tokenize (bool guessColTypes) for (auto tokenized_line : tokenizer->get_tokens()) { parsed_lines.push_back (std::make_tuple (tokenized_line, std::string(), - std::make_shared(), std::make_shared())); + nullptr, nullptr)); auto length = tokenized_line.size(); if (length > max_cols) max_cols = length; @@ -338,9 +338,9 @@ void GncTxImport::create_transaction (std::vector::iterator& parse { StrVec line; std::string error_message; - std::shared_ptr trans_props; - std::shared_ptr split_props; - std::tie(line, error_message, trans_props, split_props) = *parsed_line; + auto trans_props = std::make_shared(date_format); + auto split_props = std::make_shared(date_format, currency_format); + std::tie(line, error_message, std::ignore, std::ignore) = *parsed_line; error_message.clear(); /* Convert all tokens in this line into transaction/split properties. */ @@ -359,10 +359,10 @@ void GncTxImport::create_transaction (std::vector::iterator& parse { if (multi_split && line_it->empty()) continue; // In multi-split mode, transaction properties can be empty - trans_props->set_property(*col_types_it, *line_it, date_format); + trans_props->set_property(*col_types_it, *line_it); } else - split_props->set_property(*col_types_it, *line_it, currency_format); + split_props->set_property(*col_types_it, *line_it); } catch (const std::exception& e) { @@ -393,9 +393,12 @@ void GncTxImport::create_transaction (std::vector::iterator& parse error_message = _("First line of this transaction has errors."); } else + { + std::get<2>(*parsed_line) = trans_props; /* This line starts a new transaction, set it as parent for * subsequent lines. */ parent = trans_props; + } } if (!error_message.empty()) @@ -418,6 +421,7 @@ void GncTxImport::create_transaction (std::vector::iterator& parse throw std::invalid_argument(error_message); } } + std::get<3>(*parsed_line) = split_props; /* If column parsing was successful, convert trans properties into a draft transaction. */ try