query metadata in automated transactions?

271 views
Skip to first unread message

Eric Abrahamsen

unread,
May 15, 2014, 6:57:49 AM5/15/14
to ledge...@googlegroups.com
Is it possible to see transaction metadata when doing matching for
automated transactions? For some arbitrary transactions, I want to be
able to say "I got a receipt for this transaction", and then add a
virtual posting for the amount of the transaction, into Assets:Receipts.
Ideally, I'd also be able to give an amount for the metadata, and if
it's present use that instead of the transaction amount. So if I had
this transaction:

05/15 Shoe Store
; Receipt
Expenses:Personal:Clothes $50
Assets:Cash

I would get an automatic:

(Assets:Receipts) $50

But if I had:

05/15 Fancy Restaurant
; Receipt: $240
Expenses:Food:Restaurant $82
Assets:Cash

I would get the automatic:

(Assets:Receipts) $240


Is that possible? The manual doesn't mention anything like this...

Thanks!

Eric

John Wiegley

unread,
May 16, 2014, 6:08:32 PM5/16/14
to ledge...@googlegroups.com
>>>>> Eric Abrahamsen <er...@ericabrahamsen.net> writes:

> Is it possible to see transaction metadata when doing matching for automated
> transactions?

Yes, if you start the automated transaction directive with "= expr ", then you
can use any value expression, which includes "tag('NAME')", whose value is
whatever the metadata tag as set to.

John

Eric Abrahamsen

unread,
May 16, 2014, 7:27:03 PM5/16/14
to ledge...@googlegroups.com
Very cool, thanks for the explanation!

Eric Abrahamsen

unread,
May 18, 2014, 1:48:21 AM5/18/14
to ledge...@googlegroups.com
Okay, I'm nearly there, but not quite. My test data looks like this:

05/15 * Taxi
; Receipt: 40 RMB
Expenses:Transportation 23 RMB
Assets:Cash

05/15 * BHG
; Receipt:
Expenses:Food:Supermarket 154 RMB
Assets:Bank

I've got the simple case (just making an automated transaction when the
"Receipt" tag appears) working, with this:

= tag("Receipt") and /^expenses:(transportation|food|books)/
(Assets:Receipts) 1

My best guess for the complicated case (using the value of the Receipt
tag, when present, instead of the posting value) is this:

= expr recpt = tag("Receipt") and expr account =~ /^expenses:(transportation|food|books)/
(Assets:Receipts) ((recpt > 0) ? recpt : 1)

But running that gives me this error:

While parsing value expression:
recpt = tag("Receipt"

While parsing automated transaction:
> = expr recpt = tag("Receipt") and expr account =~ /^expenses:(transportation|food|books)/
Error: Invalid token '<end of input>' (wanted ')')

I'm not sure if this is a bug, or if I'm just writing it wrong. Should
it work as I've got it?

Thanks again,
Eric

John Wiegley

unread,
May 18, 2014, 2:47:23 PM5/18/14
to ledge...@googlegroups.com
>>>>> Eric Abrahamsen <er...@ericabrahamsen.net> writes:

> = expr recpt = tag("Receipt") and expr account =~
> /^expenses:(transportation|food|books)/ (Assets:Receipts) ((recpt > 0) ?
> recpt : 1)

Only use "expr" at the beginning.

John

Eric Abrahamsen

unread,
May 18, 2014, 9:28:18 PM5/18/14
to ledge...@googlegroups.com
Still getting the same error without the second "expr". Just reducing
the matching line to this:

= expr recpt = tag("Receipt")

Is enough to get the "Invalid token" parsing error. Tried it with single
quotes around Receipt as well...

Thanks,
Eric

John Wiegley

unread,
May 21, 2014, 2:48:51 PM5/21/14
to ledge...@googlegroups.com
>>>>> Eric Abrahamsen <er...@ericabrahamsen.net> writes:

> "John Wiegley" <jo...@newartisans.com> writes:
>>>>>>> Eric Abrahamsen <er...@ericabrahamsen.net> writes:
>>
>>> = expr recpt = tag("Receipt") and expr account =~
>>> /^expenses:(transportation|food|books)/ (Assets:Receipts) ((recpt > 0) ?
>>> recpt : 1)
>>
>> Only use "expr" at the beginning.

> Still getting the same error without the second "expr". Just reducing the
> matching line to this:

Try this maybe?

= expr has_tag("Receipt") and expr account =~
/^expenses:(transportation|food|books)/ (Assets:Receipts) ((tag("Receipt") > 0) ? tag("Receipt") : 1)

John

Eric Abrahamsen

unread,
May 21, 2014, 10:39:46 PM5/21/14
to ledge...@googlegroups.com
No, I'd tried that one before. It looks like parenthesis inside any
"expr" clause will cause the parsing error. If there's no "expr", the
parenthesis is read correctly and things seem to work. In your above
suggestion, I got the parsing error at ("Receipt". If I take out the
first "expr", I get the parsing error at (transportation|food|books)/,
saying: Error: Missing '/'.

The only way I can get it to work is to have no first "expr", use tag
instead of has_tag (using has_tag simply produces no results), and have
no parenthesis in the "expr account" clause.

The ternary expression works if given as:

((to_amount(tag("Receipt")) > 0) ? to_amount(tag("Receipt")) : 1)

So really all I'm missing there is the ability to match:

= expr amount = to_amount(tag("Receipt")) and expr etc etc etc

with parentheses in.

Sorry to keep on with this -- it seems like a hassle just to get a
little convenience. On the other hand, it really does seem to be just
the one issue!

Thanks,
Eric

John Wiegley

unread,
May 22, 2014, 3:45:49 PM5/22/14
to ledge...@googlegroups.com
>>>>> Eric Abrahamsen <er...@ericabrahamsen.net> writes:

> No, I'd tried that one before. It looks like parenthesis inside any "expr"
> clause will cause the parsing error. If there's no "expr", the parenthesis
> is read correctly and things seem to work. In your above suggestion, I got
> the parsing error at ("Receipt". If I take out the first "expr", I get the
> parsing error at (transportation|food|books)/, saying: Error: Missing '/'.

Sorry, copy and paste bug, the second "expr" shouldn't appear.

> The only way I can get it to work is to have no first "expr", use tag
> instead of has_tag (using has_tag simply produces no results), and have no
> parenthesis in the "expr account" clause.

> The ternary expression works if given as:

> ((to_amount(tag("Receipt")) > 0) ? to_amount(tag("Receipt")) : 1)

> So really all I'm missing there is the ability to match:

> = expr amount = to_amount(tag("Receipt")) and expr etc etc etc

> with parentheses in.

Yes, you can't do variable assignments like this at the moment.

John

Eric Abrahamsen

unread,
May 22, 2014, 10:24:53 PM5/22/14
to ledge...@googlegroups.com
Okay, no worries. Thanks for your help!

Eric

Reply all
Reply to author
Forward
0 new messages