CsvTxImp - rename 'Deposit' and 'Withdrawal' columns

Multiple reasons:
- they only have meaning in bank or cash contexts, but the importer is meant
  to be more generic.
- 'Withdrawal' is misleading in that the code behind it caters very
  generically for cases where values should be negated before being
  used. A 'Withdrawal' is only a single use case of this behaviour.

New names are 'Amount' (iso 'Deposit')
and 'Amount (Negated)' (iso 'Withdrawal')
This commit is contained in:
Geert Janssens 2023-02-01 12:47:37 +01:00
parent 4e6637e67e
commit 1c2c184e2e
4 changed files with 48 additions and 44 deletions

View File

@ -57,15 +57,15 @@ std::map<GncTransPropType, const char*> gnc_csv_col_type_strs = {
{ GncTransPropType::NONE, N_("None") },
{ GncTransPropType::UNIQUE_ID, N_("Transaction ID") },
{ GncTransPropType::DATE, N_("Date") },
{ GncTransPropType::NUM, N_("Num") },
{ GncTransPropType::NUM, N_("Number") },
{ GncTransPropType::DESCRIPTION, N_("Description") },
{ GncTransPropType::NOTES, N_("Notes") },
{ GncTransPropType::COMMODITY, N_("Transaction Commodity") },
{ GncTransPropType::VOID_REASON, N_("Void Reason") },
{ GncTransPropType::ACTION, N_("Action") },
{ GncTransPropType::ACCOUNT, N_("Account") },
{ GncTransPropType::DEPOSIT, N_("Deposit") },
{ GncTransPropType::WITHDRAWAL, N_("Withdrawal") },
{ GncTransPropType::AMOUNT, N_("Amount") },
{ GncTransPropType::AMOUNT_NEG, N_("Amount (Negated)") },
{ GncTransPropType::PRICE, N_("Price") },
{ GncTransPropType::MEMO, N_("Memo") },
{ GncTransPropType::REC_STATE, N_("Reconciled") },
@ -442,13 +442,13 @@ void GncPreSplit::set (GncTransPropType prop_type, const std::string& value)
m_tmemo = value;
break;
case GncTransPropType::DEPOSIT:
m_deposit = boost::none;
m_deposit = parse_monetary (value, m_currency_format); // Will throw if parsing fails
case GncTransPropType::AMOUNT:
m_amount = boost::none;
m_amount = parse_monetary (value, m_currency_format); // Will throw if parsing fails
break;
case GncTransPropType::WITHDRAWAL:
m_withdrawal = boost::none;
m_withdrawal = parse_monetary (value, m_currency_format); // Will throw if parsing fails
case GncTransPropType::AMOUNT_NEG:
m_amount_neg = boost::none;
m_amount_neg = parse_monetary (value, m_currency_format); // Will throw if parsing fails
break;
case GncTransPropType::PRICE:
@ -532,18 +532,18 @@ void GncPreSplit::add (GncTransPropType prop_type, const std::string& value)
auto num_val = GncNumeric();
switch (prop_type)
{
case GncTransPropType::DEPOSIT:
case GncTransPropType::AMOUNT:
num_val = parse_monetary (value, m_currency_format); // Will throw if parsing fails
if (m_deposit)
num_val += *m_deposit;
m_deposit = num_val;
if (m_amount)
num_val += *m_amount;
m_amount = num_val;
break;
case GncTransPropType::WITHDRAWAL:
case GncTransPropType::AMOUNT_NEG:
num_val = parse_monetary (value, m_currency_format); // Will throw if parsing fails
if (m_withdrawal)
num_val += *m_withdrawal;
m_withdrawal = num_val;
if (m_amount_neg)
num_val += *m_amount_neg;
m_amount_neg = num_val;
break;
default:
@ -574,8 +574,8 @@ std::string GncPreSplit::verify_essentials (void)
{
auto err_msg = std::string();
/* Make sure this split has the minimum required set of properties defined. */
if (!m_deposit && !m_withdrawal)
err_msg = _("No deposit or withdrawal column.");
if (!m_amount && !m_amount_neg)
err_msg = _("No amount or negated amount column.");
if (m_rec_state && *m_rec_state == YREC && !m_rec_date)
{
@ -679,20 +679,16 @@ void GncPreSplit::create_split (Transaction* trans)
Account *account = nullptr;
Account *taccount = nullptr;
auto deposit = GncNumeric();
auto withdrawal = GncNumeric();
auto amount = GncNumeric();
if (m_account)
account = *m_account;
if (m_taccount)
taccount = *m_taccount;
if (m_deposit)
deposit = *m_deposit;
if (m_withdrawal)
withdrawal = *m_withdrawal;
amount = deposit - withdrawal;
if (m_amount)
amount += *m_amount;
if (m_amount_neg)
amount -= *m_amount_neg;
/* Add a split with the cumulative amount value. */
trans_add_split (trans, account, amount, m_action, m_memo, m_rec_state, m_rec_date, m_price);

View File

@ -59,8 +59,8 @@ enum class GncTransPropType {
ACTION,
ACCOUNT,
DEPOSIT,
WITHDRAWAL,
AMOUNT,
AMOUNT_NEG,
PRICE,
MEMO,
REC_STATE,
@ -173,8 +173,8 @@ private:
int m_currency_format;
boost::optional<std::string> m_action;
boost::optional<Account*> m_account;
boost::optional<GncNumeric> m_deposit;
boost::optional<GncNumeric> m_withdrawal;
boost::optional<GncNumeric> m_amount;
boost::optional<GncNumeric> m_amount_neg;
boost::optional<GncNumeric> m_price;
boost::optional<std::string> m_memo;
boost::optional<char> m_rec_state;

View File

@ -89,7 +89,7 @@ static std::shared_ptr<CsvTransImpSettings> create_int_gnc_exp_preset(void)
GncTransPropType::ACCOUNT,
GncTransPropType::NONE,
GncTransPropType::NONE,
GncTransPropType::DEPOSIT,
GncTransPropType::AMOUNT,
GncTransPropType::REC_STATE,
GncTransPropType::REC_DATE,
GncTransPropType::PRICE
@ -214,8 +214,16 @@ CsvTransImpSettings::load (void)
&list_len, &key_error);
for (uint32_t i = 0; i < list_len; i++)
{
/* Special case a few legacy column names */
const char *col_type_str = col_types_str[i];
if (!g_strcmp0(col_type_str, "Deposit")) // -> "Amount"
col_type_str = gnc_csv_col_type_strs[GncTransPropType::AMOUNT];
if (!g_strcmp0(col_type_str, "Withdrawal")) // -> "Amount (Negated)"
col_type_str = gnc_csv_col_type_strs[GncTransPropType::AMOUNT_NEG];
if (!g_strcmp0(col_type_str, "Num")) // -> "Number"
col_type_str = gnc_csv_col_type_strs[GncTransPropType::NUM];
auto col_types_it = std::find_if (gnc_csv_col_type_strs.begin(),
gnc_csv_col_type_strs.end(), test_prop_type_str (col_types_str[i]));
gnc_csv_col_type_strs.end(), test_prop_type_str (col_type_str));
if (col_types_it != gnc_csv_col_type_strs.end())
{
/* Found a valid column type. Now check whether it is allowed

View File

@ -216,8 +216,8 @@ void GncTxImport::currency_format (int currency_format)
m_settings.m_currency_format = currency_format;
/* Reparse all currency related columns */
std::vector<GncTransPropType> commodities = { GncTransPropType::DEPOSIT,
GncTransPropType::WITHDRAWAL,
std::vector<GncTransPropType> commodities = { GncTransPropType::AMOUNT,
GncTransPropType::AMOUNT_NEG,
GncTransPropType::PRICE};
reset_formatted_column (commodities);
}
@ -485,11 +485,11 @@ void GncTxImport::verify_column_selections (ErrorList& error_msg)
if (!check_for_column_type(GncTransPropType::DESCRIPTION))
error_msg.add_error( _("Please select a description column."));
/* Verify at least one amount column (deposit or withdrawal) column is selected.
/* Verify at least one amount column (amount or amount_neg) column is selected.
*/
if (!check_for_column_type(GncTransPropType::DEPOSIT) &&
!check_for_column_type(GncTransPropType::WITHDRAWAL))
error_msg.add_error( _("Please select a deposit or withdrawal column."));
if (!check_for_column_type(GncTransPropType::AMOUNT) &&
!check_for_column_type(GncTransPropType::AMOUNT_NEG))
error_msg.add_error( _("Please select a amount or negated amount column."));
/* Verify a transfer account is selected if any of the other transfer properties
* are selected.
@ -769,8 +769,8 @@ void GncTxImport::update_pre_trans_split_props (uint32_t row, uint32_t col, GncT
{
/* Except for Deposit or Withdrawal lines there can only be
* one column with a given property type. */
if ((new_type != GncTransPropType::DEPOSIT) &&
(new_type != GncTransPropType::WITHDRAWAL))
if ((new_type != GncTransPropType::AMOUNT) &&
(new_type != GncTransPropType::AMOUNT_NEG))
{
auto value = std::get<PL_INPUT>(m_parsed_lines[row]).at(col);
split_props->set(new_type, value);
@ -827,10 +827,10 @@ GncTxImport::set_column_type (uint32_t position, GncTransPropType type, bool for
if ((type == old_type) && !force)
return; /* Nothing to do */
// Column types except deposit and withdrawal should be unique,
// Column types except amount and negated amount should be unique,
// so remove any previous occurrence of the new type
if ((type != GncTransPropType::DEPOSIT) &&
(type != GncTransPropType::WITHDRAWAL))
if ((type != GncTransPropType::AMOUNT) &&
(type != GncTransPropType::AMOUNT_NEG))
std::replace(m_settings.m_column_types.begin(), m_settings.m_column_types.end(),
type, GncTransPropType::NONE);