Skip to content

A local-first personal finance app

Add ability to provide defaults for and skip updating cleared status in API (#4129)

Nikaa529a2cf1dc
diff --git a/packages/api/methods.ts b/packages/api/methods.ts
index 5ed53e9c7e..426afc2d50 100644
--- a/packages/api/methods.ts
+++ b/packages/api/methods.ts
@@ -85,10 +85,21 @@ export function addTransactions(
});
}
-export function importTransactions(accountId, transactions) {
+export interface ImportTransactionsOpts {
+ defaultCleared?: boolean;
+}
+
+export function importTransactions(
+ accountId,
+ transactions,
+ opts: ImportTransactionsOpts = {
+ defaultCleared: true,
+ },
+) {
return send('api/transactions-import', {
accountId,
transactions,
+ opts,
});
}
diff --git a/packages/loot-core/src/server/accounts/sync.ts b/packages/loot-core/src/server/accounts/sync.ts
index 62954778ca..5add734d79 100644
--- a/packages/loot-core/src/server/accounts/sync.ts
+++ b/packages/loot-core/src/server/accounts/sync.ts
@@ -393,6 +393,7 @@ export async function reconcileTransactions(
isBankSyncAccount = false,
strictIdChecking = true,
isPreview = false,
+ defaultCleared = true,
) {
console.log('Performing transaction reconciliation');
@@ -436,7 +437,7 @@ export async function reconcileTransactions(
category: existing.category || trans.category || null,
imported_payee: trans.imported_payee || null,
notes: existing.notes || trans.notes || null,
- cleared: trans.cleared != null ? trans.cleared : true,
+ cleared: trans.cleared ?? existing.cleared,
};
if (hasFieldsChanged(existing, updates, Object.keys(updates))) {
@@ -468,7 +469,7 @@ export async function reconcileTransactions(
...newTrans,
id: uuidv4(),
category: trans.category || null,
- cleared: trans.cleared != null ? trans.cleared : true,
+ cleared: trans.cleared ?? defaultCleared,
};
if (subtransactions && subtransactions.length > 0) {
diff --git a/packages/loot-core/src/server/main.ts b/packages/loot-core/src/server/main.ts
index 4deee12800..c4ac7e7ef0 100644
--- a/packages/loot-core/src/server/main.ts
+++ b/packages/loot-core/src/server/main.ts
@@ -1242,6 +1242,7 @@ handlers['transactions-import'] = mutator(function ({
accountId,
transactions,
isPreview,
+ opts,
}) {
return withUndo(async () => {
if (typeof accountId !== 'string') {
@@ -1255,6 +1256,7 @@ handlers['transactions-import'] = mutator(function ({
false,
true,
isPreview,
+ opts?.defaultCleared,
);
} catch (err) {
if (err instanceof TransactionError) {
diff --git a/packages/loot-core/src/types/api-handlers.d.ts b/packages/loot-core/src/types/api-handlers.d.ts
index eb294292d5..37ca533668 100644
--- a/packages/loot-core/src/types/api-handlers.d.ts
+++ b/packages/loot-core/src/types/api-handlers.d.ts
@@ -1,3 +1,5 @@
+import { ImportTransactionsOpts } from '@actual-app/api';
+
import { type batchUpdateTransactions } from '../server/accounts/transactions';
import type {
APIAccountEntity,
@@ -80,6 +82,7 @@ export interface ApiHandlers {
accountId;
transactions;
isPreview?;
+ opts?: ImportTransactionsOpts;
}) => Promise<{
errors?: { message: string }[];
added;
diff --git a/packages/loot-core/src/types/server-handlers.d.ts b/packages/loot-core/src/types/server-handlers.d.ts
index 030ffdb2c5..3007a8735a 100644
--- a/packages/loot-core/src/types/server-handlers.d.ts
+++ b/packages/loot-core/src/types/server-handlers.d.ts
@@ -1,3 +1,5 @@
+import { ImportTransactionsOpts } from '@actual-app/api';
+
import { ParseFileResult } from '../server/accounts/parse-file';
import { batchUpdateTransactions } from '../server/accounts/transactions';
import { Backup } from '../server/backups';
@@ -239,6 +241,7 @@ export interface ServerHandlers {
accountId;
transactions;
isPreview;
+ opts?: ImportTransactionsOpts;
}) => Promise<{
errors?: { message: string }[];
added;
diff --git a/upcoming-release-notes/4129.md b/upcoming-release-notes/4129.md
new file mode 100644
index 0000000000..4a903f6076
--- /dev/null
+++ b/upcoming-release-notes/4129.md
@@ -0,0 +1,6 @@
+---
+category: Enhancements
+authors: [NikxDa]
+---
+
+Add ability to provide default cleared status in the API and skip updating the cleared status on subsequent imports.