mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 12:04:08 +00:00
Add exclude transaction rule action (#437)
* Initial plan * Add ExcludeTransaction rule action executor with tests Co-authored-by: jjmata <187772+jjmata@users.noreply.github.com> * Copy clarification --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jjmata <187772+jjmata@users.noreply.github.com> Co-authored-by: Juan José Mata <juanjo.mata@gmail.com>
This commit is contained in:
26
app/models/rule/action_executor/exclude_transaction.rb
Normal file
26
app/models/rule/action_executor/exclude_transaction.rb
Normal file
@@ -0,0 +1,26 @@
|
||||
class Rule::ActionExecutor::ExcludeTransaction < Rule::ActionExecutor
|
||||
def label
|
||||
"Exclude from budgeting and reports"
|
||||
end
|
||||
|
||||
def execute(transaction_scope, value: nil, ignore_attribute_locks: false, rule_run: nil)
|
||||
scope = transaction_scope.with_entry
|
||||
|
||||
unless ignore_attribute_locks
|
||||
# Filter by entry's locked_attributes, not transaction's
|
||||
# Since excluded is on Entry, not Transaction, we need to check entries.locked_attributes
|
||||
scope = scope.where.not(
|
||||
Arel.sql("entries.locked_attributes ? 'excluded'")
|
||||
)
|
||||
end
|
||||
|
||||
count_modified_resources(scope) do |txn|
|
||||
# enrich_attribute returns true if the entry was actually modified, false otherwise
|
||||
txn.entry.enrich_attribute(
|
||||
:excluded,
|
||||
true,
|
||||
source: "rule"
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user