Skip to content

A local-first personal finance app

[AI] Fix missing payee on schedule previews if the schedule has a split (#8624)

youngcw6b7d8c9326fa
diff --git a/packages/desktop-client/src/components/transactions/TransactionsTable.test.tsx b/packages/desktop-client/src/components/transactions/TransactionsTable.test.tsx
index ed4b4a3f06..e62d9b5098 100644
--- a/packages/desktop-client/src/components/transactions/TransactionsTable.test.tsx
+++ b/packages/desktop-client/src/components/transactions/TransactionsTable.test.tsx
@@ -497,6 +497,80 @@ describe('Transactions', () => {
});
});
+ test('preview split transactions show a payee', async () => {
+ schedules = [
+ {
+ id: 'schedule-1',
+ name: 'Monthly rent',
+ rule: 'rule-1',
+ next_date: '2017-01-01',
+ completed: false,
+ posts_transaction: false,
+ tombstone: false,
+ _payee: 'alice-id',
+ _account: accounts[0].id,
+ _amount: -1000,
+ _amountOp: 'is',
+ _date: '2017-01-01',
+ _conditions: [],
+ _actions: [],
+ },
+ ];
+
+ const previewParentId = 'preview/schedule-1/2017-01-01';
+ const previewParent: TransactionEntity = {
+ id: previewParentId,
+ account: accounts[0].id,
+ amount: -1000,
+ date: '2017-01-01',
+ payee: null,
+ is_parent: true,
+ schedule: 'schedule-1',
+ cleared: false,
+ reconciled: false,
+ };
+ const previewChildren: TransactionEntity[] = [
+ {
+ id: 'preview/schedule-1-child-1',
+ account: accounts[0].id,
+ amount: -600,
+ date: '2017-01-01',
+ payee: 'alice-id',
+ is_child: true,
+ parent_id: previewParentId,
+ schedule: 'schedule-1',
+ cleared: false,
+ reconciled: false,
+ },
+ {
+ id: 'preview/schedule-1-child-2',
+ account: accounts[0].id,
+ amount: -400,
+ date: '2017-01-01',
+ payee: 'alice-id',
+ is_child: true,
+ parent_id: previewParentId,
+ schedule: 'schedule-1',
+ cleared: false,
+ reconciled: false,
+ },
+ ];
+
+ const { container } = renderTransactions({
+ transactions: [previewParent, ...previewChildren],
+ isAdding: false,
+ });
+
+ // The preview parent row should show the same computed payee a real,
+ // persisted split transaction would show (most common child payee),
+ // instead of being blank.
+ await waitFor(() => {
+ expect(queryField(container, 'payee', '', 0).textContent).toContain(
+ 'Alice',
+ );
+ });
+ });
+
test('transactions table shows the correct data', () => {
const { container, getTransactions } = renderTransactions();
diff --git a/packages/desktop-client/src/hooks/useDisplayPayee.tsx b/packages/desktop-client/src/hooks/useDisplayPayee.tsx
index 22cb14828f..a29fff3788 100644
--- a/packages/desktop-client/src/hooks/useDisplayPayee.tsx
+++ b/packages/desktop-client/src/hooks/useDisplayPayee.tsx
@@ -38,11 +38,23 @@ export function DisplayPayeeProvider({
.select('*'),
[transactions],
);
- const { transactions: allSubtransactions = [] } = useTransactions({
+ const { transactions: queriedSubtransactions = [] } = useTransactions({
query: subtransactionsQuery,
options: { pageSize: transactions.length * 5 },
});
+ // Preview and other not-yet-saved split transactions have subtransactions
+ // that only exist in-memory (never persisted), so the query above can't
+ // find them. Merge those in from the transactions we were already given.
+ const allSubtransactions = useMemo(() => {
+ const localChildren = transactions.filter(t => t.is_child);
+ const localIds = new Set(localChildren.map(t => t.id));
+ return [
+ ...queriedSubtransactions.filter(st => !localIds.has(st.id)),
+ ...localChildren,
+ ];
+ }, [queriedSubtransactions, transactions]);
+
const { data: accounts = [] } = useAccounts();
const { data: payeesById = {} } = usePayeesById();
diff --git a/upcoming-release-notes/fix-schedule-preview-split-payee.md b/upcoming-release-notes/fix-schedule-preview-split-payee.md
new file mode 100644
index 0000000000..4069fd0e8f
--- /dev/null
+++ b/upcoming-release-notes/fix-schedule-preview-split-payee.md
@@ -0,0 +1,6 @@
+---
+category: Bugfix
+authors: [youngcw]
+---
+
+Show the payee on upcoming/preview schedule rows that split into multiple categories instead of nothing