The personal finance app for everyone (by everyone)
Ruby
Fix "invisible" merchants (#262)
soky srm369ae8a6da36
diff --git a/app/controllers/family_merchants_controller.rb b/app/controllers/family_merchants_controller.rbindex 1798056fda..d0875393b3 100644--- a/app/controllers/family_merchants_controller.rb+++ b/app/controllers/family_merchants_controller.rb@@ -4,7 +4,8 @@ class FamilyMerchantsController < ApplicationControllerdef index@breadcrumbs = [ [ "Home", root_path ], [ "Merchants", nil ] ]- @family_merchants = Current.family.merchants.alphabetically+ # Show all merchants assigned to transactions (both FamilyMerchant and ProviderMerchant)+ @family_merchants = Current.family.assigned_merchants.alphabeticallyrender layout: "settings"enddiff --git a/app/models/simplefin_entry/processor.rb b/app/models/simplefin_entry/processor.rbindex a9bb606bb4..73779c3aee 100644--- a/app/models/simplefin_entry/processor.rb+++ b/app/models/simplefin_entry/processor.rb@@ -1,3 +1,5 @@+require "digest/md5"+class SimplefinEntry::Processor# simplefin_transaction is the raw hash fetched from SimpleFin API and converted to JSONBdef initialize(simplefin_transaction, simplefin_account:)@@ -100,6 +102,22 @@ class SimplefinEntry::Processordef merchant- @merchant ||= SimplefinAccount::Transactions::MerchantDetector.new(data).detect_merchant+ # Use SimpleFin's clean payee data for merchant detection+ payee = data[:payee]&.strip+ return nil unless payee.present?++ @merchant ||= import_adapter.find_or_create_merchant(+ provider_merchant_id: generate_merchant_id(payee),+ name: payee,+ source: "simplefin"+ )+ rescue ActiveRecord::RecordInvalid => e+ Rails.logger.error "SimplefinEntry::Processor - Failed to create merchant '#{payee}': #{e.message}"+ nil+ end++ def generate_merchant_id(merchant_name)+ # Generate a consistent ID for merchants without explicit IDs+ "simplefin_#{Digest::MD5.hexdigest(merchant_name.downcase)}"endend