mirror of
https://github.com/we-promise/sure.git
synced 2026-04-25 06:54:07 +00:00
Fix CSV import with no currency (#462)
* FIX use the accounts we are importing currency as default, not family default * FIX add family fallback for multi account import
This commit is contained in:
@@ -244,7 +244,7 @@ class Import < ApplicationRecord
|
||||
end
|
||||
|
||||
def default_currency
|
||||
family.currency
|
||||
account&.currency || family.currency
|
||||
end
|
||||
|
||||
def parsed_csv
|
||||
|
||||
@@ -29,11 +29,14 @@ class MintImport < Import
|
||||
category = mappings.categories.mappable_for(row.category)
|
||||
tags = row.tags_list.map { |tag| mappings.tags.mappable_for(tag) }.compact
|
||||
|
||||
# Use account's currency when no currency column was mapped in CSV, with family currency as fallback
|
||||
effective_currency = currency_col_label.present? ? row.currency : (account.currency.presence || family.currency)
|
||||
|
||||
entry = account.entries.build \
|
||||
date: row.date_iso,
|
||||
amount: row.signed_amount,
|
||||
name: row.name,
|
||||
currency: row.currency,
|
||||
currency: effective_currency,
|
||||
notes: row.notes,
|
||||
entryable: Transaction.new(category: category, tags: tags),
|
||||
import: self
|
||||
|
||||
@@ -27,6 +27,9 @@ class TransactionImport < Import
|
||||
category = mappings.categories.mappable_for(row.category)
|
||||
tags = row.tags_list.map { |tag| mappings.tags.mappable_for(tag) }.compact
|
||||
|
||||
# Use account's currency when no currency column was mapped in CSV, with family currency as fallback
|
||||
effective_currency = currency_col_label.present? ? row.currency : (mapped_account.currency.presence || family.currency)
|
||||
|
||||
# Check for duplicate transactions using the adapter's deduplication logic
|
||||
# Pass claimed_entry_ids to exclude entries we've already matched in this import
|
||||
# This ensures identical rows within the CSV are all imported as separate transactions
|
||||
@@ -34,7 +37,7 @@ class TransactionImport < Import
|
||||
duplicate_entry = adapter.find_duplicate_transaction(
|
||||
date: row.date_iso,
|
||||
amount: row.signed_amount,
|
||||
currency: row.currency,
|
||||
currency: effective_currency,
|
||||
name: row.name,
|
||||
exclude_entry_ids: claimed_entry_ids
|
||||
)
|
||||
@@ -57,7 +60,7 @@ class TransactionImport < Import
|
||||
date: row.date_iso,
|
||||
amount: row.signed_amount,
|
||||
name: row.name,
|
||||
currency: row.currency,
|
||||
currency: effective_currency,
|
||||
notes: row.notes,
|
||||
import: self
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user