Hi,
a couple of things, I am not sure I can bring it into a well structured
message ;-)
First,
> Now what puzzles me is
>
> #+begin_src ledger
> = expr account =~ /Liabilities:[a-zA-z0-9]*$/ and aux_date >=
> [2020/05]
> $account -1.0
> $account:from User1 (roundto(0.5*amount, 0))
> $account:from User2 (amount-roundto(0.5*amount, 0))
> 2021-12-05=2021-12-07 User1
> expenses:Jacket 80
> Liabilities:User1
> 2021-12-05=2021-12-07 User1
> expenses:Pajama 30
> Liabilities:User1
> 2021-12-05=2021-12-07 User2
> expenses:Flowers 20
> Liabilities:User2
> 2021-12-05=2021-12-07 User2
> expenses:ChristmasTree 40.00
> Liabilities:User2
> #+end_src
>
> Here, ledger does not do anything.
Well, it does *something*, it prints a lot of error messages about
unbalanced transactions. I don't know why, but it seems you need a
currency here. If I just add "JPY" after every number in your example,
`ledger bal` shows
```
-170.00 JPY Liabilities
-110.00 JPY User1
-55.00 JPY from User1
-55.00 JPY from User2
-60.00 JPY User2
-30.00 JPY from User1
-30.00 JPY from User2
170.00 JPY expenses
40.00 JPY ChristmasTree
20.00 JPY Flowers
80.00 JPY Jacket
30.00 JPY Pajama
--------------------
0
```
as expected.
Now, as you wrote:
> I rather don't know how to interpret the result, I hoped I would
> automatically know who has to pay whom, what amount.
That is certainly true, and I have to admit I should have elaborated
more on the clearing process.
"Liabilities:User1:from User1" means "this is the amount of User1's
expenses that he should actually pay by himself according to the
decided ratio". That's a bit silly and if there are only the two users
involved maybe a better way to formulate the automated transaction
would be:
```
= expr account =~ /Liabilities:User1$/
$account -1.0
Income:User1 (roundto(0.5*amount, 0))
$account:from User2 (amount-roundto(0.5*amount, 0))
= expr account =~ /Liabilities:User2$/
$account -1.0
$account:from User1 (roundto(0.5*amount, 0))
Income:User2 (amount-roundto(0.5*amount, 0))
```
Then your balance does not have the silly "liabilities towards self"
lines any more:
```
-85.00 JPY Income
-55.00 JPY User1
-30.00 JPY User2
-85.00 JPY Liabilities
-55.00 JPY User1
-55.00 JPY from User2
-30.00 JPY User2
-30.00 JPY from User1
170.00 JPY expenses
40.00 JPY ChristmasTree
20.00 JPY Flowers
80.00 JPY Jacket
30.00 JPY Pajama
--------------------
0
```
However, you still need to do some manual balancing of
"Liabilities:User1:from User2" and "Liabilities:User2:from User1",
concretely you would need two transactions:
```
# this is just for internal accounting purposes, no money
# is handed over to anyone
2021-12-08=2021-12-08 Counterbalancing
Income:User1 -30 JPY
Liabilities:User2:from User1 30 JPY
Income:User2 -30 JPY
Liabilities:User1:from User2 30 JPY
# this is the thing that you are actually interested in:
# User2 needs to pay User1 an additional 25 JPY
2021-12-08=2021-12-08 Payback Time
Income:User2 -25 JPY
Liabilities:User1:from User2 25 JPY
```
If you do that, then the balance looks as you would like:
```
-170.00 JPY Income
-85.00 JPY User1
-85.00 JPY User2
170.00 JPY expenses
40.00 JPY ChristmasTree
20.00 JPY Flowers
80.00 JPY Jacket
30.00 JPY Pajama
--------------------
0
```
However, you understandably would like to avoid the manual computations
needed with this process. The key to that is to
1. use only a single account for liabilities between user, and use
the sign of this account's amount to determine who needs to pay
whom, and
2. do the counterbalancing implicitly in each transaction.
However, I feel that in particular (1) is somewhat contrary to the idea
of double-entry accounting, and by using only a single account for
directional liabilities you get quite a bit of asymmetry into the
automated transactions.
Consider
```
= expr account =~ /Liabilities:User1$/
$account -1.0
Income:User1 1.0
Liabilities:User1-from-User2 (-(amount-roundto(0.5*amount, 0)))
Income:User2 (amount-roundto(0.5*amount, 0))
= expr account =~ /Liabilities:User2$/
$account -1.0
Income:User2 (amount-roundto(0.5*amount, 0))
Liabilities:User1-from-User2 (roundto(0.5*amount, 0))
```
then your example transactions leave you with a balance (before
clearing) of
```
-195.00 JPY Income
-110.00 JPY User1
-85.00 JPY User2
25.00 JPY Liabilities:User1-from-User2
170.00 JPY expenses
40.00 JPY ChristmasTree
20.00 JPY Flowers
80.00 JPY Jacket
30.00 JPY Pajama
--------------------
0
```
so you can see easily that User1 gets 25 JPY from User2, which is
realized by the following clearing transaction:
```
# User2 needs to pay User1 an additional 25 JPY
2021-12-08=2021-12-08 Payback Time
Income:User1 25 JPY
Liabilities:User1-from-User2 -25 JPY
```
I think this is fairly close to what you imagined, but personally I
feel that
- the automated transactions are hard to understand
- maybe it's just a matter of naming accounts, but I think there
are some postings now that do not reflect the actual situation in
anyone's wallet,
so I think I'd still prefer the method of two liabilities accounts that
are then counterbalanced against each other, but maybe you can build a
flow that works well for you based on this.
Hope this helps
Tobias