From 422f1084c9b131f1de8e5dc7d7f148f95889a4d4 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Wed, 27 Jun 2018 11:15:46 +0100 Subject: [PATCH 1/6] doc: journal: note that non-regex alias directive is case sensitive [ci skip] --- hledger-lib/hledger_journal.m4.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hledger-lib/hledger_journal.m4.md b/hledger-lib/hledger_journal.m4.md index b555a2fca..dc1769208 100644 --- a/hledger-lib/hledger_journal.m4.md +++ b/hledger-lib/hledger_journal.m4.md @@ -874,7 +874,7 @@ alias OLD = NEW Or, you can use the `--alias 'OLD=NEW'` option on the command line. This affects all entries. It's useful for trying out aliases interactively. -OLD and NEW are full account names. +OLD and NEW are case sensitive full account names. hledger will replace any occurrence of the old account name with the new one. Subaccounts are also affected. Eg: From 6924e8390cdf3796799ed74756b95e071432e8ef Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Wed, 27 Jun 2018 11:26:08 +0100 Subject: [PATCH 2/6] lib: journal: let alias/apply account affect account directives (#825) --- hledger-lib/Hledger/Read/Common.hs | 4 +++- hledger-lib/Hledger/Read/JournalReader.hs | 2 +- hledger-lib/hledger_journal.m4.md | 7 +++++++ tests/journal/accounts.test | 19 +++++++++++++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 tests/journal/accounts.test diff --git a/hledger-lib/Hledger/Read/Common.hs b/hledger-lib/Hledger/Read/Common.hs index d1fe031c5..e75058d8d 100644 --- a/hledger-lib/Hledger/Read/Common.hs +++ b/hledger-lib/Hledger/Read/Common.hs @@ -459,7 +459,9 @@ secondarydatep primaryDate = char '=' *> datep' (Just primaryYear) --- ** account names --- | Parse an account name, then apply any parent account prefix and/or account aliases currently in effect. +-- | Parse an account name (plus one following space if present), +-- then apply any parent account prefix and/or account aliases currently in effect, +-- in that order. (Ie first add the parent account prefix, then rewrite with aliases). modifiedaccountnamep :: JournalParser m AccountName modifiedaccountnamep = do parent <- getParentAccount diff --git a/hledger-lib/Hledger/Read/JournalReader.hs b/hledger-lib/Hledger/Read/JournalReader.hs index d6cdb9f56..f2a18d495 100644 --- a/hledger-lib/Hledger/Read/JournalReader.hs +++ b/hledger-lib/Hledger/Read/JournalReader.hs @@ -248,7 +248,7 @@ accountdirectivep :: JournalParser m () accountdirectivep = do string "account" lift (skipSome spacenonewline) - acct <- lift accountnamep -- eats single spaces + acct <- modifiedaccountnamep -- account directives can be modified by alias/apply account macode' :: Maybe String <- (optional $ lift $ skipSome spacenonewline >> some digitChar) let macode :: Maybe AccountCode = read <$> macode' newline diff --git a/hledger-lib/hledger_journal.m4.md b/hledger-lib/hledger_journal.m4.md index dc1769208..865e43116 100644 --- a/hledger-lib/hledger_journal.m4.md +++ b/hledger-lib/hledger_journal.m4.md @@ -928,6 +928,9 @@ You can clear (forget) all currently defined aliases with the `end aliases` dire end aliases ``` +Account aliases also affect [account directives](#declaring-accounts). +They do not affect account names being entered via hledger add or hledger-web. + ### Default parent account You can specify a parent account which will be prepended to all accounts @@ -963,6 +966,10 @@ include personal.journal Prior to hledger 1.0, legacy `account` and `end` spellings were also supported. +A default parent account also affects [account directives](#declaring-accounts). +It does not affect account names being entered via hledger add or hledger-web. +If account aliases are present, they are applied after the default parent account. + ## Periodic transactions Periodic transaction rules describe transactions that recur. diff --git a/tests/journal/accounts.test b/tests/journal/accounts.test new file mode 100644 index 000000000..5f87bcef5 --- /dev/null +++ b/tests/journal/accounts.test @@ -0,0 +1,19 @@ +# account names + +# 1. account directives are affected by aliases and apply account. +< +apply account c +alias c:a=b +account a +$ hledger -f - accounts +b + + + +# TODO +# a trailing : should give a clear error +# 2009/1/1 +# a: 1 +# $ hledger -f - print +# >2 /accountname seems ill-formed: a:/ +# >= 1 From 6d215945b629b1b77cd59f079d6048c8990a22d4 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Wed, 27 Jun 2018 11:41:11 +0100 Subject: [PATCH 3/6] doc: journal: clarify account aliases doc [ci skip] --- hledger-lib/hledger_journal.m4.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hledger-lib/hledger_journal.m4.md b/hledger-lib/hledger_journal.m4.md index 865e43116..9beaefc6f 100644 --- a/hledger-lib/hledger_journal.m4.md +++ b/hledger-lib/hledger_journal.m4.md @@ -858,6 +858,9 @@ before generating reports). hledger's account aliases can be useful for: - experimenting with new account organisations, like a new hierarchy or combining two accounts into one - customising reports +Account aliases also affect [account directives](#declaring-accounts). +They do not affect account names being entered via hledger add or hledger-web. + See also [Cookbook: Rewrite account names](https://github.com/simonmichael/hledger/wiki/Rewrite-account-names). #### Basic aliases @@ -928,9 +931,6 @@ You can clear (forget) all currently defined aliases with the `end aliases` dire end aliases ``` -Account aliases also affect [account directives](#declaring-accounts). -They do not affect account names being entered via hledger add or hledger-web. - ### Default parent account You can specify a parent account which will be prepended to all accounts From 35e68e23c5a6387657c472ff638ff4df500d746b Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Wed, 27 Jun 2018 11:44:26 +0100 Subject: [PATCH 4/6] doc: journal: clarify account aliases doc [ci skip] --- hledger-lib/hledger_journal.m4.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hledger-lib/hledger_journal.m4.md b/hledger-lib/hledger_journal.m4.md index 9beaefc6f..b1e72d21b 100644 --- a/hledger-lib/hledger_journal.m4.md +++ b/hledger-lib/hledger_journal.m4.md @@ -850,15 +850,16 @@ account assets:bank:checking 1110 ### Rewriting accounts -You can define aliases which rewrite your account names (after reading the journal, -before generating reports). hledger's account aliases can be useful for: +You can define account alias rules which rewrite your account names, or parts of them, +before generating reports. +This can be useful for: - expanding shorthand account names to their full form, allowing easier data entry and a less verbose journal - adapting old journals to your current chart of accounts - experimenting with new account organisations, like a new hierarchy or combining two accounts into one - customising reports -Account aliases also affect [account directives](#declaring-accounts). +Account aliases also rewrite account names in [account directives](#declaring-accounts). They do not affect account names being entered via hledger add or hledger-web. See also [Cookbook: Rewrite account names](https://github.com/simonmichael/hledger/wiki/Rewrite-account-names). From 2959356bd9237e0fd39f6e993d9c7d1acb0dfb7f Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Wed, 27 Jun 2018 12:19:25 +0100 Subject: [PATCH 5/6] doc: journal: note another account codes limitation, in flat mode [ci skip] --- hledger-lib/hledger_journal.m4.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/hledger-lib/hledger_journal.m4.md b/hledger-lib/hledger_journal.m4.md index b1e72d21b..3b31c17ff 100644 --- a/hledger-lib/hledger_journal.m4.md +++ b/hledger-lib/hledger_journal.m4.md @@ -826,10 +826,14 @@ account liabilities 2000 account revenues 4000 account expenses 6000 ``` -This affects account display order in reports: -accounts with codes are listed before accounts without codes and in increasing code order, -instead of listing all accounts alphabetically. -(*Note: currently not supported in the `balance` command's single-column mode.*) +This affects how accounts are sorted in account and balance reports: +accounts with codes are listed before accounts without codes, and in increasing code order +(instead of listing all accounts alphabetically). +Some current limitations: + +- in the `balance` command's single-column mode, account codes do not affect sort order +- in flat mode reports, account codes on parent accounts do not affect the sort order of subaccounts. + (To work around this, declare account codes on the subaccounts as well.) Account codes should be all numeric digits, unique, and separated from the account name by at least two spaces (since account names may contain single spaces). By convention, often the first digit indicates the type of account, From 937333c2c1d48b8f058bd09b3e1ff31c8294cb6c Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Wed, 27 Jun 2018 12:42:05 +0100 Subject: [PATCH 6/6] doc: journal: more account codes limitations [ci skip] --- hledger-lib/hledger_journal.m4.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/hledger-lib/hledger_journal.m4.md b/hledger-lib/hledger_journal.m4.md index 3b31c17ff..d43c61ec5 100644 --- a/hledger-lib/hledger_journal.m4.md +++ b/hledger-lib/hledger_journal.m4.md @@ -829,11 +829,13 @@ account expenses 6000 This affects how accounts are sorted in account and balance reports: accounts with codes are listed before accounts without codes, and in increasing code order (instead of listing all accounts alphabetically). -Some current limitations: +Warning, this feature is incomplete; account codes do not yet affect sort order in -- in the `balance` command's single-column mode, account codes do not affect sort order -- in flat mode reports, account codes on parent accounts do not affect the sort order of subaccounts. - (To work around this, declare account codes on the subaccounts as well.) +- the `accounts` command +- the `balance` command's single-column mode +- flat mode balance reports + (to work around this, declare account codes on the subaccounts as well). +- hledger-web's sidebar Account codes should be all numeric digits, unique, and separated from the account name by at least two spaces (since account names may contain single spaces). By convention, often the first digit indicates the type of account,