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

Support splits in create-rule option on account page #2569

Merged
merged 2 commits into from
Apr 11, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 41 additions & 9 deletions packages/desktop-client/src/components/accounts/Account.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1056,18 +1056,24 @@ class AccountInternal extends PureComponent {
.select('*')
.options({ splits: 'grouped' }),
);

const transactions = ungroupTransactions(data);
const payeeCondition = transactions[0].imported_payee
const ruleTransaction = transactions[0];
const childTransactions = transactions.filter(
t => t.parent_id === ruleTransaction.id,
);

const payeeCondition = ruleTransaction.imported_payee
? {
field: 'imported_payee',
op: 'is',
value: transactions[0].imported_payee,
value: ruleTransaction.imported_payee,
type: 'string',
}
: {
field: 'payee',
op: 'is',
value: transactions[0].payee,
value: ruleTransaction.payee,
type: 'id',
};

Expand All @@ -1076,12 +1082,38 @@ class AccountInternal extends PureComponent {
conditionsOp: 'and',
conditions: [payeeCondition],
actions: [
{
op: 'set',
field: 'category',
value: transactions[0].category,
type: 'id',
},
...(childTransactions.length === 0
? [
{
op: 'set',
field: 'category',
value: ruleTransaction.category,
type: 'id',
options: {
splitIndex: 0,
},
},
]
: []),
...childTransactions.flatMap((sub, index) => [
{
op: 'set-split-amount',
value: sub.amount,
options: {
splitIndex: index + 1,
method: 'fixed-amount',
},
},
{
op: 'set',
field: 'category',
value: sub.category,
type: 'id',
options: {
splitIndex: index + 1,
},
},
]),
],
};

Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/2569.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [jfdoming]
---

Support creating rules from split transactions on the accounts page