-
Notifications
You must be signed in to change notification settings - Fork 4k
fix: subcategories are not properly handled for budget allocations #1844
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
fix: subcategories are not properly handled for budget allocations #1844
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this solution! I think we should rearrange a bit of the code though to fit the budget domain a bit closer. I've left some ideas on how we could do that.
Finally, I think in order for these client-side validations to properly work, we'll need to update the Turbo stream responses for the update action so that subcategory forms and their directly siblings are replaced each time a subcategory budget is updated. This will ensure that the max:
validation value is directly updated to reflect the new "max" based on the other subcategory sibling budget amounts.
I tried getting the forms to re-update on the new changes, but couldn't quite get it. |
@pauleke65 yeah the streams take a bit of getting used to! I think it can all be achieved here in this file: We'll likely need to add something along the lines of (untested code below): <% if @budget_category.subcategory? %>
<% @budget_category.siblings.each do |sibling| %>
<%= turbo_stream.update dom_id(sibling, :form), partial: "budget_categories/budget_category_form", locals: { budget_category: sibling } %>
<% end %>
<% end %> And then over in <div id=<%= dom_id(budget_category, :form) %> class="w-full flex gap-3"> And finally, add that def siblings
budget.budget_categories.select { |bc| bc.category.parent_id == category.parent_id && bc.id != id }
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Just waiting for tests to pass and will get it merged.
resolved lint issues |
…aybe-finance#1844) * fix: `allocated_spending` logic * fix: subcategories exceeding parent limit * refactor: budget allocations and max allocation logic * feat: add stream for budget category form validation * feat: update uncategorized value via stream, refactor confirm button with stream * fix: ensure live updates for parent & sibling budgets in Turbo Stream * fix: lint issues
This PR ensures that subcategory budget allocations cannot exceed the total budget allocated to their parent category.
Changes:
Issue Fixed:
Fixes #1665
Testing:
Demo:
Screen.Recording.2025-02-10.at.11.25.58.AM.mov