mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-05 05:25:24 +02: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:
parent
1746533842
commit
cd9f20747c
6 changed files with 44 additions and 10 deletions
|
@ -71,10 +71,10 @@ class Import < ApplicationRecord
|
|||
{
|
||||
account: row[account_col_label].to_s,
|
||||
date: row[date_col_label].to_s,
|
||||
qty: row[qty_col_label].to_s,
|
||||
qty: sanitize_number(row[qty_col_label]).to_s,
|
||||
ticker: row[ticker_col_label].to_s,
|
||||
price: row[price_col_label].to_s,
|
||||
amount: row[amount_col_label].to_s,
|
||||
price: sanitize_number(row[price_col_label]).to_s,
|
||||
amount: sanitize_number(row[amount_col_label]).to_s,
|
||||
currency: (row[currency_col_label] || default_currency).to_s,
|
||||
name: (row[name_col_label] || default_row_name).to_s,
|
||||
category: row[category_col_label].to_s,
|
||||
|
@ -113,6 +113,10 @@ class Import < ApplicationRecord
|
|||
cleaned? && mappings.all?(&:valid?)
|
||||
end
|
||||
|
||||
def requires_account?
|
||||
family.accounts.empty? && mappings.accounts.where(key: "").any?
|
||||
end
|
||||
|
||||
private
|
||||
def import!
|
||||
# no-op, subclasses can implement for customization of algorithm
|
||||
|
@ -134,4 +138,9 @@ class Import < ApplicationRecord
|
|||
converters: [ ->(str) { str&.strip } ]
|
||||
)
|
||||
end
|
||||
|
||||
def sanitize_number(value)
|
||||
return "" if value.nil?
|
||||
value.gsub(/[^\d.]/, "")
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue