1
0
Fork 0
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:
Zach Gollwitzer 2024-05-22 10:02:03 -04:00 committed by GitHub
parent 77f166a5f8
commit 41c991384a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 24 additions and 12 deletions

View file

@ -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"]),