fix(imports): preserve account status from backups (#1603)

This commit is contained in:
ghost
2026-04-30 15:53:55 -06:00
committed by GitHub
parent 43a500d9fa
commit 072f92c715
2 changed files with 51 additions and 1 deletions

View File

@@ -92,7 +92,7 @@ class Family::DataImporter
institution_name: data["institution_name"],
institution_domain: data["institution_domain"],
notes: data["notes"],
status: "active"
status: importable_account_status(data["status"])
)
account.save!
@@ -108,6 +108,10 @@ class Family::DataImporter
end
end
def importable_account_status(status)
status.to_s.in?(%w[active disabled draft]) ? status.to_s : "active"
end
def import_categories(records)
# First pass: create all categories without parent relationships
parent_mappings = {}

View File

@@ -31,6 +31,52 @@ class Family::DataImporterTest < ActiveSupport::TestCase
assert_equal "Depository", account.accountable_type
end
test "imports non-destructive account status from ndjson" do
ndjson = build_ndjson([
{
type: "Account",
data: {
id: "disabled-account",
name: "Closed Checking",
balance: "0.00",
currency: "USD",
accountable_type: "Depository",
status: "disabled"
}
}
])
importer = Family::DataImporter.new(@family, ndjson)
result = importer.import!
account = result[:accounts].first
assert_equal "Closed Checking", account.name
assert_equal "disabled", account.status
end
test "does not import pending deletion account status" do
ndjson = build_ndjson([
{
type: "Account",
data: {
id: "pending-delete-account",
name: "Pending Delete Checking",
balance: "0.00",
currency: "USD",
accountable_type: "Depository",
status: "pending_deletion"
}
}
])
importer = Family::DataImporter.new(@family, ndjson)
result = importer.import!
account = result[:accounts].first
assert_equal "Pending Delete Checking", account.name
assert_equal "active", account.status
end
test "imports categories with parent relationships" do
ndjson = build_ndjson([
{