mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-24 15:49:39 +02:00
Ignore empty categories while importing (#789)
* Ignore empty categories while importing * Review fixes
This commit is contained in:
parent
ac27a1c87f
commit
77f166a5f8
5 changed files with 23 additions and 8 deletions
|
@ -11,6 +11,8 @@ class Import < ApplicationRecord
|
|||
|
||||
scope :ordered, -> { order(created_at: :desc) }
|
||||
|
||||
FALLBACK_TRANSACTION_NAME = "Imported transaction"
|
||||
|
||||
def publish_later
|
||||
ImportJob.perform_later(self)
|
||||
end
|
||||
|
@ -110,9 +112,9 @@ class Import < ApplicationRecord
|
|||
transactions = []
|
||||
|
||||
csv.table.each do |row|
|
||||
category = account.family.transaction_categories.find_or_initialize_by(name: row["category"])
|
||||
category = account.family.transaction_categories.find_or_initialize_by(name: row["category"]) if row["category"].present?
|
||||
txn = account.transactions.build \
|
||||
name: row["name"].presence || "Imported transaction",
|
||||
name: row["name"].presence || FALLBACK_TRANSACTION_NAME,
|
||||
date: Date.iso8601(row["date"]),
|
||||
category: category,
|
||||
amount: BigDecimal(row["amount"]) * -1, # User inputs amounts with opposite signage of our internal representation
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue