Skip to content

Commit

Permalink
Fix crash when editing parent transaction amount
Browse files Browse the repository at this point in the history
  • Loading branch information
jfdoming committed Jan 28, 2024
1 parent 1e1777a commit 0d89f75
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@ function PayeeIcons({
const Transaction = memo(function Transaction(props) {
const {
transaction: originalTransaction,
subtransactions,
editing,
showAccount,
showBalance,
Expand Down Expand Up @@ -827,6 +828,8 @@ const Transaction = memo(function Transaction(props) {
// Run the transaction through the formatting so that we know
// it's always showing the formatted result
setTransaction(serializeTransaction(deserialized, showZeroInDeposit));

deserialized.subtransactions = subtransactions;
onSave(deserialized);
}
}
Expand Down Expand Up @@ -1473,9 +1476,10 @@ function NewTransaction({
const error = transactions[0].error;
const isDeposit = transactions[0].amount > 0;

const emptyChildTransactions = transactions.filter(
t => t.parent_id === transactions[0].id && t.amount === 0,
const childTransactions = transactions.filter(
t => t.parent_id === transactions[0].id,
);
const emptyChildTransactions = childTransactions.filter(t => t.amount === 0);

return (
<View
Expand All @@ -1497,6 +1501,7 @@ function NewTransaction({
key={transaction.id}
editing={editingTransaction === transaction.id}
transaction={transaction}
subtransactions={childTransactions.length ? childTransactions : null}
showAccount={showAccount}
showCategory={showCategory}
showBalance={showBalance}
Expand Down
6 changes: 5 additions & 1 deletion packages/loot-core/src/server/accounts/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
addSplitTransaction,
recalculateSplit,
splitTransaction,
ungroupTransaction,
} from '../../shared/transactions';
import { fastSetMerge } from '../../shared/util';
import { RuleConditionEntity } from '../../types/models';
Expand Down Expand Up @@ -541,7 +542,10 @@ export function execActions(actions: Action[], transaction) {
return transaction;
}

const { data, newTransaction } = splitTransaction([update], transaction.id);
const { data, newTransaction } = splitTransaction(
ungroupTransaction(update),
transaction.id,
);
update = recalculateSplit(newTransaction);
data[0] = update;
let newTransactions = data;
Expand Down

0 comments on commit 0d89f75

Please sign in to comment.