From e791e4924f4bfb58044420ff5ab495f3ff5cf8c1 Mon Sep 17 00:00:00 2001 From: Kai Wohlfahrt Date: Tue, 9 Jun 2020 22:12:13 +0100 Subject: Add debit field to convert command This changes the error reported when a transaction with no amount is imported. --- src/csv.cc | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src/csv.cc') 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; } -- cgit v1.2.3