mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 20:14:08 +00:00
Allow inline account creation when importing CSV (#1291)
* Allow inline account creation when importing CSV * Sanitize numeric inputs for CSV * CSV import date validation * Lint fix
This commit is contained in:
@@ -4,7 +4,7 @@ class Import::Row < ApplicationRecord
|
||||
validates :amount, numericality: true, allow_blank: true
|
||||
validates :currency, presence: true
|
||||
|
||||
validate :date_matches_user_format
|
||||
validate :date_valid
|
||||
validate :required_columns
|
||||
validate :currency_is_valid
|
||||
|
||||
@@ -54,13 +54,21 @@ class Import::Row < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def date_matches_user_format
|
||||
def date_valid
|
||||
return if date.blank?
|
||||
|
||||
parsed_date = Date.strptime(date, import.date_format) rescue nil
|
||||
|
||||
if parsed_date.nil?
|
||||
errors.add(:date, "must exactly match the format: #{import.date_format}")
|
||||
return
|
||||
end
|
||||
|
||||
min_date = Account::Entry.min_supported_date
|
||||
max_date = Date.current
|
||||
|
||||
if parsed_date < min_date || parsed_date > max_date
|
||||
errors.add(:date, "must be between #{min_date} and #{max_date}")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user