A local-first personal finance app
Fix rules not being applied in mobile transaction entry (#3073)
Joel Jeremy Marquez33049a77e770
diff --git a/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.jsx b/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.jsxindex be26185149..9a570fecc0 100644--- a/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.jsx+++ b/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.jsx@@ -561,7 +561,7 @@ const TransactionEditInner = memo(function TransactionEditInner({const onUpdate = async (serializedTransaction, name, value) => {const newTransaction = { ...serializedTransaction, [name]: value };- await props.onUpdate(newTransaction);+ await props.onUpdate(newTransaction, name);onClearActiveEdit();};@@ -1061,7 +1061,7 @@ function TransactionEditUnconnected({return null;}- const onUpdate = async serializedTransaction => {+ const onUpdate = async (serializedTransaction, updatedField) => {const transaction = deserializeTransaction(serializedTransaction,null,@@ -1070,22 +1070,46 @@ function TransactionEditUnconnected({// Run the rules to auto-fill in any data. Right now we only do// this on new transactions because that's how desktop works.- if (isTemporary(transaction)) {- const afterRules = await send('rules-run', { transaction });- const diff = getChangedValues(transaction, afterRules);+ const newTransaction = { ...transaction };+ if (isTemporary(newTransaction)) {+ const afterRules = await send('rules-run', {+ transaction: newTransaction,+ });+ const diff = getChangedValues(newTransaction, afterRules);if (diff) {Object.keys(diff).forEach(field => {- if (transaction[field] == null) {- transaction[field] = diff[field];+ if (+ newTransaction[field] == null ||+ newTransaction[field] === '' ||+ newTransaction[field] === 0 ||+ newTransaction[field] === false+ ) {+ newTransaction[field] = diff[field];}});++ // When a rule updates a parent transaction, overwrite all changes to the current field in subtransactions.+ if (+ newTransaction.is_parent &&+ diff.subtransactions !== undefined &&+ updatedField !== null+ ) {+ newTransaction.subtransactions = diff.subtransactions.map(+ (st, idx) => ({+ ...(newTransaction.subtransactions[idx] || st),+ ...(st[updatedField] != null && {+ [updatedField]: st[updatedField],+ }),+ }),+ );+ }}}const { data: newTransactions } = updateTransaction(transactions,- transaction,+ newTransaction,);setTransactions(newTransactions);};diff --git a/upcoming-release-notes/3073.md b/upcoming-release-notes/3073.mdnew file mode 100644index 0000000000..8987c45156--- /dev/null+++ b/upcoming-release-notes/3073.md@@ -0,0 +1,6 @@+---+category: Bugfix+authors: [joel-jeremy]+---++Fix rules in mobile transaction entry