1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-02 20:15:22 +02:00

Add assign merchant rule for transactions (#2174)

This commit is contained in:
Alex Hatzenbuhler 2025-05-02 06:30:31 -05:00 committed by GitHub
parent 0946a1497a
commit cf72f1a387
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 53 additions and 1 deletions

View file

@ -0,0 +1,30 @@
class Rule::ActionExecutor::SetTransactionMerchant < Rule::ActionExecutor
def type
"select"
end
def options
family.merchants.pluck(:name, :id)
end
def execute(transaction_scope, value: nil, ignore_attribute_locks: false)
merchant = family.merchants.find_by_id(value)
return unless merchant
scope = transaction_scope
unless ignore_attribute_locks
scope = scope.enrichable(:merchant_id)
end
scope.each do |txn|
Rule.transaction do
txn.log_enrichment!(
attribute_name: "merchant_id",
attribute_value: merchant.id,
source: "rule"
)
txn.update!(merchant: merchant)
end
end
end
end