Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feedback] Rule action templating #3606

Open
matt-fidd opened this issue Oct 8, 2024 · 27 comments
Open

[Feedback] Rule action templating #3606

matt-fidd opened this issue Oct 8, 2024 · 27 comments
Labels
experimental feature Related to an experimental feature feedback Single feedback thread for bug reports on a new feature rules Related to rules

Comments

@matt-fidd
Copy link
Contributor

matt-fidd commented Oct 8, 2024

Rule action templating allows rules to dynamically set fields based on transaction data.

To enable the feature - head over to experimental features and toggle the rule action templating feature flag. Next, go to the "rules" page and set up a new rule.

To use it, click the icon on the right hand side of the input box to toggle from "text" to "template" mode:
Text mode:
image
Template mode:
image

Then enter your template. For example, the below will replace the notes field with the VAT paid (standard VAT is 20% in the uk)
image

At the moment, templating is supported for setting:

  • notes
  • date
  • amount
  • cleared (although no boolean helper functions are currently supported)

Full list of available helper functions:

  • regex value regex replacement
  • add num1 num2 ...
  • sub num1 num2 ...
  • div num1 num2 ...
  • mul num1 num2 ...
  • mod num1 num2 ...
  • floor num
  • ceil num
  • round num
  • abs num
  • min num1 num2 ...
  • max num1 num2 ...
  • fixed num1 num2
  • day date
  • month date
  • year date
  • format date format
  • debug value (logs to console)

Full list of available variables that can be used

  • today (date)
  • account (id)
  • amount (number)
    • remember this is stored without the decimal place. ie. £152 will be 15200. {{div amount 100}} can be used to convert back
  • cleared (boolean)
  • date (date)
  • error (?)
  • imported_id (id)
  • imported_payee (string)
  • is_child (boolean)
  • is_parent (boolean)
  • notes (string)
  • parent_id (id)
  • payee (id)
  • reconciled (boolean)
  • schedule (id)
  • sort_order (number)
  • starting_balance_flag (boolean)
  • tombstone (boolean)
  • transfer_id (id)

Feel free to share your ideas, bug reports and feedback below.

@matt-fidd matt-fidd added rules Related to rules experimental feature Related to an experimental feature feedback Single feedback thread for bug reports on a new feature labels Oct 8, 2024
@youngcw
Copy link
Member

youngcw commented Oct 8, 2024

Some additional variables I would appreciate being added are:

  1. Current Balance of Account (extra bonus points for average monthly balance). This would be nice for automatically determining interest amounts that are included in a mortgage payment for example.

  2. Account balance on day. Useful for determining what a paid in full credit card payment will be dynamically based on current balance of the CC account within a window. (EX. Balance_today- Balance_one_month_prior = payment amount)

@UnderKoen
Copy link
Member

Some additional variables I would appreciate being added are:

  1. Current Balance of Account (extra bonus points for average monthly balance). This would be nice for automatically determining interest amounts that are included in a mortgage payment for example.
  2. Account balance on day. Useful for determining what a paid in full credit card payment will be dynamically based on current balance of the CC account within a window. (EX. Balance_today- Balance_one_month_prior = payment amount)

I think these could best be added as helper functions. Especially the second one.
We could use https://github.com/gastonrobledo/handlebars-async-helpers/ to make an helper that fetches on execution

@mullermn
Copy link

This looks incredibly powerful, I will turn this on and start playing with it.

My condolences to whoever eventually takes on the task of building a UI for this! 😃

@UnderKoen
Copy link
Member

I don't thing there will ever be an UI for this, (at most an helper to show which fields are available). As that it would most likely limit the usage of this function.

@UnderKoen
Copy link
Member

Maybe fun to share, my current rules with templating
image

@IsThisThingStillOn
Copy link

IsThisThingStillOn commented Oct 28, 2024

I'd love to see some examples of using the date functions. As of now I have only successfully got a result with {{today}}. {{day today}} for example doesn't bring up any result. {{date}} doesn't work.

What surprisingly worked was {{regex today "-[0-9]{2}-[0-9]{2}" "-11-01"}} to set the date.

But right now making date calculations doesn't seem to be supported at all, is that assumption correct? I'd love to see that as a feature. Along with other date functions (first of month, end of month etc.)

/E:
After fix #3749 day, month and year work as intended.

To everyone interested, the following rule template will move the transaction to the first of the next month (including changing the year):

{{add (year date) (floor (div (add (month date) 1) 13))}}-{{add (mod (month date) 12) 1}}-1

@londondev77
Copy link

Not sure if I'm using this wrong but I'm trying to do a currency conversion by using the following rule to set the amount:
{{ div amount 119.76 }}

I thought maybe it was down to decimal places so I also tried:
{{ fixed (div amount 119.76) 2 }}

Both result in the following error:
There was an internal error. Please get in touch https://actualbudget.org/contact for support.

If I look at the console, it shows:
Internal error: Error: Can’t convert to integer: -62.83

If I use the same rule but to set the note rather than the amount, then it works fine.

@UnderKoen
Copy link
Member

@londondev77 the amount should be in cents (*100). Decimals are not allowed,

@londondev77
Copy link

Thanks. I misread the note about decimal places in the instructions at the top.

Unfortunately I can't test for the rest of the day as I've used up my GoCardless rate today.

@IsThisThingStillOn
Copy link

@londondev77 You don't need to import transactions to test this. In the edit window of each rule you see a list of matching transactions. Just click the checkbox in the leftmost column and then click "Apply actions" in the top right above said list.

@youngcw
Copy link
Member

youngcw commented Nov 4, 2024

Another useful value for the templating would be the balance of a budget category.

For example in a split rule have a split line of amount = balance of and a second split line of amount = remainder.

@TWilhoWI
Copy link

TWilhoWI commented Nov 7, 2024

Could someone help me with following: I got a monthly payment for savings. This is categorised as payment, but I want to categorise it a deposit. So from - to +. How can I do this? Amount does change every month.

@UnderKoen
Copy link
Member

UnderKoen commented Nov 7, 2024

@TWilhoWI
image
{{mul amount -1}}

@TWilhoWI
Copy link

TWilhoWI commented Nov 7, 2024

Thank you very much!

@nmathey
Copy link
Contributor

nmathey commented Nov 7, 2024

Wow this looks powerful!
would it be possible to extend templating to "conditions match" criterias?
Basically I would like to action a rule if the amount is a decimal number.

@IsThisThingStillOn
Copy link

@nmathey
You can already so that with the regular filters

For payments:
amount is less than -0.00
amount is greater than -1.00

For deposits:
amount is greater than -0,00
amount is less than +1,00

@nmathey
Copy link
Contributor

nmathey commented Nov 12, 2024

Mmmm rule doesn't match any

image

image

@youngcw
Copy link
Member

youngcw commented Nov 12, 2024

Mmmm rule doesn't match any

image

image

There isn't any templating in that rule. Also it looks like that transaction is out of range.

@nmathey
Copy link
Contributor

nmathey commented Nov 12, 2024

Yeah I just tried to apply whats @IsThisThingStillOn were referring too even if it looked weird for me as is.
I want to basically match any decimal number not only a range and do not match if integer: that was my point to extend templating rule in "conditions match" in order to extend filter possibility.
If it is still valid for my use case, I'll switch to discord to avoid polluting this thread.

@UnderKoen
Copy link
Member

Basically I would like to action a rule if the amount is a decimal number.

We could achieve this by adding regex matching to the amount field. I will look if I can get this working.

@gael-vanderlee
Copy link

My imported payees always start with "CARDXXXX" or "CARDXXXX DD/MM", would this new feature allow me to remove those automatically ?

@youngcw
Copy link
Member

youngcw commented Nov 15, 2024

My imported payees always start with "CARDXXXX" or "CARDXXXX DD/MM", would this new feature allow me to remove those automatically ?

It could, but you probably should be able to use a regular "imported_payee"-"contains" rule and not need to use a template rule.

@gael-vanderlee
Copy link

gael-vanderlee commented Nov 15, 2024

@youngcw Ah nice !
How would I set that up in the payee section ? I'd like a rule that goes for any transaction of the form CARD XXXX DD/MM YYYYY:

  • If imported payee matches (regex expression)
  • Set payee to YYYY

I'm struggling to know how to extract the YYYY information from the imported payee to set it in the payee field. Hope that makes sense

@youngcw
Copy link
Member

youngcw commented Nov 15, 2024

@youngcw Ah nice ! How would I set that up in the payee section ? I'd like a rule that goes for any transaction of the form CARD XXXX DD/MM YYYYY:

  • If imported payee matches (regex expression)
  • Set payee to YYYY

I'm struggling to know how to extract the YYYY information from the imported payee to set it in the payee field. Hope that makes sense

I don't think you need to extract anything. Use if imported payee contains "Grocery Store", set payee "Grocery Store"

@gael-vanderlee
Copy link

gael-vanderlee commented Nov 15, 2024

@youngcw Ah yes I already do that, but a universal rule on import would help a lot with readability when sorting through the transactions. Hopefully that's possible with rule action templating.

Since the proposed solution includes regex replacement and imported payee, it's looking promising !

@matt-fidd
Copy link
Contributor Author

matt-fidd commented Nov 15, 2024

@youngcw Ah yes I already do that, but a universal rule on import would help a lot with readability when sorting through the transactions. Hopefully that's possible with rule action templating.

I think you should be able to do something like the below... it might need a bit of tweaking though

if: imported payee contains "CARD" (regex is not availble for rule criteria) AND account = the account you're seeing this on
set payee = {{regex imported_payee "^CARD\s.*\s\d{2}\\\d{2}\s(.*)$" "$1"}}

@gael-vanderlee
Copy link

gael-vanderlee commented Nov 15, 2024

Had to make a few tweaks (mine is in french so "Carte XXXXX" and the date field is optional). For those interested, the final formula is {{regex imported_payee "^Carte X\d{4}(\s+\d{2}/\d{2})?\s+(.*)$" "$2"}}
Thank you very much for the help ! Came to github to make a feature request and left with a working solution :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
experimental feature Related to an experimental feature feedback Single feedback thread for bug reports on a new feature rules Related to rules
Projects
None yet
Development

No branches or pull requests

9 participants