mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-05 13:35:21 +02:00
Auto sync preference, max limit on account CSV imports (#2259)
* Auto sync preference, max limit on account CSV imports * MaxRowCountExceededError
This commit is contained in:
parent
f82f77466a
commit
e26e5c5aec
7 changed files with 35 additions and 1 deletions
|
@ -13,6 +13,7 @@ module AutoSync
|
|||
def family_needs_auto_sync?
|
||||
return false unless Current.family&.accounts&.active&.any?
|
||||
return false if (Current.family.last_sync_created_at&.to_date || 1.day.ago) >= Date.current
|
||||
return false unless Current.family.auto_sync_on_login
|
||||
|
||||
Rails.logger.info "Auto-syncing family #{Current.family.id}, last sync was #{Current.family.last_sync_created_at}"
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@ class ImportsController < ApplicationController
|
|||
@import.publish_later
|
||||
|
||||
redirect_to import_path(@import), notice: "Your import has started in the background."
|
||||
rescue Import::MaxRowCountExceededError
|
||||
redirect_back_or_to import_path(@import), alert: "Your import exceeds the maximum row count of #{@import.max_row_count}."
|
||||
end
|
||||
|
||||
def index
|
||||
|
|
|
@ -54,4 +54,8 @@ class AccountImport < Import
|
|||
|
||||
CSV.parse(template, headers: true)
|
||||
end
|
||||
|
||||
def max_row_count
|
||||
50
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
class Import < ApplicationRecord
|
||||
MaxRowCountExceededError = Class.new(StandardError)
|
||||
|
||||
TYPES = %w[TransactionImport TradeImport AccountImport MintImport].freeze
|
||||
SIGNAGE_CONVENTIONS = %w[inflows_positive inflows_negative]
|
||||
SEPARATORS = [ [ "Comma (,)", "," ], [ "Semicolon (;)", ";" ] ].freeze
|
||||
|
@ -52,6 +54,7 @@ class Import < ApplicationRecord
|
|||
end
|
||||
|
||||
def publish_later
|
||||
raise MaxRowCountExceededError if row_count_exceeded?
|
||||
raise "Import is not publishable" unless publishable?
|
||||
|
||||
update! status: :importing
|
||||
|
@ -60,6 +63,8 @@ class Import < ApplicationRecord
|
|||
end
|
||||
|
||||
def publish
|
||||
raise MaxRowCountExceededError if row_count_exceeded?
|
||||
|
||||
import!
|
||||
|
||||
family.sync_later
|
||||
|
@ -220,7 +225,15 @@ class Import < ApplicationRecord
|
|||
)
|
||||
end
|
||||
|
||||
def max_row_count
|
||||
10000
|
||||
end
|
||||
|
||||
private
|
||||
def row_count_exceeded?
|
||||
rows.count > max_row_count
|
||||
end
|
||||
|
||||
def import!
|
||||
# no-op, subclasses can implement for customization of algorithm
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue