Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Add “Is not equal to” operator for transaction amount rules (#2922)

William Wei Ming62fd47def9c4
diff --git a/app/models/rule/condition_filter.rb b/app/models/rule/condition_filter.rb
index ad0574386c..387fdb355d 100644
--- a/app/models/rule/condition_filter.rb
+++ b/app/models/rule/condition_filter.rb
@@ -5,7 +5,7 @@ class Rule::ConditionFilter
OPERATORS_MAP = {
"text" => [ [ "Contains", "like" ], [ "Equal to", "=" ], [ "Is empty", "is_null" ] ],
- "number" => [ [ "Greater than", ">" ], [ "Greater or equal to", ">=" ], [ "Less than", "<" ], [ "Less than or equal to", "<=" ], [ "Is equal to", "=" ] ],
+ "number" => [ [ "Greater than", ">" ], [ "Greater or equal to", ">=" ], [ "Less than", "<" ], [ "Less than or equal to", "<=" ], [ "Is equal to", "=" ], [ "Is not equal to", "!=" ] ],
"select" => [ [ "Equal to", "=" ], [ "Is empty", "is_null" ] ]
}
diff --git a/test/models/rule/condition_test.rb b/test/models/rule/condition_test.rb
index 52ab403718..c42e0a2b62 100644
--- a/test/models/rule/condition_test.rb
+++ b/test/models/rule/condition_test.rb
@@ -56,6 +56,25 @@ class Rule::ConditionTest < ActiveSupport::TestCase
assert_equal 3, filtered.count
end
+ test "applies transaction_amount not equal operator using absolute values" do
+ create_transaction(date: Date.current, account: @account, amount: -100, name: "Rule test transaction negative 100")
+ scope = @account.transactions
+
+ condition = Rule::Condition.new(
+ rule: @transaction_rule,
+ condition_type: "transaction_amount",
+ operator: "!=",
+ value: "100"
+ )
+
+ scope = condition.prepare(scope)
+
+ filtered = condition.apply(scope)
+ # Absolute amounts: 100, -100, 200, 50, 10, 1000 — exclude both ±100
+ assert_equal 4, filtered.count
+ assert_not filtered.any? { |txn| txn.entry.amount.abs == 100 }
+ end
+
test "applies transaction_merchant condition" do
scope = @rule_scope