Add "Transaction account" as rule condition filter (#1186)

* feat: Add transaction account as rule condition filter

* Update app/models/rule/condition_filter/transaction_account.rb

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Signed-off-by: Alessio Cappa <104093777+alessiocappa@users.noreply.github.com>

---------

Signed-off-by: Alessio Cappa <104093777+alessiocappa@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
Alessio Cappa
2026-03-13 07:59:45 +01:00
committed by GitHub
parent 9888b3071c
commit 80026aeee4
3 changed files with 70 additions and 1 deletions

View File

@@ -294,4 +294,58 @@ class RuleTest < ActiveSupport::TestCase
test "total_affected_resource_count returns zero for empty rules" do
assert_equal 0, Rule.total_affected_resource_count([])
end
test "rule matching on transaction account" do
# Create a second account
other_account = @family.accounts.create!(
name: "Other account",
balance: 500,
currency: "USD",
accountable: Depository.new
)
# Transaction on the target account
transaction_entry1 = create_transaction(
date: Date.current,
account: @account,
amount: 50
)
# Transaction on another account
transaction_entry2 = create_transaction(
date: Date.current,
account: other_account,
amount: 75
)
rule = Rule.create!(
family: @family,
resource_type: "transaction",
effective_date: 1.day.ago.to_date,
conditions: [
Rule::Condition.new(
condition_type: "transaction_account",
operator: "=",
value: @account.id
)
],
actions: [
Rule::Action.new(
action_type: "set_transaction_category",
value: @groceries_category.id
)
]
)
rule.apply
transaction_entry1.reload
transaction_entry2.reload
assert_equal @groceries_category, transaction_entry1.transaction.category,
"Transaction on selected account should be categorized"
assert_nil transaction_entry2.transaction.category,
"Transaction on other account should not be categorized"
end
end