That's the current most robust way. Otherwise, it can fail due to stack's progress output as it reinstalls hledger libs, and that reinstallation also forces all the addons to be relinked.
		
			
				
	
	
		
			251 lines
		
	
	
		
			5.7 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			251 lines
		
	
	
		
			5.7 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
| # Tests for rewrite addon
 | |
| 
 | |
| # Add proportional income tax (from documentation)
 | |
| ../../bin/hledger-rewrite -f- ^income --add-posting '(liabilities:tax)  *.33  ; income tax'
 | |
| <<<
 | |
| 2016/1/1 paycheck
 | |
|     income:remuneration     $-100
 | |
|     income:donations         $-15
 | |
|     assets:bank
 | |
| 
 | |
| 2016/1/1 withdraw
 | |
|     assets:cash             $20
 | |
|     assets:bank
 | |
| >>>
 | |
| 2016/01/01 paycheck
 | |
|     income:remuneration           $-100
 | |
|     income:donations               $-15
 | |
|     assets:bank
 | |
|     (liabilities:tax)              $-33    ; income tax
 | |
|     (liabilities:tax)               $-5    ; income tax
 | |
| 
 | |
| 2016/01/01 withdraw
 | |
|     assets:cash             $20
 | |
|     assets:bank
 | |
| 
 | |
| >>>2
 | |
| >>>=0
 | |
| 
 | |
| # Duplicate posting for budgeting (from documentation)
 | |
| ../../bin/hledger-rewrite -f- expenses:gifts --add-posting '(budget:gifts)  *-1'
 | |
| <<<
 | |
| 2016/1/1 withdraw
 | |
|     assets:cash     $20
 | |
|     assets:bank
 | |
| 
 | |
| 2016/1/1 gift
 | |
|     assets:cash     $-15
 | |
|     expenses:gifts  ; [1/2]
 | |
| >>>
 | |
| 2016/01/01 withdraw
 | |
|     assets:cash             $20
 | |
|     assets:bank
 | |
| 
 | |
| 2016/01/01 gift
 | |
|     assets:cash               $-15
 | |
|     expenses:gifts        ; [1/2]
 | |
|     (budget:gifts)            $-15    ; [2016/01/02]
 | |
| 
 | |
| >>>2
 | |
| >>>=0
 | |
| 
 | |
| # Add postings in another commodity
 | |
| ../../bin/hledger-rewrite -f-
 | |
| <<<
 | |
| 2017/04/24 * 09:00-09:25
 | |
|     (assets:unbilled:client1)           0.42h
 | |
| 
 | |
| 2017/04/25 * 10:00-11:15
 | |
|     (assets:unbilled:client1)           1.25h
 | |
| 
 | |
| 2017/04/25 * 14:00-15:32
 | |
|     (assets:unbilled:client2)           1.54h
 | |
| 
 | |
| ; billing rules
 | |
| = ^assets:unbilled:client1
 | |
|   (assets:to bill:client1)   *100.00 CAD
 | |
| 
 | |
| = ^assets:unbilled:client2
 | |
|   (assets:to bill:client2)   *150.00 CAD
 | |
| >>>
 | |
| 2017/04/24 * 09:00-09:25
 | |
|     (assets:unbilled:client1)           0.42h
 | |
|     (assets:to bill:client1)        42.00 CAD
 | |
| 
 | |
| 2017/04/25 * 10:00-11:15
 | |
|     (assets:unbilled:client1)           1.25h
 | |
|     (assets:to bill:client1)       125.00 CAD
 | |
| 
 | |
| 2017/04/25 * 14:00-15:32
 | |
|     (assets:unbilled:client2)           1.54h
 | |
|     (assets:to bill:client2)       231.00 CAD
 | |
| 
 | |
| >>>2
 | |
| >>>=0
 | |
| 
 | |
| 
 | |
| # Add postings with prices
 | |
| ../../bin/hledger-rewrite -f- -B
 | |
| <<<
 | |
| 2017/04/24 * 09:00-09:25
 | |
|     (assets:unbilled:client1)         0.42h
 | |
| 
 | |
| 2017/04/25 * 10:00-11:15
 | |
|     (assets:unbilled:client1)         1.25h
 | |
| 
 | |
| 2017/04/25 * 14:00-15:32
 | |
|     (assets:unbilled:client2)         1.54h
 | |
| 
 | |
| ; billing rules
 | |
| = ^assets:unbilled:client1
 | |
|   assets:to bill:client1   *1.00 hours @ $100.00
 | |
|   income:consulting:client1
 | |
| 
 | |
| = ^assets:unbilled:client2
 | |
|   assets:to bill:client2   *1.00 hours @ $150.00
 | |
|   income:consulting:client2
 | |
| >>>
 | |
| 2017/04/24 * 09:00-09:25
 | |
|     (assets:unbilled:client1)           0.42h
 | |
|     assets:to bill:client1             $42.00
 | |
|     income:consulting:client1
 | |
| 
 | |
| 2017/04/25 * 10:00-11:15
 | |
|     (assets:unbilled:client1)           1.25h
 | |
|     assets:to bill:client1            $125.00
 | |
|     income:consulting:client1
 | |
| 
 | |
| 2017/04/25 * 14:00-15:32
 | |
|     (assets:unbilled:client2)           1.54h
 | |
|     assets:to bill:client2            $231.00
 | |
|     income:consulting:client2
 | |
| 
 | |
| >>>2
 | |
| >>>=0
 | |
| 
 | |
| # Add absolute bank processing fee
 | |
| ../../bin/hledger-rewrite -f- assets:bank and 'amt:<0' --add-posting 'expenses:fee  $5'  --add-posting 'assets:bank  $-5'
 | |
| <<<
 | |
| 2016/1/1 withdraw
 | |
|     assets:cash     $20
 | |
|     assets:bank
 | |
| 
 | |
| 2016/1/2 withdraw
 | |
|     assets:cash
 | |
|     assets:bank     $-30
 | |
| 
 | |
| # # TODO: Fix to filter out this txn by missing amt:<0 condition on assets:bank
 | |
| # 2016/1/31 paycheck
 | |
| #     income:remuneration     $-100
 | |
| #     assets:bank
 | |
| >>>
 | |
| 2016/01/01 withdraw
 | |
|     assets:cash              $20
 | |
|     assets:bank
 | |
|     expenses:fee              $5
 | |
|     assets:bank              $-5
 | |
| 
 | |
| 2016/01/02 withdraw
 | |
|     assets:cash
 | |
|     assets:bank             $-30
 | |
|     expenses:fee              $5
 | |
|     assets:bank              $-5
 | |
| 
 | |
| >>>2
 | |
| >>>=0
 | |
| 
 | |
| # Rewrite rule within journal
 | |
| ../../bin/hledger-rewrite -f- date:2017/1  --add-posting 'Here comes Santa  $0'
 | |
| <<<
 | |
| = ^assets:bank$ date:2017/1 amt:<0
 | |
|     assets:bank  *0.008
 | |
|     expenses:fee  *-0.008  ; cash withdraw fee
 | |
| = ^expenses:housing
 | |
|     (budget:housing)  *-1
 | |
| = ^expenses:grocery ^expenses:food
 | |
|     (budget:food)  *-1
 | |
| 
 | |
| 2016/12/31
 | |
|     expenses:housing  $600
 | |
|     assets:cash
 | |
| 
 | |
| 2017/1/1
 | |
|     expenses:food  $20
 | |
|     expenses:leisure  $15
 | |
|     expenses:grocery  $30
 | |
|     assets:cash
 | |
| 
 | |
| 2017/1/2
 | |
|     assets:cash  $200.00
 | |
|     assets:bank
 | |
| 
 | |
| 2017/2/1
 | |
|     assets:cash  $100.00
 | |
|     assets:bank
 | |
| 
 | |
| ; order with normal entries doesn't matter
 | |
| ; but relative order matters to refer-rewritten transactions
 | |
| = ^expenses not:housing not:grocery not:food
 | |
|     (budget:misc)  *-1
 | |
| >>>
 | |
| 2016/12/31
 | |
|     expenses:housing         $600.00
 | |
|     assets:cash
 | |
| 
 | |
| 2017/01/01
 | |
|     expenses:food             $20.00
 | |
|     expenses:leisure          $15.00
 | |
|     expenses:grocery          $30.00
 | |
|     assets:cash
 | |
|     Here comes Santa               0
 | |
|     Here comes Santa               0
 | |
|     Here comes Santa               0
 | |
|     Here comes Santa               0
 | |
|     (budget:food)            $-20.00
 | |
|     (budget:food)            $-30.00
 | |
|     (budget:misc)            $-15.00
 | |
| 
 | |
| 2017/01/02
 | |
|     assets:cash              $200.00
 | |
|     assets:bank
 | |
|     Here comes Santa               0
 | |
|     Here comes Santa               0
 | |
|     assets:bank               $-1.60
 | |
|     expenses:fee               $1.60    ; cash withdraw fee
 | |
|     (budget:misc)             $-1.60
 | |
| 
 | |
| 2017/02/01
 | |
|     assets:cash         $100.00
 | |
|     assets:bank
 | |
| 
 | |
| >>>2
 | |
| >>>=0
 | |
| 
 | |
| # Rewrite using diff output
 | |
| ../../bin/hledger-rewrite --diff -f- assets:bank and 'amt:<0' --add-posting 'expenses:fee  $5'  --add-posting 'assets:bank  $-5'
 | |
| <<<
 | |
| 2016/01/01 withdraw
 | |
|     assets:cash              $20
 | |
|     assets:bank
 | |
| 
 | |
| 2016/01/02 withdraw
 | |
|     assets:cash
 | |
|     assets:bank             $-30
 | |
| >>>
 | |
| --- -
 | |
| +++ -
 | |
| @@ -1,3 +1,5 @@
 | |
|  2016/01/01 withdraw
 | |
|      assets:cash              $20
 | |
|      assets:bank
 | |
| +    expenses:fee              $5
 | |
| +    assets:bank              $-5
 | |
| @@ -5,3 +7,5 @@
 | |
|  2016/01/02 withdraw
 | |
|      assets:cash
 | |
|      assets:bank             $-30
 | |
| +    expenses:fee              $5
 | |
| +    assets:bank              $-5
 | |
| >>>2
 | |
| >>>=0
 |