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 b555a2fca..d43c61ec5 100644 --- a/hledger-lib/hledger_journal.m4.md +++ b/hledger-lib/hledger_journal.m4.md @@ -826,10 +826,16 @@ 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). +Warning, this feature is incomplete; account codes do not yet affect sort order in + +- 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, @@ -850,14 +856,18 @@ 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 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). #### Basic aliases @@ -874,7 +884,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: @@ -963,6 +973,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