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

🐛 (schedules) fix showing balance of approximate transactions #1473

Merged
merged 4 commits into from
Aug 6, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v2
- uses: actions/setup-node@v3
with:
node-version: '19'
- name: Check migrations
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/issues-feature-implemented.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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@v3
with:
node-version: '19'
- name: Handle feature requests
Expand Down
3 changes: 2 additions & 1 deletion packages/desktop-client/src/components/accounts/Account.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
27 changes: 22 additions & 5 deletions packages/desktop-client/src/components/accounts/Balance.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 (
<Text
style={{
Expand All @@ -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>
);
Expand Down Expand Up @@ -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);
}
}
}
Expand All @@ -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 }) {
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/1473.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [MatissJanis]
---

Fix approximate schedule values showing in balance pill when selected