From 49b02614a39ad86bb499df8b410232a5948247d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johann=20Kl=C3=A4hn?= Date: Sat, 13 Oct 2012 15:17:09 +0200 Subject: [PATCH 1/2] fix account mapping in csv conversion By using payees_for_unknown_accounts instead of account_mappings in csv.cc ledger will have the same behaviour as in `ledger -f - print` in that it uses payee fields in account directives to rewrite the account. --- src/csv.cc | 2 +- test/baseline/feat-convert-with-diretives.dat | 3 ++ .../baseline/feat-convert-with-diretives.test | 28 +++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 test/baseline/feat-convert-with-diretives.dat create mode 100644 test/baseline/feat-convert-with-diretives.test diff --git a/src/csv.cc b/src/csv.cc index 71b6516a..dbd2dbfe 100644 --- a/src/csv.cc +++ b/src/csv.cc @@ -243,7 +243,7 @@ xact_t * csv_reader::read_xact(bool rich_data) // Translate the account name, if we have enough information to do so - foreach (account_mapping_t& value, context.journal->account_mappings) { + foreach (account_mapping_t& value, context.journal->payees_for_unknown_accounts) { if (value.first.match(xact->payee)) { post->account = value.second; break; diff --git a/test/baseline/feat-convert-with-diretives.dat b/test/baseline/feat-convert-with-diretives.dat new file mode 100644 index 00000000..ac13ff81 --- /dev/null +++ b/test/baseline/feat-convert-with-diretives.dat @@ -0,0 +1,3 @@ +date,payee,amount +2012/01/01,KFC,$10 +2012/01/02,"REWE SAGT DANKE 123454321",10€ diff --git a/test/baseline/feat-convert-with-diretives.test b/test/baseline/feat-convert-with-diretives.test new file mode 100644 index 00000000..2f6e0102 --- /dev/null +++ b/test/baseline/feat-convert-with-diretives.test @@ -0,0 +1,28 @@ +account Expenses:Food + payee KFC + payee REWE + +payee REWE + alias REWE SAGT DANKE + +# When reading csv file without directives: +test -f /dev/null convert test/baseline/feat-convert-with-diretives.dat +2012/01/01 * KFC + Expenses:Unknown $10 + Equity:Unknown + +2012/01/02 * REWE SAGT DANKE 123454321 + Expenses:Unknown 10€ + Equity:Unknown +end test + +# When reading csv file with directives: +test --account "Assets:Cash" convert test/baseline/feat-convert-with-diretives.dat +2012/01/01 * KFC + Expenses:Food $10 + Assets:Cash + +2012/01/02 * REWE + Expenses:Food 10€ + Assets:Cash +end test From 08033e6d50dbe659b8393464eab119b00d8ba44a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johann=20Kl=C3=A4hn?= Date: Sat, 13 Oct 2012 15:06:48 +0200 Subject: [PATCH 2/2] fix test runner if filename is specified If the command line switch "-f" is used the test runner will not pass the file name of the test file to ledger. The line "test -f /dev/null" as used in test/baseline/cmd-convert.test did not work as intended before this. Also using "-f - " did not work as "$ledger" was noti prepended to the command. --- test/RegressTests.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/RegressTests.py b/test/RegressTests.py index 7d67eb21..1094d0d5 100755 --- a/test/RegressTests.py +++ b/test/RegressTests.py @@ -98,8 +98,10 @@ class RegressFile(object): def run_test(self, test): use_stdin = False - if test['command'].find("-f - ") != -1: - use_stdin = True + if test['command'].find("-f ") != -1: + test['command'] = '$ledger ' + test['command'] + if test['command'].find("-f - ") != -1: + use_stdin = True else: test['command'] = (('$ledger -f "%s" ' % os.path.abspath(self.filename)) +