mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-24 15:49:39 +02:00
Fix duplicate category creation on import (#791)
* Repro * Fix * Update signage
This commit is contained in:
parent
77f166a5f8
commit
41c991384a
4 changed files with 24 additions and 12 deletions
|
@ -110,9 +110,13 @@ class Import < ApplicationRecord
|
|||
|
||||
def generate_transactions
|
||||
transactions = []
|
||||
category_cache = {}
|
||||
|
||||
csv.table.each do |row|
|
||||
category = account.family.transaction_categories.find_or_initialize_by(name: row["category"]) if row["category"].present?
|
||||
category_name = row["category"]
|
||||
|
||||
category = category_cache[category_name] ||= account.family.transaction_categories.find_or_initialize_by(name: category_name) if row["category"].present?
|
||||
|
||||
txn = account.transactions.build \
|
||||
name: row["name"].presence || FALLBACK_TRANSACTION_NAME,
|
||||
date: Date.iso8601(row["date"]),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue