diff --git a/app/controllers/import/cleans_controller.rb b/app/controllers/import/cleans_controller.rb index a8bda133c..2c502f0a1 100644 --- a/app/controllers/import/cleans_controller.rb +++ b/app/controllers/import/cleans_controller.rb @@ -4,7 +4,10 @@ class Import::CleansController < ApplicationController before_action :set_import def show - redirect_to import_configuration_path(@import), alert: "Please configure your import before proceeding." unless @import.configured? + unless @import.configured? + redirect_path = @import.is_a?(PdfImport) ? import_path(@import) : import_configuration_path(@import) + return redirect_to redirect_path, alert: "Please configure your import before proceeding." + end rows = @import.rows.ordered diff --git a/app/jobs/process_pdf_job.rb b/app/jobs/process_pdf_job.rb index e5d0e2480..1ed48cf49 100644 --- a/app/jobs/process_pdf_job.rb +++ b/app/jobs/process_pdf_job.rb @@ -5,7 +5,7 @@ class ProcessPdfJob < ApplicationJob return unless pdf_import.is_a?(PdfImport) return unless pdf_import.pdf_uploaded? return if pdf_import.status == "complete" - return if pdf_import.ai_processed? && (!pdf_import.bank_statement? || pdf_import.rows_count > 0) + return if pdf_import.ai_processed? && (!pdf_import.statement_with_transactions? || pdf_import.rows_count > 0) pdf_import.update!(status: :importing) @@ -14,9 +14,9 @@ class ProcessPdfJob < ApplicationJob document_type = resolve_document_type(pdf_import, process_result) upload_to_vector_store(pdf_import, document_type: document_type) - # For bank statements, extract transactions and generate import rows - if bank_statement_document?(document_type) - Rails.logger.info("ProcessPdfJob: Extracting transactions for bank statement import #{pdf_import.id}") + # For statements with transactions (bank/credit card), extract and generate import rows + if statement_with_transactions?(document_type) + Rails.logger.info("ProcessPdfJob: Extracting transactions for #{document_type} import #{pdf_import.id}") pdf_import.extract_transactions Rails.logger.info("ProcessPdfJob: Extracted #{pdf_import.extracted_transactions.size} transactions") @@ -32,9 +32,9 @@ class ProcessPdfJob < ApplicationJob pdf_import.send_next_steps_email(user) end - # Bank statements with rows go to pending for user review/publish - # Non-bank statements are marked complete (no further action needed) - final_status = bank_statement_document?(document_type) && pdf_import.rows_count > 0 ? :pending : :complete + # Statements with extracted rows go to pending for user review/publish + # Other document types are marked complete (no further action needed) + final_status = statement_with_transactions?(document_type) && pdf_import.rows_count > 0 ? :pending : :complete pdf_import.update!(status: final_status) rescue StandardError => e sanitized_error = sanitize_error_message(e) @@ -82,7 +82,7 @@ class ProcessPdfJob < ApplicationJob pdf_import.reload.document_type end - def bank_statement_document?(document_type) - document_type == "bank_statement" + def statement_with_transactions?(document_type) + document_type.in?(%w[bank_statement credit_card_statement]) end end diff --git a/app/models/pdf_import.rb b/app/models/pdf_import.rb index 90cb3379d..38091bf2c 100644 --- a/app/models/pdf_import.rb +++ b/app/models/pdf_import.rb @@ -68,7 +68,7 @@ class PdfImport < Import end def extract_transactions - return unless bank_statement? + return unless statement_with_transactions? provider = Provider::Registry.get_provider(:openai) raise "AI provider not configured" unless provider @@ -91,6 +91,10 @@ class PdfImport < Import document_type == "bank_statement" end + def statement_with_transactions? + document_type.in?(%w[bank_statement credit_card_statement]) + end + def has_extracted_transactions? extracted_data.present? && extracted_data["transactions"].present? end @@ -147,7 +151,7 @@ class PdfImport < Import end def publishable? - account.present? && bank_statement? && cleaned? && mappings.all?(&:valid?) + account.present? && statement_with_transactions? && cleaned? && mappings.all?(&:valid?) end def column_keys diff --git a/app/views/import/cleans/show.html.erb b/app/views/import/cleans/show.html.erb index c0bce7d7c..3fcbf8143 100644 --- a/app/views/import/cleans/show.html.erb +++ b/app/views/import/cleans/show.html.erb @@ -2,7 +2,7 @@ <%= render "imports/nav", import: @import %> <% end %> -<%= content_for :previous_path, import_configuration_path(@import) %> +<%= content_for :previous_path, @import.is_a?(PdfImport) ? import_path(@import) : import_configuration_path(@import) %>
<%= t("imports.pdf_import.ready_for_review_description", default: "We extracted %{count} transactions from your bank statement. Review and publish them to add to your account.", count: import.rows_count) %>
+<%= t("imports.pdf_import.ready_for_review_description", default: "We extracted %{count} transactions from your statement. Review and publish them to add to your account.", count: import.rows_count) %>
<%= t("imports.pdf_import.select_account_to_continue", default: "Please select an account above to continue.") %>
<% end %>