Skip to content
Snippets Groups Projects
Unverified Commit 1195af76 authored by Neil's avatar Neil Committed by GitHub
Browse files

Filter Balance fix (#2777)


* filterQuery

* notes

* update

* lint fix

* VRT

* fix account filter

* VRT

---------

Co-authored-by: default avataryoungcw <calebyoung94@gmail.com>
parent e4bc0caa
No related branches found
No related tags found
No related merge requests found
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
......@@ -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);
};
......@@ -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],
});
......@@ -1524,6 +1548,7 @@ class AccountInternal extends PureComponent {
>
<View style={styles.page}>
<AccountHeader
filteredAmount={this.filteredAmount}
tableRef={this.table}
editingName={editingName}
isNameEditable={isNameEditable}
......
......@@ -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}
/>
);
......@@ -142,7 +138,7 @@ export function Balances({
onToggleExtraBalances,
account,
filteredItems,
transactions,
filteredAmount,
}) {
const selectedItems = useSelectedItems();
......@@ -201,7 +197,7 @@ export function Balances({
<SelectedBalance selectedItems={selectedItems} account={account} />
)}
{filteredItems.length > 0 && (
<FilteredBalance selectedItems={transactions} />
<FilteredBalance filteredAmount={filteredAmount} />
)}
</View>
);
......
......@@ -32,6 +32,7 @@ import { Balances } from './Balance';
import { ReconcilingMessage, ReconcileTooltip } from './Reconcile';
export function AccountHeader({
filteredAmount,
tableRef,
editingName,
isNameEditable,
......@@ -242,7 +243,7 @@ export function AccountHeader({
onToggleExtraBalances={onToggleExtraBalances}
account={account}
filteredItems={filters}
transactions={transactions}
filteredAmount={filteredAmount}
/>
<Stack
......
---
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.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment