A local-first personal finance app
:bug: (schedules) fix showing balance of approximate transactions (#1473)
Matiss Janis Aboltinse78430db627d
diff --git a/.github/workflows/check.yml b/.github/workflows/check.ymlindex 4e949a465b..6e00fcb98f 100644--- a/.github/workflows/check.yml+++ b/.github/workflows/check.yml@@ -41,7 +41,7 @@ jobs:runs-on: ubuntu-lateststeps:- uses: actions/checkout@v3- - uses: actions/setup-node@v2+ - uses: actions/setup-node@v3with:node-version: '19'- name: Check migrationsdiff --git a/.github/workflows/issues-feature-implemented.yml b/.github/workflows/issues-feature-implemented.ymlindex 039ee5e500..4c8bf1ea7f 100644--- a/.github/workflows/issues-feature-implemented.yml+++ b/.github/workflows/issues-feature-implemented.yml@@ -25,7 +25,7 @@ jobs:steps:# This is not a security concern because we have approved & merged the PR- uses: actions/checkout@v3- - uses: actions/setup-node@v2+ - uses: actions/setup-node@v3with:node-version: '19'- name: Handle feature requestsdiff --git a/packages/desktop-client/src/components/accounts/Account.js b/packages/desktop-client/src/components/accounts/Account.jsindex 7332c4cfdc..638159a16b 100644--- a/packages/desktop-client/src/components/accounts/Account.js+++ b/packages/desktop-client/src/components/accounts/Account.js@@ -15,6 +15,7 @@ import * as queries from 'loot-core/src/client/queries';import q, { runQuery, pagedQuery } from 'loot-core/src/client/query-helpers';import { send, listen } from 'loot-core/src/platform/client/fetch';import { currentDay } from 'loot-core/src/shared/months';+import { getScheduledAmount } from 'loot-core/src/shared/schedules';import {deleteTransaction,updateTransaction,@@ -137,7 +138,7 @@ function AllTransactions({.map(scheduledTransaction => {let amount =(scheduledTransaction._inverse ? -1 : 1) *- scheduledTransaction.amount;+ getScheduledAmount(scheduledTransaction.amount);return {balance: (runningBalance += amount),id: scheduledTransaction.id,diff --git a/packages/desktop-client/src/components/accounts/Balance.js b/packages/desktop-client/src/components/accounts/Balance.jsindex 8a2b7dde72..700e2683d3 100644--- a/packages/desktop-client/src/components/accounts/Balance.js+++ b/packages/desktop-client/src/components/accounts/Balance.js@@ -2,6 +2,7 @@ import React from 'react';import { useCachedSchedules } from 'loot-core/src/client/data-hooks/schedules';import q from 'loot-core/src/client/query-helpers';+import { getScheduledAmount } from 'loot-core/src/shared/schedules';import { useSelectedItems } from '../../hooks/useSelected';import ArrowButtonRight1 from '../../icons/v2/ArrowButtonRight1';@@ -15,7 +16,7 @@ import format from '../spreadsheet/format';import useSheetValue from '../spreadsheet/useSheetValue';import { isPreviewId } from '../transactions/TransactionsTable';-function DetailedBalance({ name, balance }) {+function DetailedBalance({ name, balance, isExactBalance = true }) {return (<Textstyle={{@@ -28,7 +29,10 @@ function DetailedBalance({ name, balance }) {>{name}{' '}<PrivacyFilter>- <Text style={{ fontWeight: 600 }}>{format(balance, 'financial')}</Text>+ <Text style={{ fontWeight: 600 }}>+ {!isExactBalance && '~ '}+ {format(balance, 'financial')}+ </Text></PrivacyFilter></Text>);@@ -63,12 +67,19 @@ function SelectedBalance({ selectedItems, account }) {let previewIds = [...selectedItems].filter(id => isPreviewId(id)).map(id => id.slice(8));+ let isExactBalance = true;+for (let s of schedules) {if (previewIds.includes(s.id)) {+ // If a schedule is `between X and Y` then we calculate the average+ if (s._amountOp === 'isbetween') {+ isExactBalance = false;+ }+if (!account || account.id === s._account) {- scheduleBalance += s._amount;+ scheduleBalance += getScheduledAmount(s._amount);} else {- scheduleBalance -= s._amount;+ scheduleBalance -= getScheduledAmount(s._amount);}}}@@ -83,7 +94,13 @@ function SelectedBalance({ selectedItems, account }) {balance += scheduleBalance;}- return <DetailedBalance name="Selected balance:" balance={balance} />;+ return (+ <DetailedBalance+ name="Selected balance:"+ balance={balance}+ isExactBalance={isExactBalance}+ />+ );}function MoreBalances({ balanceQuery }) {diff --git a/upcoming-release-notes/1473.md b/upcoming-release-notes/1473.mdnew file mode 100644index 0000000000..ee5b1f7588--- /dev/null+++ b/upcoming-release-notes/1473.md@@ -0,0 +1,6 @@+---+category: Bugfix+authors: [MatissJanis]+---++Fix approximate schedule values showing in balance pill when selected