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

Filter Balance fix #2777

Merged
merged 10 commits into from
May 29, 2024
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions packages/desktop-client/src/components/accounts/Account.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,26 @@ class AccountInternal extends PureComponent {
};
}

getFilteredAmount = async (filters, conditionsOpKey) => {
const filter = queries.getAccountFilter(this.props.accountId);

let query = q('transactions').filter({
[conditionsOpKey]: [...filters],
});
if (filter) {
query = query.filter(filter);
}

const filteredQuery = await runQuery(
query.select([{ amount: { $sum: '$amount' } }]),
);
const filteredAmount = filteredQuery.data.reduce(
(a, v) => (a = a + v.amount),
0,
);
return filteredAmount;
};

isNew = id => {
return this.props.newTransactions.includes(id);
};
Expand Down Expand Up @@ -1307,6 +1327,10 @@ class AccountInternal extends PureComponent {
conditions: conditions.filter(cond => !cond.customName),
});
const conditionsOpKey = this.state.conditionsOp === 'or' ? '$or' : '$and';
this.filteredAmount = await this.getFilteredAmount(
filters,
conditionsOpKey,
);
this.currentQuery = this.rootQuery.filter({
[conditionsOpKey]: [...filters, ...customFilters],
});
Expand Down Expand Up @@ -1524,6 +1548,7 @@ class AccountInternal extends PureComponent {
>
<View style={styles.page}>
<AccountHeader
filteredAmount={this.filteredAmount}
tableRef={this.table}
editingName={editingName}
isNameEditable={isNameEditable}
Expand Down
12 changes: 4 additions & 8 deletions packages/desktop-client/src/components/accounts/Balance.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,11 @@ function SelectedBalance({ selectedItems, account }) {
);
}

function FilteredBalance({ selectedItems }) {
const balance = selectedItems
.filter(item => !item._unmatched && !item.is_parent)
.reduce((sum, product) => sum + product.amount, 0);

function FilteredBalance({ filteredAmount }) {
return (
<DetailedBalance
name="Filtered balance:"
balance={balance}
balance={filteredAmount || 0}
isExactBalance={true}
/>
);
Expand Down Expand Up @@ -142,7 +138,7 @@ export function Balances({
onToggleExtraBalances,
account,
filteredItems,
transactions,
filteredAmount,
}) {
const selectedItems = useSelectedItems();

Expand Down Expand Up @@ -201,7 +197,7 @@ export function Balances({
<SelectedBalance selectedItems={selectedItems} account={account} />
)}
{filteredItems.length > 0 && (
<FilteredBalance selectedItems={transactions} />
<FilteredBalance filteredAmount={filteredAmount} />
)}
</View>
);
Expand Down
3 changes: 2 additions & 1 deletion packages/desktop-client/src/components/accounts/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { Balances } from './Balance';
import { ReconcilingMessage, ReconcileTooltip } from './Reconcile';

export function AccountHeader({
filteredAmount,
tableRef,
editingName,
isNameEditable,
Expand Down Expand Up @@ -242,7 +243,7 @@ export function AccountHeader({
onToggleExtraBalances={onToggleExtraBalances}
account={account}
filteredItems={filters}
transactions={transactions}
filteredAmount={filteredAmount}
/>

<Stack
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/2777.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [carkom]
---

On the accounts page - filter balance only adds up transactions that are showing. If your filter has more than one page it won't be added to the balance unless you scroll to the bottom and reveal all transactions. This fixes that.
Loading