[GH-ISSUE #1409] [Bug]: Templates--Bad available_remaining tracking #26322

Closed
opened 2026-04-18 02:26:34 -05:00 by GiteaMirror · 7 comments
Owner

Originally created by @youngcw on GitHub (Jul 28, 2023).
Original GitHub issue: https://github.com/actualbudget/actual/issues/1409

Verified issue does not already exist?

  • I have searched and found no existing issue

What happened?

@shall0pass
The recent template speed up that is manually tracking the available_remaining gets messed up if there are multiple priority levels in the same category.

Since the template processing includes previous priority level values in the to_budget variable, when subtracting to_budget from available_funds the previous pass values get removed again. This will keep happening for every pass if there is a template with that priority level.

Ex
Start with $50
Cat1 :#template 10, #template-1 15
Cat2: #template remainder

The remainder should should get $25 but will end up with $15 since the first $10 gets deducted twice from available_funds in the main loop.

There may be a quick way to fix this, but I wonder if the best way would be to reorganize how the templates are processed. So that the processing of a single template doesn't care about what was there before, and the top loop adds in the previous funds instead of the previous funds being added during the processing. I would have to check all the processing to make sure that setup doesn't break anything.

What error did you receive?

No response

Where are you hosting Actual?

None

What browsers are you seeing the problem on?

No response

Operating System

None

Originally created by @youngcw on GitHub (Jul 28, 2023). Original GitHub issue: https://github.com/actualbudget/actual/issues/1409 ### Verified issue does not already exist? - [X] I have searched and found no existing issue ### What happened? @shall0pass The recent template speed up that is manually tracking the available_remaining gets messed up if there are multiple priority levels in the same category. Since the template processing includes previous priority level values in the to_budget variable, when subtracting to_budget from available_funds the previous pass values get removed again. This will keep happening for every pass if there is a template with that priority level. Ex Start with $50 Cat1 :`#template 10`, `#template-1 15` Cat2: `#template remainder` The remainder should should get $25 but will end up with $15 since the first $10 gets deducted twice from available_funds in the main loop. There may be a quick way to fix this, but I wonder if the best way would be to reorganize how the templates are processed. So that the processing of a single template doesn't care about what was there before, and the top loop adds in the previous funds instead of the previous funds being added during the processing. I would have to check all the processing to make sure that setup doesn't break anything. ### What error did you receive? _No response_ ### Where are you hosting Actual? None ### What browsers are you seeing the problem on? _No response_ ### Operating System None
GiteaMirror added the goal templatesbug labels 2026-04-18 02:26:34 -05:00
Author
Owner

@shall0pass commented on GitHub (Jul 28, 2023):

You're right. I'm seeing it. The easiest way I can think of at the moment to is to pass the 'increment' value back to the calling function and subtract it instead of the whole amount.

<!-- gh-comment-id:1656250362 --> @shall0pass commented on GitHub (Jul 28, 2023): You're right. I'm seeing it. The easiest way I can think of at the moment to is to pass the 'increment' value back to the calling function and subtract it instead of the whole amount.
Author
Owner

@youngcw commented on GitHub (Jul 28, 2023):

If the previous budgeted amount is only used for checks then maybe the addition of previous amounts could happen outside the process loop and somewhere up higher like in the setGoalBudget function. That wouldn't be as much duplication of work, but more time to implement.

<!-- gh-comment-id:1656263357 --> @youngcw commented on GitHub (Jul 28, 2023): If the previous budgeted amount is only used for checks then maybe the addition of previous amounts could happen outside the process loop and somewhere up higher like in the setGoalBudget function. That wouldn't be as much duplication of work, but more time to implement.
Author
Owner

@youngcw commented on GitHub (Jul 28, 2023):

I guess splitting up the to_Budget into an increment and prev values would work ok and be easy to work with afterwords.

<!-- gh-comment-id:1656266279 --> @youngcw commented on GitHub (Jul 28, 2023): I guess splitting up the to_Budget into an increment and prev values would work ok and be easy to work with afterwords.
Author
Owner

@shall0pass commented on GitHub (Jul 28, 2023):

Check out this branch. I only tested it for this scenario. It probably needs a little more stress testing. It passes the increment back. I don't quite follow moving it out of the loop, so If you think it's a better approach you could try it.

https://github.com/shall0pass/actual/tree/available_remaining

<!-- gh-comment-id:1656282803 --> @shall0pass commented on GitHub (Jul 28, 2023): Check out this branch. I only tested it for this scenario. It probably needs a little more stress testing. It passes the increment back. I don't quite follow moving it out of the loop, so If you think it's a better approach you could try it. https://github.com/shall0pass/actual/tree/available_remaining
Author
Owner

@youngcw commented on GitHub (Jul 28, 2023):

I think that could work. We would need to make sure that each of the template types use increment in their calculations. I can see that remainder currently doesn't and would need changed.

I also whipped up one 😄. This excludes previous amounts and adds them back in when saving. A quick search showed that only the remainder goal really used the existing values anyways. It passes all my tests, but I don't think there is a spend goal in here.
https://github.com/youngcw/actual/tree/goals_fixRemaining

<!-- gh-comment-id:1656295104 --> @youngcw commented on GitHub (Jul 28, 2023): I think that could work. We would need to make sure that each of the template types use increment in their calculations. I can see that remainder currently doesn't and would need changed. I also whipped up one :smile:. This excludes previous amounts and adds them back in when saving. A quick search showed that only the remainder goal really used the existing values anyways. It passes all my tests, but I don't think there is a spend goal in here. https://github.com/youngcw/actual/tree/goals_fixRemaining
Author
Owner

@shall0pass commented on GitHub (Jul 28, 2023):

That looks like it works too :) I'm not really sure which is considered the best approach, but yours touches fewer lines of code so I'm leaning that way 😅. Will you open a PR?

<!-- gh-comment-id:1656322985 --> @shall0pass commented on GitHub (Jul 28, 2023): That looks like it works too :) I'm not really sure which is considered the best approach, but yours touches fewer lines of code so I'm leaning that way 😅. Will you open a PR?
Author
Owner

@youngcw commented on GitHub (Jul 28, 2023):

Will do

<!-- gh-comment-id:1656323908 --> @youngcw commented on GitHub (Jul 28, 2023): Will do
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/actual#26322