A bunch of account sorting changes that got intermingled.
First, account codes have been dropped. They can still be parsed and
will be ignored, for now. I don't know if anyone used them.
Instead, account display order is now controlled by the order of account
directives, if any. From the mail list:
  I'd like to drop account codes, introduced in hledger 1.9 to control
  the display order of accounts. In my experience,
  - they are tedious to maintain
  - they duplicate/compete with the natural tendency to arrange account
    directives to match your mental chart of accounts
  - they duplicate/compete with the tree structure created by account
    names
  and it gets worse if you think about using them more extensively,
  eg to classify accounts by type.
  Instead, I plan to just let the position (parse order) of account
  directives determine the display order of those declared accounts.
  Undeclared accounts will be displayed after declared accounts,
  sorted alphabetically as usual.
Second, the various account sorting modes have been implemented more
widely and more correctly. All sorting modes (alphabetically, by account
declaration, by amount) should now work correctly in almost all commands
and modes (non-tabular and tabular balance reports, tree and flat modes,
the accounts command). Sorting bugs have been fixed, eg #875.
Only the budget report (balance --budget) does not yet support sorting.
Comprehensive functional tests for sorting in the accounts and balance
commands have been added. If you are confused by some sorting behaviour,
studying these tests is recommended, as sorting gets tricky.
		
	
			
		
			
				
	
	
		
			353 lines
		
	
	
		
			5.8 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			353 lines
		
	
	
		
			5.8 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
| * balance report sorting.
 | |
| # These tests are based on accounts' and somewhat duplicatory if
 | |
| # sorting code is shared between commands, but might be worth having
 | |
| # all the same.
 | |
| ** Tabular balance reports
 | |
| *** Default sort without account declarations
 | |
| 
 | |
| # 1. Rows are sorted alphabetically by account name, at each tree level. 
 | |
| # Flat mode. Unused parent accounts are not added (b).
 | |
| <
 | |
| 2018/1/1
 | |
|   (b:j)  1
 | |
| 
 | |
| 2018/1/1
 | |
|   (c)    1
 | |
| 
 | |
| 2018/1/1
 | |
|   (b:i)  1
 | |
| 
 | |
| 2018/1/1
 | |
|   (a:k)  1
 | |
| 
 | |
| $ hledger -f- bal -NY
 | |
| Balance changes in 2018:
 | |
| 
 | |
|      || 2018 
 | |
| =====++======
 | |
|  a:k ||    1 
 | |
|  b:i ||    1 
 | |
|  b:j ||    1 
 | |
|  c   ||    1 
 | |
| >=
 | |
| 
 | |
| # 2. Tree mode. Missing parent accounts are added (b).
 | |
| $ hledger -f- bal -NY --tree
 | |
| Balance changes in 2018:
 | |
| 
 | |
|      || 2018 
 | |
| =====++======
 | |
|  a   ||    1 
 | |
|    k ||    1 
 | |
|  b   ||    2 
 | |
|    i ||    1 
 | |
|    j ||    1 
 | |
|  c   ||    1 
 | |
| >=
 | |
| 
 | |
| *** Default sort with account declarations
 | |
| 
 | |
| # 3. With account directives, flat mode.
 | |
| # At each tree level, declared accounts are sorted first, in
 | |
| # declaration order, followed by undeclared accounts sorted alphabetically.
 | |
| # Unused parent accounts are not added (b).
 | |
| # The b:k, b:j declarations affect the subs of b, not b itself.
 | |
| <
 | |
| account b:k
 | |
| account b:j
 | |
| account d
 | |
| 
 | |
| 2018/1/1
 | |
|   (a:l)  1
 | |
| 
 | |
| 2018/1/1
 | |
|   (b:i)  1
 | |
| 
 | |
| 2018/1/1
 | |
|   (b:j)  1
 | |
| 
 | |
| 2018/1/1
 | |
|   (b:k)  1
 | |
| 
 | |
| 2018/1/1
 | |
|   (c)    1
 | |
| 
 | |
| 2018/1/1
 | |
|   (d)    1
 | |
| 
 | |
| $ hledger -f- bal -NY
 | |
| Balance changes in 2018:
 | |
| 
 | |
|      || 2018 
 | |
| =====++======
 | |
|  d   ||    1 
 | |
|  a:l ||    1 
 | |
|  b:k ||    1 
 | |
|  b:j ||    1 
 | |
|  b:i ||    1 
 | |
|  c   ||    1 
 | |
| >=
 | |
| 
 | |
| # 4. With account directives, tree mode.
 | |
| # Missing parent accounts are added (b).
 | |
| $ hledger -f- bal -NY --tree
 | |
| Balance changes in 2018:
 | |
| 
 | |
|      || 2018 
 | |
| =====++======
 | |
|  d   ||    1 
 | |
|  a   ||    1 
 | |
|    l ||    1 
 | |
|  b   ||    3 
 | |
|    k ||    1 
 | |
|    j ||    1 
 | |
|    i ||    1 
 | |
|  c   ||    1 
 | |
| >=
 | |
| 
 | |
| # # .
 | |
| # <
 | |
| # $ hledger -f- bal -NY
 | |
| # >=
 | |
| 
 | |
| # . With --drop, the modified names are sorted. ?
 | |
| # XXX not supported ?
 | |
| # $ hledger -f- bal -NY --drop 2
 | |
| # Balance changes in 2018:
 | |
| #
 | |
| #      || 2018 
 | |
| # =====++======
 | |
| #  c ||    1 
 | |
| #  i ||    1 
 | |
| #  j ||    1 
 | |
| #  k ||    1 
 | |
| # >=
 | |
| 
 | |
| *** Sort by amount
 | |
| 
 | |
| # 5. Rows are sorted by decreasing amount (and then by account), at each tree level. 
 | |
| # Tree mode.
 | |
| 
 | |
| <
 | |
| 2018/1/1
 | |
|   (b:j)  2
 | |
| 
 | |
| 2018/1/1
 | |
|   (c)    1
 | |
| 
 | |
| 2018/1/1
 | |
|   (b:i)  1
 | |
| 
 | |
| 2018/1/1
 | |
|   (a:k)  1
 | |
| 
 | |
| $ hledger -f- bal -NY --sort-amount --tree
 | |
| Balance changes in 2018:
 | |
| 
 | |
|      || 2018 
 | |
| =====++======
 | |
|  b   ||    3 
 | |
|    j ||    2 
 | |
|    i ||    1 
 | |
|  a   ||    1 
 | |
|    k ||    1 
 | |
|  c   ||    1 
 | |
| >=
 | |
| 
 | |
| # 6. Flat mode.
 | |
| $ hledger -f- bal -NY --flat --sort-amount
 | |
| Balance changes in 2018:
 | |
| 
 | |
|      || 2018 
 | |
| =====++======
 | |
|  b:j ||    2 
 | |
|  a:k ||    1 
 | |
|  b:i ||    1 
 | |
|  c   ||    1 
 | |
| >=
 | |
| 
 | |
| # 7. When the larger amount is composed of differently-priced amounts,
 | |
| # it could get sorted as if smaller (bug in hledger 1.4-1.10). Flat mode.
 | |
| <
 | |
| 2018/1/1
 | |
|   (a)  2X @ 1Y
 | |
|   (a)  2X @ 2Y
 | |
| 
 | |
| 2018/1/1
 | |
|   (b)  3X
 | |
| 
 | |
| $ hledger -f- bal -NY --sort-amount
 | |
| Balance changes in 2018:
 | |
| 
 | |
|    || 2018 
 | |
| ===++======
 | |
|  a ||   4X 
 | |
|  b ||   3X 
 | |
| >=
 | |
| 
 | |
| # 8. Explicit --flat flag, should be the same as above.
 | |
| $ hledger -f- bal -NY --sort-amount --flat
 | |
| Balance changes in 2018:
 | |
| 
 | |
|    || 2018 
 | |
| ===++======
 | |
|  a ||   4X 
 | |
|  b ||   3X 
 | |
| >=
 | |
| 
 | |
| # 9. Tree mode.
 | |
| $ hledger -f- bal -NY --sort-amount --tree
 | |
| Balance changes in 2018:
 | |
| 
 | |
|    || 2018 
 | |
| ===++======
 | |
|  a ||   4X 
 | |
|  b ||   3X 
 | |
| >=
 | |
| 
 | |
| ** Non-tabular balance reports
 | |
| *** Default sort without account declarations
 | |
| 
 | |
| # 10. Rows are sorted alphabetically by account name, at each tree level. 
 | |
| # Tree mode. Missing parent accounts are added (b).
 | |
| <
 | |
| 2018/1/1
 | |
|   (b:j)  1
 | |
| 
 | |
| 2018/1/1
 | |
|   (c)    1
 | |
| 
 | |
| 2018/1/1
 | |
|   (b:i)  1
 | |
| 
 | |
| 2018/1/1
 | |
|   (a:k)  1
 | |
| 
 | |
| $ hledger -f- bal -N
 | |
|                    1  a:k
 | |
|                    2  b
 | |
|                    1    i
 | |
|                    1    j
 | |
|                    1  c
 | |
| >=
 | |
| 
 | |
| # 11. Flat mode. Unused parent accounts are not added (b).
 | |
| $ hledger -f- bal -N --flat
 | |
|                    1  a:k
 | |
|                    1  b:i
 | |
|                    1  b:j
 | |
|                    1  c
 | |
| >=
 | |
| 
 | |
| *** Default sort with account declarations
 | |
| 
 | |
| # 12. With account directives, tree mode.
 | |
| # At each tree level, declared accounts are sorted first, in
 | |
| # declaration order, followed by undeclared accounts sorted alphabetically.
 | |
| # Missing parent accounts are added (b).
 | |
| <
 | |
| account b:k
 | |
| account b:j
 | |
| account d
 | |
| 
 | |
| 2018/1/1
 | |
|   (a:l)  1
 | |
| 
 | |
| 2018/1/1
 | |
|   (b:i)  1
 | |
| 
 | |
| 2018/1/1
 | |
|   (b:j)  1
 | |
| 
 | |
| 2018/1/1
 | |
|   (b:k)  1
 | |
| 
 | |
| 2018/1/1
 | |
|   (c)    1
 | |
| 
 | |
| 2018/1/1
 | |
|   (d)    1
 | |
| 
 | |
| $ hledger -f- bal -N
 | |
|                    1  d
 | |
|                    1  a:l
 | |
|                    3  b
 | |
|                    1    k
 | |
|                    1    j
 | |
|                    1    i
 | |
|                    1  c
 | |
| >=
 | |
| 
 | |
| # 13. With account directives, flat mode.
 | |
| # Unused parent accounts are not added (b).
 | |
| # The b:k, b:j declarations affect the subs of b, not b itself.
 | |
| $ hledger -f- bal -N --flat
 | |
|                    1  d
 | |
|                    1  a:l
 | |
|                    1  b:k
 | |
|                    1  b:j
 | |
|                    1  b:i
 | |
|                    1  c
 | |
| >=
 | |
| 
 | |
| *** Sort by amount
 | |
| 
 | |
| # 14. Rows are sorted by decreasing amount (and then by account), at each tree level. 
 | |
| # Tree mode.
 | |
| 
 | |
| <
 | |
| 2018/1/1
 | |
|   (b:j)  2
 | |
| 
 | |
| 2018/1/1
 | |
|   (c)    1
 | |
| 
 | |
| 2018/1/1
 | |
|   (b:i)  1
 | |
| 
 | |
| 2018/1/1
 | |
|   (a:k)  1
 | |
| 
 | |
| $ hledger -f- bal -N --sort-amount --tree
 | |
|                    3  b
 | |
|                    2    j
 | |
|                    1    i
 | |
|                    1  a:k
 | |
|                    1  c
 | |
| >=
 | |
| 
 | |
| # 15. Flat mode.
 | |
| $ hledger -f- bal -N --flat --sort-amount
 | |
|                    2  b:j
 | |
|                    1  a:k
 | |
|                    1  b:i
 | |
|                    1  c
 | |
| >=
 | |
| 
 | |
| # 16. When the larger amount is composed of differently-priced amounts,
 | |
| # it could get sorted as if smaller (bug in hledger 1.4-1.10). Tree mode.
 | |
| <
 | |
| 2018/1/1
 | |
|   (a)  2X @ 1Y
 | |
|   (a)  2X @ 2Y
 | |
| 
 | |
| 2018/1/1
 | |
|   (b)  3X
 | |
| 
 | |
| $ hledger -f- bal -N --sort-amount
 | |
|                   4X  a
 | |
|                   3X  b
 | |
| >=
 | |
| 
 | |
| # 17. Explicit --tree flag, should be the same as above.
 | |
| $ hledger -f- bal -N --sort-amount --tree
 | |
|                   4X  a
 | |
|                   3X  b
 | |
| >=
 | |
| 
 | |
| # 18. Flat mode.
 | |
| $ hledger -f- bal -N --sort-amount --flat
 | |
|                   4X  a
 | |
|                   3X  b
 | |
| >=
 |