50% of the balance?

I am trying to create a report that will help me with my tax work. I am importing CSV statements from banks, which give me gross interest for my savings accounts.

Some of those accounts are mine alone, and I am liable for tax on all gross interest. Some, however, are joint, and I am liable for tax on just half of gross interest. Interest transactions are (of course!) not split by bank 50/50; they are often just one lump sum arriving in a single transaction.

I am trying to figure a way to get a report that gives me "the balance of all interest transactions in those accounts, and half of the balance in those other accounts", and I am trying to keep it simple.

My "plan B" is to either write a small haskell script that uses hledger-lib or a small python script that post-processes the output of "hledger balance". Both of these options make me a bit sad.

I wonder if anyone has done anything similar in the past?

I found a way to do it with auto postings:

$ hledger bal revenues:interest
             $ -0.96  JS:revenues:interest
             $ -0.37  sm:revenues:interest
--------------------
             $ -1.33  

To halve just the JS total, add this rule somewhere in the journal:

= JS:revenues:interest
    (JS:revenues:interest)  *-.5

And activate it with --auto:

$ hledger bal revenues:interest --auto
             $ -0.48  JS:revenues:interest
             $ -0.37  sm:revenues:interest
--------------------
             $ -0.85  

I tried at first to supply the rule as an extra file, eg with -f <(printf ...) on the command line, but found auto posting rules don't affect sibling files · Issue #1212 · simonmichael/hledger · GitHub, unfortunately.

PS: here's a one-liner that works:

printf "= JS:revenues:interest\n (JS:revenues:interest)  *-.5\ninclude $LEDGER_FILE\n" | hledger -f- --auto bal revenues:interest

Thank you very much, this seems to be exactly what I want