mirror of
https://github.com/actualbudget/actual.git
synced 2026-04-28 10:33:02 -05:00
Fix amount filter to include both incoming and outgoing amounts (#2643)
* Update filter amount to filter incoming and outgoing transactions * Add test and fix logic * Added release note * Update with linter fixes * Update new ammount filter to apply to all ops * Fix lint
This commit is contained in:
@@ -420,7 +420,23 @@ describe('Transaction rules', () => {
|
||||
account,
|
||||
payee: lowesId,
|
||||
notes: '',
|
||||
amount: 124,
|
||||
amount: 102,
|
||||
});
|
||||
await db.insertTransaction({
|
||||
id: '6',
|
||||
date: '2020-10-17',
|
||||
account,
|
||||
payee: krogerId,
|
||||
notes: 'baz',
|
||||
amount: -102,
|
||||
});
|
||||
await db.insertTransaction({
|
||||
id: '7',
|
||||
date: '2020-10-17',
|
||||
account,
|
||||
payee: krogerId,
|
||||
notes: 'zaz',
|
||||
amount: -101,
|
||||
});
|
||||
|
||||
let transactions = await getMatchingTransactions([
|
||||
@@ -438,6 +454,36 @@ describe('Transaction rules', () => {
|
||||
]);
|
||||
expect(transactions.map(t => t.id)).toEqual(['1']);
|
||||
|
||||
transactions = await getMatchingTransactions([
|
||||
{ field: 'amount', op: 'is', value: 102 },
|
||||
]);
|
||||
expect(transactions.map(t => t.id)).toEqual(['6', '5']);
|
||||
|
||||
transactions = await getMatchingTransactions([
|
||||
{ field: 'amount', op: 'isapprox', value: 102 },
|
||||
]);
|
||||
expect(transactions.map(t => t.id)).toEqual(['6', '7', '4', '5']);
|
||||
|
||||
transactions = await getMatchingTransactions([
|
||||
{ field: 'amount', op: 'gt', value: 102 },
|
||||
]);
|
||||
expect(transactions.map(t => t.id)).toEqual(['2', '3', '1']);
|
||||
|
||||
transactions = await getMatchingTransactions([
|
||||
{ field: 'amount', op: 'lt', value: 102 },
|
||||
]);
|
||||
expect(transactions.map(t => t.id)).toEqual(['7', '4']);
|
||||
|
||||
transactions = await getMatchingTransactions([
|
||||
{ field: 'amount', op: 'gte', value: 102 },
|
||||
]);
|
||||
expect(transactions.map(t => t.id)).toEqual(['6', '5', '2', '3', '1']);
|
||||
|
||||
transactions = await getMatchingTransactions([
|
||||
{ field: 'amount', op: 'lte', value: 102 },
|
||||
]);
|
||||
expect(transactions.map(t => t.id)).toEqual(['6', '7', '4', '5']);
|
||||
|
||||
transactions = await getMatchingTransactions([
|
||||
{ field: 'notes', op: 'is', value: 'FooO' },
|
||||
]);
|
||||
@@ -461,7 +507,7 @@ describe('Transaction rules', () => {
|
||||
transactions = await getMatchingTransactions([
|
||||
{ field: 'amount', op: 'gt', value: 300 },
|
||||
]);
|
||||
expect(transactions.map(t => t.id)).toEqual(['2', '1']);
|
||||
expect(transactions.map(t => t.id)).toEqual(['2', '3', '1']);
|
||||
|
||||
transactions = await getMatchingTransactions([
|
||||
{ field: 'amount', op: 'gt', value: 400 },
|
||||
@@ -490,7 +536,7 @@ describe('Transaction rules', () => {
|
||||
transactions = await getMatchingTransactions([
|
||||
{ field: 'date', op: 'gt', value: '2020-10-10' },
|
||||
]);
|
||||
expect(transactions.map(t => t.id)).toEqual(['4', '5', '2', '3']);
|
||||
expect(transactions.map(t => t.id)).toEqual(['6', '7', '4', '5', '2', '3']);
|
||||
|
||||
// todo: isapprox
|
||||
});
|
||||
|
||||
@@ -335,22 +335,25 @@ export function conditionsToAQL(conditions, { recurDateBounds = 100 } = {}) {
|
||||
|
||||
const apply = (field, op, value) => {
|
||||
if (type === 'number') {
|
||||
const outflowQuery = {
|
||||
$and: [
|
||||
{ amount: { $lt: 0 } },
|
||||
{ [field]: { $transform: '$neg', [op]: value } },
|
||||
],
|
||||
};
|
||||
const inflowQuery = {
|
||||
$and: [{ amount: { $gt: 0 } }, { [field]: { [op]: value } }],
|
||||
};
|
||||
if (options) {
|
||||
if (options.outflow) {
|
||||
return {
|
||||
$and: [
|
||||
{ amount: { $lt: 0 } },
|
||||
{ [field]: { $transform: '$neg', [op]: value } },
|
||||
],
|
||||
};
|
||||
return outflowQuery;
|
||||
} else if (options.inflow) {
|
||||
return {
|
||||
$and: [{ amount: { $gt: 0 } }, { [field]: { [op]: value } }],
|
||||
};
|
||||
return inflowQuery;
|
||||
}
|
||||
}
|
||||
|
||||
return { amount: { [op]: value } };
|
||||
return {
|
||||
$or: [outflowQuery, inflowQuery],
|
||||
};
|
||||
} else if (type === 'string') {
|
||||
return { [field]: { $transform: '$lower', [op]: value } };
|
||||
} else if (type === 'date') {
|
||||
|
||||
6
upcoming-release-notes/2643.md
Normal file
6
upcoming-release-notes/2643.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
category: Bugfix
|
||||
authors: [mirdaki]
|
||||
---
|
||||
|
||||
Fix amount filter to include both incoming and outgoing amounts.
|
||||
Reference in New Issue
Block a user