feat(rules): apply a new rule to existing transactions on creation#310
Merged
Conversation
Creating a rule previously only persisted it; existing transactions were
left untouched until the user manually hit "Reapply all". Now the create
endpoint applies the new rule to existing transactions right away and
returns how many were affected, and the success toast reports it ("Rule
created and applied to N transactions") for transparency.
The auto-apply is non-destructive: a transaction that already has a
category keeps it (same semantics used when new transactions arrive), so
creating a rule never silently overwrites manual categorizations. Payee,
notes and ignore actions still apply on a match. Only transactions whose
fields actually change are counted.
- backend: add rule_service.apply_single_rule; POST /api/rules returns
RuleCreateResponse with applied_count
- frontend: combined toast + financial query invalidation when count > 0
- i18n: rules.createdAndApplied across all locales
- tests: cover match/apply, no-match, and non-destructive behavior
ADolkun
pushed a commit
to ADolkun/lovenest
that referenced
this pull request
Jul 21, 2026
…ecuro-finance#310) Creating a rule previously only persisted it; existing transactions were left untouched until the user manually hit "Reapply all". Now the create endpoint applies the new rule to existing transactions right away and returns how many were affected, and the success toast reports it ("Rule created and applied to N transactions") for transparency. The auto-apply is non-destructive: a transaction that already has a category keeps it (same semantics used when new transactions arrive), so creating a rule never silently overwrites manual categorizations. Payee, notes and ignore actions still apply on a match. Only transactions whose fields actually change are counted. - backend: add rule_service.apply_single_rule; POST /api/rules returns RuleCreateResponse with applied_count - frontend: combined toast + financial query invalidation when count > 0 - i18n: rules.createdAndApplied across all locales - tests: cover match/apply, no-match, and non-destructive behavior
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to the rule-form UX work on #306. Previously, creating a rule only saved it — existing transactions stayed untouched until the user manually clicked Reapply all. This was an invisible gap, especially when creating rules in bulk.
Now, creating a rule immediately applies it to existing transactions and the success toast reports the result with a single combined message:
(falling back to plain "Rule created" when nothing matched).
Behavior
The auto-apply is non-destructive by design:
For a full reset that re-runs every rule and overwrites, Reapply all is still there and unchanged.
Changes
rule_service.apply_single_rule();POST /api/rulesnow returnsRuleCreateResponse(=RuleRead+applied_count).createMutation.onSuccess, plusinvalidateFinancialQuerieswhen count > 0 so transactions/reports refresh.rules.createdAndAppliedadded to en, pt-BR, es, it, pl.Testing
test_new_rules_api,test_rule_service,test_rule_engine) — 38 tests including the 3 new ones. Frontendtsc -b+ eslint clean.