diff --git a/app/controllers/family_merchants_controller.rb b/app/controllers/family_merchants_controller.rb index 1798056fd..d0875393b 100644 --- a/app/controllers/family_merchants_controller.rb +++ b/app/controllers/family_merchants_controller.rb @@ -4,7 +4,8 @@ class FamilyMerchantsController < ApplicationController def 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.alphabetically render layout: "settings" end diff --git a/app/models/simplefin_entry/processor.rb b/app/models/simplefin_entry/processor.rb index a9bb606bb..73779c3ae 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 JSONB def initialize(simplefin_transaction, simplefin_account:) @@ -100,6 +102,22 @@ class SimplefinEntry::Processor def 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)}" end end