Nice, that is even cleaner. One thing however is if I then later add a
transaction to pay the card, the automatic transaction still applies.

What would be right way to do apply the automatic transaction only when
there is also an Expenses entry? I could not figure out the proper syntax.
I tried something like:

= expr "any(account =~ /^Liabilities:Apple Card/) and any(account =~
/^Expenses/)"

but this does not seem to work. I get some errors if I try removing the
quotes, but I'm likely doing it wrong.

Thanks,

Viraj.

On Thu, Jun 8, 2023 at 3:19 PM Yuri Khan <[email protected]> wrote:

> On Thu, 8 Jun 2023 at 18:53, Alexis <[email protected]> wrote:
>
> > I know of two options to reduce the duplication of the amount value:>
> > 1. Using transaction typed metadata
> >
> >   2023/06/06 McDonalds
> >       ; amount_spent:: $23.98
> >       Expenses:Food:Restaurants                    (tag("amount_spent"))
> >       Liabilities:Apple Card                      (-tag("amount_spent"))
> >       Income:Credit Card Rewards         (-(tag("amount_spent")) * 0.02)
> >       Assets:Apple Cash
> >
> >   See https://ledger-cli.org/doc/ledger3.html#Typed-metadata
>
> One might try to combine typed metadata with automated transactions:
>
>     = Liabilities:Apple Card
>         Assets:Apple Cash           (-tag("cashback"))
>         Income:Credit Card Rewards   (tag("cashback"))
>
>     2023-06-06 McDonalds
>         ; cashback:: 0.02
>         Expenses:Food:Restaurants                    $23.98
>         Liabilities:Apple Card
>
>     $ ledger bal -f test_cashback.ledger
>                    $0.48  Assets:Apple Cash
>                   $23.98  Expenses:Food:Restaurants
>                   $-0.48  Income:Credit Card Rewards
>                  $-23.98  Liabilities:Apple Card
>       --------------------
>                         0
>
> I do not know off the bat how to apply a default 0.02 value if the tag
> is not present, but that is probably possible.
>
> --
>
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "Ledger" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/ledger-cli/tqXZGjJbZSo/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ledger-cli/CAP_d_8W_G-iTxw1XykVCdcpuabu2wQ%3DQZaitAfmx%2BZRR9x6x0w%40mail.gmail.com
> .
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"Ledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ledger-cli/CAM502dMxL4Z%2BJmQh2ai7qA_CH-J4oJ2hBZkPdj-ETjaY%3DRMqWg%40mail.gmail.com.

Reply via email to