Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: CSV import creates duplicate when creating new categories #763

Closed
2 tasks done
jakubkottnauer opened this issue May 18, 2024 · 1 comment · Fixed by #791
Closed
2 tasks done

Bug: CSV import creates duplicate when creating new categories #763

jakubkottnauer opened this issue May 18, 2024 · 1 comment · Fixed by #791
Assignees
Labels
🐛 Bug Something isn't working
Milestone

Comments

@jakubkottnauer
Copy link
Contributor

Where did this bug occur?

  • Local development
  • Self hosted app (i.e. Docker)

Describe the bug
New categories present in the CSV being imported are created on every occurrence, instead of just once.

To Reproduce
Steps to reproduce the behavior:

  1. Import the following CSV
date,name,category,amount
2024-01-01,Starbucks drink,SOMETHING_NEW,20
2024-01-02,Amazon stuff,SOMETHING_NEW,200
  1. Observe that the SOMETHING_NEW category has been created twice
Screenshot 2024-05-18 at 22 37 08

Expected behavior
New categories are only created once

@jakubkottnauer jakubkottnauer added 🐛 Bug Something isn't working 🚀 Feature labels May 18, 2024
@zachgoll
Copy link
Collaborator

@jakubkottnauer good catch here. This is the relevant method we'll need to rework. I think the challenge here is that we'll need to create a data structure that allows us to know in what order to call .save on each model. We may even need to rework the "preview -> save" flow a bit.

maybe/app/models/import.rb

Lines 109 to 125 in 34811d8

def generate_transactions
transactions = []
csv.table.each do |row|
category = account.family.transaction_categories.find_or_initialize_by(name: row["category"])
txn = account.transactions.build \
name: row["name"] || "Imported transaction",
date: Date.iso8601(row["date"]),
category: category,
amount: BigDecimal(row["amount"]) * -1, # User inputs amounts with opposite signage of our internal representation
currency: account.currency
transactions << txn
end
transactions
end

@zachgoll zachgoll added this to the v0.2.0-alpha milestone May 20, 2024
@zachgoll zachgoll self-assigned this May 22, 2024
@zachgoll zachgoll linked a pull request May 22, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants