amount multipliers based on the value of a tag

44 views
Skip to first unread message

mail....@gmail.com

unread,
Jun 22, 2020, 4:39:36 PM6/22/20
to Ledger
Hi, 
Can an "amount multiplier" in an "automated transaction" be based on the value of a tag?

Something like: 

= /My:Bank:?/ & %/SHARED/
    (Me->Roommate)            to_val(tag("SHARED"))

Basically, I want to achieve parameterized sharing between e.g., me and a roommate.

Thanks,
Dimitar

John Wiegley

unread,
Jun 24, 2020, 1:14:45 AM6/24/20
to mail....@gmail.com, Ledger
>>>>> "mm" == mail mitko <mail....@gmail.com> writes:

mm> Can an "amount multiplier" in an "automated transaction" be based on the
mm> value of a tag?

Sounds like an interesting idea. You'd have to use this:

(Me->Roommate) (to_val(tag("SHARED")))

Not sure if it works, though!

John

Dimitar Dimitrov

unread,
Jun 24, 2020, 8:27:32 AM6/24/20
to John Wiegley, Ledger
> Sounds like an interesting idea. You'd have to use this:
>
> (Me->Roommate) (to_val(tag("SHARED")))
>
> Not sure if it works, though!

It appears to work (it helps me to considerably simplify my design). I used

(Me->Roommate) (to_amount(tag("SHARED")))

The documentation of `to_amount` says "For internal use only". Is there
a more appropriate function that I can use? And one more thing: it would
be nice to be able to specify fractional amounts, e.g., "SHARED: 1/3"
instead of "SHARED: .0333333" (but `to_amount` doesn't seem to support
this). Any ideas?

Thanks,
Dimitar

Martin Michlmayr

unread,
Jun 24, 2020, 8:32:21 AM6/24/20
to ledge...@googlegroups.com, John Wiegley
* Dimitar Dimitrov <mail....@gmail.com> [2020-06-24 14:27]:
> The documentation of `to_amount` says "For internal use only". Is
> there a more appropriate function that I can use? And one more
> thing: it would be nice to be able to specify fractional amounts,
> e.g., "SHARED: 1/3" instead of "SHARED: .0333333" (but `to_amount`
> doesn't seem to support this). Any ideas?

Use:
; SHARED:: (1/3)

as in:

2020-06-24 * Test
; SHARED:: (1/3)
Assets:My:Bank:Foo 30.00
Assets:Test

--
Martin Michlmayr
https://www.cyrius.com/

Dimitar Dimitrov

unread,
Jun 24, 2020, 9:49:51 AM6/24/20
to ledge...@googlegroups.com, Martin Michlmayr

> Use:
> ; SHARED:: (1/3)
>
> as in:
>
> 2020-06-24 * Test
> ; SHARED:: (1/3)
> Assets:My:Bank:Foo 30.00
> Assets:Test

Indeed, the documentation explains it well (I must have missed it) -
thanks.

It appears that, in this case, the braces are optional and one can
use ; SHARED:: 1/3. Furthermore, if one uses the SHARED:: construct,
`to_amount` in no longer necessary.

Dimitar

John Wiegley

unread,
Jun 24, 2020, 10:30:07 AM6/24/20
to Dimitar Dimitrov, ledge...@googlegroups.com, Martin Michlmayr
>>>>> "DD" == Dimitar Dimitrov <mail....@gmail.com> writes:

DD> It appears that, in this case, the braces are optional and one can use ;
DD> SHARED:: 1/3. Furthermore, if one uses the SHARED:: construct, `to_amount`
DD> in no longer necessary.

This is correct. `::` interprets the metadata value as an amount, whereas `:`
takes it as a plain string.

John
Reply all
Reply to author
Forward
0 new messages