Skip to content

A local-first personal finance app

Identify and fix broken transfers (#4216)

youngcw977657a0beb4
diff --git a/packages/desktop-client/src/components/settings/FixSplits.tsx b/packages/desktop-client/src/components/settings/RepairTransactions.tsx
similarity index 80%
rename from packages/desktop-client/src/components/settings/FixSplits.tsx
rename to packages/desktop-client/src/components/settings/RepairTransactions.tsx
index fa87cecfee..b70f9f89f2 100644
--- a/packages/desktop-client/src/components/settings/FixSplits.tsx
+++ b/packages/desktop-client/src/components/settings/RepairTransactions.tsx
@@ -18,14 +18,20 @@ function useRenderResults() {
const { t } = useTranslation();
function renderResults(results: Results) {
- const { numBlankPayees, numCleared, numDeleted, mismatchedSplits } =
- results;
+ const {
+ numBlankPayees,
+ numCleared,
+ numDeleted,
+ numTransfersFixed,
+ mismatchedSplits,
+ } = results;
const result: string[] = [];
if (
numBlankPayees === 0 &&
numCleared === 0 &&
numDeleted === 0 &&
+ numTransfersFixed === 0 &&
mismatchedSplits.length === 0
) {
result.push(t('No split transactions found needing repair.'));
@@ -51,6 +57,13 @@ function useRenderResults() {
}),
);
}
+ if (numTransfersFixed > 0) {
+ result.push(
+ t('Fixed {{count}} transfers.', {
+ count: numTransfersFixed,
+ }),
+ );
+ }
if (mismatchedSplits.length > 0) {
const mismatchedSplitInfo = mismatchedSplits
.map(t => `- ${t.date}`)
@@ -83,7 +96,7 @@ function useRenderResults() {
return { renderResults };
}
-export function FixSplits() {
+export function RepairTransactions() {
const [loading, setLoading] = useState(false);
const [results, setResults] = useState<Results | null>(null);
@@ -108,7 +121,7 @@ export function FixSplits() {
}}
>
<ButtonWithLoading isLoading={loading} onPress={onFix}>
- <Trans>Repair split transactions</Trans>
+ <Trans>Repair transactions</Trans>
</ButtonWithLoading>
{results && renderResults(results)}
</View>
@@ -116,11 +129,11 @@ export function FixSplits() {
>
<Trans>
<Text>
- <strong>Repair split transactions</strong> if you are experiencing
- bugs relating to split transactions and the “Reset budget cache”
- button above does not help, this tool may fix them. Some examples of
- bugs include seeing blank payees on splits or incorrect account
- balances. This tool does three things:
+ <strong>Repair transactions</strong> if you are experiencing bugs
+ relating to split transactions or transfers and the “Reset budget
+ cache” button above does not help, this tool may fix them. Some
+ examples of bugs include seeing blank payees on splits or incorrect
+ account balances. This tool does four things:
</Text>
<ul style={{ margin: 0, paddingLeft: '1.5em' }}>
<li style={{ marginBottom: '0.5em' }}>
@@ -140,6 +153,10 @@ export function FixSplits() {
amount. If not, these will be flagged below to allow you to easily
locate and fix the amounts.
</li>
+ <li>
+ Check if you have any budget transfers that erroneous contain a
+ category, and remove the category.
+ </li>
</ul>
</Trans>
</Setting>
diff --git a/packages/desktop-client/src/components/settings/index.tsx b/packages/desktop-client/src/components/settings/index.tsx
index 80c6cb137e..038e4b80e4 100644
--- a/packages/desktop-client/src/components/settings/index.tsx
+++ b/packages/desktop-client/src/components/settings/index.tsx
@@ -30,9 +30,9 @@ import { BudgetTypeSettings } from './BudgetTypeSettings';
import { EncryptionSettings } from './Encryption';
import { ExperimentalFeatures } from './Experimental';
import { ExportBudget } from './Export';
-import { FixSplits } from './FixSplits';
import { FormatSettings } from './Format';
import { LanguageSettings } from './LanguageSettings';
+import { RepairTransactions } from './RepairTransactions';
import { ResetCache, ResetSync } from './Reset';
import { ThemeSettings } from './Themes';
import { AdvancedToggle, Setting } from './UI';
@@ -209,7 +209,7 @@ export function Settings() {
<AdvancedAbout />
<ResetCache />
<ResetSync />
- <FixSplits />
+ <RepairTransactions />
<ExperimentalFeatures />
</AdvancedToggle>
</View>
diff --git a/packages/desktop-client/src/components/transactions/TransactionsTable.jsx b/packages/desktop-client/src/components/transactions/TransactionsTable.jsx
index 0e166d10e9..0bae394694 100644
--- a/packages/desktop-client/src/components/transactions/TransactionsTable.jsx
+++ b/packages/desktop-client/src/components/transactions/TransactionsTable.jsx
@@ -1445,7 +1445,9 @@ const Transaction = memo(function Transaction({
: isOffBudget
? 'Off budget'
: isBudgetTransfer
- ? 'Transfer'
+ ? categoryId != null
+ ? 'Needs Repair'
+ : 'Transfer'
: ''
}
valueStyle={valueStyle}
diff --git a/packages/loot-core/src/server/tools/app.ts b/packages/loot-core/src/server/tools/app.ts
index 95cb254f9f..bc6b0321c3 100644
--- a/packages/loot-core/src/server/tools/app.ts
+++ b/packages/loot-core/src/server/tools/app.ts
@@ -73,10 +73,30 @@ app.method('tools/fix-split-transactions', async () => {
return subValue !== t.amount;
});
+ // 5. Fix transfers that should not have categories
+ const brokenTransfers = await db.all(`
+ SELECT t1.id
+ FROM v_transactions_internal t1
+ JOIN accounts a1 ON t1.account = a1.id
+ JOIN v_transactions_internal t2 ON t1.transfer_id = t2.id
+ JOIN accounts a2 ON t2.account = a2.id
+ WHERE a1.offbudget = a2.offbudget
+ AND t1.category IS NOT NULL
+ `);
+
+ await runMutator(async () => {
+ const updated = brokenTransfers.map(row => ({
+ id: row.id,
+ category: null,
+ }));
+ await batchUpdateTransactions({ updated });
+ });
+
return {
numBlankPayees: blankPayeeRows.length,
numCleared: clearedRows.length,
numDeleted: deletedRows.length,
+ numTransfersFixed: brokenTransfers.length,
mismatchedSplits,
};
});
diff --git a/packages/loot-core/src/server/tools/types/handlers.d.ts b/packages/loot-core/src/server/tools/types/handlers.d.ts
index 29420353f3..ecc0529aa7 100644
--- a/packages/loot-core/src/server/tools/types/handlers.d.ts
+++ b/packages/loot-core/src/server/tools/types/handlers.d.ts
@@ -5,6 +5,7 @@ export interface ToolsHandlers {
numBlankPayees: number;
numCleared: number;
numDeleted: number;
+ numTransfersFixed: number;
mismatchedSplits: TransactionEntity[];
}>;
}
diff --git a/upcoming-release-notes/4216.md b/upcoming-release-notes/4216.md
new file mode 100644
index 0000000000..7c513a083d
--- /dev/null
+++ b/upcoming-release-notes/4216.md
@@ -0,0 +1,6 @@
+---
+category: Enhancements
+authors: [youngcw, UnderKoen]
+---
+
+Extend "fix splits" to also fix transfers that have categories and should not.