Skip to content

Commit

Permalink
Add a new filter method that filters for transfer/non-transfer transa…
Browse files Browse the repository at this point in the history
…ctions

- Add new field to the views to denote whether a transaction is transfer
- Implement new filter method that uses the above field
- Fixes actualbudget#901
  • Loading branch information
sriranganathan committed Jun 24, 2023
1 parent f3f2c84 commit e732b13
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/desktop-client/src/components/accounts/Filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ let filterFields = [
'category',
'amount',
'cleared',
'is_transfer',
].map(field => [field, mapField(field)]);

function subfieldFromFilter({ field, options, value }) {
Expand Down
2 changes: 2 additions & 0 deletions packages/loot-core/src/server/aql/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const schema = {
cleared: f('boolean', { default: true }),
tombstone: f('boolean'),
schedule: f('id', { ref: 'schedules' }),
is_transfer: f('boolean'),
// subtransactions is a special field added if the table has the
// `splits: grouped` option
},
Expand Down Expand Up @@ -270,6 +271,7 @@ export const schemaConfig = {
category: `CASE WHEN _.isParent = 1 THEN NULL ELSE cm.transferId END`,
amount: `IFNULL(_.amount, 0)`,
parent_id: 'CASE WHEN _.isChild = 0 THEN NULL ELSE _.parent_id END',
is_transfer: 'CASE WHEN _.transferred_id is NULL THEN FALSE ELSE TRUE END'
});

return `
Expand Down
3 changes: 3 additions & 0 deletions packages/loot-core/src/shared/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const FIELD_TYPES = new Map(
category: 'id',
account: 'id',
cleared: 'boolean',
is_transfer: 'boolean',
}),
);

Expand All @@ -57,6 +58,8 @@ export function mapField(field, opts) {
return 'amount (inflow)';
case 'amount-outflow':
return 'amount (outflow)';
case 'is_transfer':
return 'Transfer';
default:
return field;
}
Expand Down

0 comments on commit e732b13

Please sign in to comment.