"insert-entry" How to make specific account to be judged first?
Like I have 2022-02-01 custom "fava-option" "insert-entry" ".*" in file other.bean ,
and 2022-02-01 custom "fava-option" "insert-entry" "Account1" in file foo\Account1.bean
What I expect is the transcation about Account1 would be stored into foo\Account1.bean, but actually it will be stored into other.bean.
Is these options sorted by directory structure? Or if I did a wrong use, how could I fix it?
Now I have
2022-02-01 custom "fava-option" "insert-entry" ".*" in 02\other.bean
2022-03-01 custom "fava-option" "insert-entry" "Account1" in 03\other.bean
2022-02-01 custom "fava-option" "insert-entry" ".*" in 02\Account1.bean
2022-03-01 custom "fava-option" "insert-entry" "Account1" in 03\Account1.bean
and when I insert:
2022-03-01 * "" ""
Account1 -12 CNY
Expenses:Food:Meals:Breakfast
It will goes to 02\other.bean
so I can't understand the rule of "insert-entry"
The option is documented on the help page as follows:
This option can be used to specify where entries are inserted. The argument to this option should be a regular expression matching account names. This option can be given multiple times. When adding an entry, the account of the entry (for a transaction, the account of the last posting is used) is matched against all insert-entry options and the entry will be inserted before the datewise latest of the matching options before the entry date. If the entry is a Transaction and no insert-entry option matches the account of the last posting the account of the second to last posting and so on will be tried. If no insert-entry option matches or none is given, the entry will be inserted at the end of the main file.
So it will try to match "Expenses:Food:Meals:Breakfast", which it does with the first given insert-entry option and hence it gets inserted into 02\other.bean.
As documented the matching is determined by the posting order and date-wise order of the insert-entry options. So you'll want to have your "catch-all" option to either have a date far back in time or have it be more specific as to not match all accounts that already have their own options. Also, you'll want to have Account1 be in the last posting so that Fava tries to match it first.
@yagebu Thanks. I haven't read the code about fava's way yet, but I have an idea and I want to know your opinion.
Like, we collect these options as a trie tree. And when it matches some account, then to determine which should be chose by time. If mismatched, then chose the latest "catch-all" one.