summaryrefslogtreecommitdiff
path: root/src/csv.cc
diff options
context:
space:
mode:
authorKai Wohlfahrt <kai.wohlfahrt@gmail.com>2020-06-09 22:12:13 +0100
committerMartin Michlmayr <tbm@cyrius.com>2021-01-31 09:59:02 +0800
commite791e4924f4bfb58044420ff5ab495f3ff5cf8c1 (patch)
tree98032476405868aad7d0986dabf13917c399af0b /src/csv.cc
parentb155f8928c6a33af42f859b27c83639b72517f5e (diff)
downloadfork-ledger-e791e4924f4bfb58044420ff5ab495f3ff5cf8c1.tar.gz
fork-ledger-e791e4924f4bfb58044420ff5ab495f3ff5cf8c1.tar.bz2
fork-ledger-e791e4924f4bfb58044420ff5ab495f3ff5cf8c1.zip
Add debit field to convert command
This changes the error reported when a transaction with no amount is imported.
Diffstat (limited to 'src/csv.cc')
-rw-r--r--src/csv.cc18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/csv.cc b/src/csv.cc
index 40b8e01b..4ee7ff60 100644
--- a/src/csv.cc
+++ b/src/csv.cc
@@ -115,8 +115,10 @@ void csv_reader::read_index(std::istream& in)
index.push_back(FIELD_CODE);
else if (payee_mask.match(field))
index.push_back(FIELD_PAYEE);
- else if (amount_mask.match(field))
- index.push_back(FIELD_AMOUNT);
+ else if (credit_mask.match(field))
+ index.push_back(FIELD_CREDIT);
+ else if (debit_mask.match(field))
+ index.push_back(FIELD_DEBIT);
else if (cost_mask.match(field))
index.push_back(FIELD_COST);
else if (total_mask.match(field))
@@ -199,12 +201,19 @@ xact_t * csv_reader::read_xact(bool rich_data)
break;
}
- case FIELD_AMOUNT: {
+ case FIELD_DEBIT:
+ case FIELD_CREDIT: {
+ if (field.length() == 0)
+ break;
std::istringstream amount_str(field);
amt.parse(amount_str, PARSE_NO_REDUCE);
if (! amt.has_commodity() &&
commodity_pool_t::current_pool->default_commodity)
amt.set_commodity(*commodity_pool_t::current_pool->default_commodity);
+ if (index[n] == FIELD_DEBIT)
+ amt = -amt;
+ if (!post->amount.is_null())
+ throw_(csv_error, _("Cannot have two values for a single transaction"));
post->amount = amt;
break;
}
@@ -214,8 +223,7 @@ xact_t * csv_reader::read_xact(bool rich_data)
amt.parse(amount_str, PARSE_NO_REDUCE);
if (! amt.has_commodity() &&
commodity_pool_t::current_pool->default_commodity)
- amt.set_commodity
- (*commodity_pool_t::current_pool->default_commodity);
+ amt.set_commodity(*commodity_pool_t::current_pool->default_commodity);
post->cost = amt;
break;
}