Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 6 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/api/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}

Expand Down
5 changes: 3 additions & 2 deletions packages/loot-core/src/server/accounts/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ export async function reconcileTransactions(
isBankSyncAccount = false,
strictIdChecking = true,
isPreview = false,
defaultCleared = true,
) {
console.log('Performing transaction reconciliation');

Expand Down Expand Up @@ -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))) {
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions packages/loot-core/src/server/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,7 @@ handlers['transactions-import'] = mutator(function ({
accountId,
transactions,
isPreview,
opts,
}) {
return withUndo(async () => {
if (typeof accountId !== 'string') {
Expand All @@ -1255,6 +1256,7 @@ handlers['transactions-import'] = mutator(function ({
false,
true,
isPreview,
opts?.defaultCleared,
);
} catch (err) {
if (err instanceof TransactionError) {
Expand Down
3 changes: 3 additions & 0 deletions packages/loot-core/src/types/api-handlers.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ImportTransactionsOpts } from '@actual-app/api';

import { type batchUpdateTransactions } from '../server/accounts/transactions';
import type {
APIAccountEntity,
Expand Down Expand Up @@ -80,6 +82,7 @@ export interface ApiHandlers {
accountId;
transactions;
isPreview?;
opts?: ImportTransactionsOpts;
}) => Promise<{
errors?: { message: string }[];
added;
Expand Down
3 changes: 3 additions & 0 deletions packages/loot-core/src/types/server-handlers.d.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -239,6 +241,7 @@ export interface ServerHandlers {
accountId;
transactions;
isPreview;
opts?: ImportTransactionsOpts;
}) => Promise<{
errors?: { message: string }[];
added;
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/4129.md
Original file line number Diff line number Diff line change
@@ -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.
Loading