- while (true) {
- ParsedLedgerAccount parsedAccount = parser.nextAccount();
- if (parsedAccount == null) break;
-
- LedgerAccount acc = new LedgerAccount(parsedAccount.getAname());
- profile.storeAccount(acc);
- for (ParsedBalance b : parsedAccount.getAebalance()) {
- profile.storeAccountValue(acc.getName(), b.getAcommodity(),
- b.getAquantity().asFloat());
- }
+ LedgerAccount prevAccount = null;
+
+ while (true) {
+ throwIfCancelled();
+ ParsedLedgerAccount parsedAccount = parser.nextAccount();
+ if (parsedAccount == null) break;
+
+ LedgerAccount acc = profile.tryLoadAccount(db, parsedAccount.getAname());
+ if (acc == null) acc = new LedgerAccount(parsedAccount.getAname());
+ else acc.removeAmounts();
+
+ profile.storeAccount(db, acc);
+ for (ParsedBalance b : parsedAccount.getAebalance()) {
+ profile.storeAccountValue(db, acc.getName(), b.getAcommodity(),
+ b.getAquantity().asFloat());