hledger/tests/balance/percent.test
Michael Kainer 79ca4a767e cli: Add -% to compound balance commands
This commit introduces the commandline argument -%/--percent to show
percentages of the column's total instead of the absolute amounts for
each account in reports. The signs of the values are preserved.

This option is especially useful for the balance and incomestatement
commands.

If there are multiple commodities involved in a report hledger bails
with an error message. This can be avoided by using --cost. Also note
that if one uses -% with the balance command the chances are high that
all numbers are 0. This is due to the fact that by default balance sums
up to zero. If one wants to use -% in a meaningful way with balance one
has to add a query.

In order to keep the implementation as simple as possible --tree has no
influence over how the percentages are calculated, i.e., the percentages
always represent the fraction of the columns total. If one wants to know
the percentages relative to a parent account, one has to use a query to
narrow down the accounts.
2019-11-18 17:10:59 -08:00

43 lines
1.4 KiB
Plaintext

#!/usr/bin/env shelltest
# 1. Single column percent
hledger -f sample.journal balance expenses -%
>>>
100.0 % expenses
50.0 % food
50.0 % supplies
--------------------
100.0 %
>>>= 0
# 2. Multi column percent
hledger -f sample.journal balance expenses -% -p daily
>>>
Balance changes in 2008/06/03:
|| 2008/06/03
===================++============
expenses:food || 50.0 %
expenses:supplies || 50.0 %
-------------------++------------
|| 100.0 %
>>>= 0
# 3. In a balanced ledger everything should sum up to zero, therefore all percentages should be zero.
hledger -f sample.journal balance -% -p quarterly
>>>
Balance changes in 2008:
|| 2008q1 2008q2 2008q3 2008q4
======================++================================
assets:bank:checking || 0 0 0 0
assets:bank:saving || 0 0 0 0
assets:cash || 0 0 0 0
expenses:food || 0 0 0 0
expenses:supplies || 0 0 0 0
income:gifts || 0 0 0 0
income:salary || 0 0 0 0
liabilities:debts || 0 0 0 0
----------------------++--------------------------------
|| 0 0 0 0
>>>= 0