mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Create trans/split props only when needed and have them keep their own value of date/currency format
This commit is contained in:
parent
443237f2b9
commit
848c7b8f8e
@ -209,12 +209,12 @@ static boost::optional<gnc_numeric> 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<GncPreTrans> 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:
|
||||
|
@ -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<GncPreTrans> parent);
|
||||
|
||||
private:
|
||||
int m_date_format;
|
||||
boost::optional<time64> m_date;
|
||||
boost::optional<std::string> m_num;
|
||||
boost::optional<std::string> 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<gnc_numeric> 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<std::string> m_action;
|
||||
boost::optional<Account*> m_account;
|
||||
boost::optional<gnc_numeric> m_deposit;
|
||||
|
@ -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<GncPreTrans>(), std::make_shared<GncPreSplit>()));
|
||||
nullptr, nullptr));
|
||||
auto length = tokenized_line.size();
|
||||
if (length > max_cols)
|
||||
max_cols = length;
|
||||
@ -338,9 +338,9 @@ void GncTxImport::create_transaction (std::vector<parse_line_t>::iterator& parse
|
||||
{
|
||||
StrVec line;
|
||||
std::string error_message;
|
||||
std::shared_ptr<GncPreTrans> trans_props;
|
||||
std::shared_ptr<GncPreSplit> split_props;
|
||||
std::tie(line, error_message, trans_props, split_props) = *parsed_line;
|
||||
auto trans_props = std::make_shared<GncPreTrans>(date_format);
|
||||
auto split_props = std::make_shared<GncPreSplit>(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<parse_line_t>::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,10 +393,13 @@ void GncTxImport::create_transaction (std::vector<parse_line_t>::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())
|
||||
throw std::invalid_argument (error_message);
|
||||
@ -418,6 +421,7 @@ void GncTxImport::create_transaction (std::vector<parse_line_t>::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
|
||||
|
Loading…
Reference in New Issue
Block a user