Update version

This commit is contained in:
2026-01-16 11:28:26 +01:00
parent 7988257399
commit c6be398e5a
28 changed files with 1061 additions and 193 deletions
+20 -6
View File
@@ -73,7 +73,11 @@ class ImportService {
)
return applyImport(parsed, context: CoreDataStack.shared.viewContext)
case .json:
let parsed = parseJSON(content, allowMultipleAccounts: allowMultipleAccounts)
let parsed = parseJSON(
content,
allowMultipleAccounts: allowMultipleAccounts,
defaultAccountName: defaultAccountName
)
return applyImport(parsed, context: CoreDataStack.shared.viewContext)
}
}
@@ -96,7 +100,11 @@ class ImportService {
defaultAccountName: defaultAccountName
)
case .json:
parsed = self.parseJSON(content, allowMultipleAccounts: allowMultipleAccounts)
parsed = self.parseJSON(
content,
allowMultipleAccounts: allowMultipleAccounts,
defaultAccountName: defaultAccountName
)
}
let totalSnapshots = parsed.reduce(0) { total, account in
@@ -189,7 +197,7 @@ Personal,Real Estate,Rental Property,2024-01-01,82000,80000,Estimated value
let normalizedAccount = (providedAccount ?? "")
.trimmingCharacters(in: .whitespacesAndNewlines)
let rawAccountName = normalizedAccount.isEmpty ? fallbackAccount : normalizedAccount
let accountName = allowMultipleAccounts ? rawAccountName : "Personal"
let accountName = allowMultipleAccounts ? rawAccountName : fallbackAccount
guard let categoryName = indexOfCategory.flatMap({ row.safeValue(at: $0) }), !categoryName.isEmpty,
let sourceName = indexOfSource.flatMap({ row.safeValue(at: $0) }), !sourceName.isEmpty,
@@ -237,7 +245,11 @@ Personal,Real Estate,Rental Property,2024-01-01,82000,80000,Estimated value
}
}
private func parseJSON(_ content: String, allowMultipleAccounts: Bool) -> [ImportedAccount] {
private func parseJSON(
_ content: String,
allowMultipleAccounts: Bool,
defaultAccountName: String?
) -> [ImportedAccount] {
guard let data = content.data(using: .utf8),
let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any] else {
return []
@@ -246,7 +258,8 @@ Personal,Real Estate,Rental Property,2024-01-01,82000,80000,Estimated value
if let accountsArray = json["accounts"] as? [[String: Any]] {
return accountsArray.compactMap { accountDict in
let rawName = accountDict["name"] as? String ?? "Personal"
let name = allowMultipleAccounts ? rawName : "Personal"
let fallbackName = defaultAccountName ?? "Personal"
let name = allowMultipleAccounts ? rawName : fallbackName
let currency = accountDict["currency"] as? String
let inputMode = InputMode(rawValue: accountDict["inputMode"] as? String ?? "") ?? .simple
@@ -341,9 +354,10 @@ Personal,Real Estate,Rental Property,2024-01-01,82000,80000,Estimated value
)
}
let fallbackName = allowMultipleAccounts ? "Personal" : (defaultAccountName ?? "Personal")
return [
ImportedAccount(
name: "Personal",
name: fallbackName,
currency: json["currency"] as? String,
inputMode: .simple,
notificationFrequency: .monthly,