From eb0f00d4969b3de0df8b84542c718c4c787bd806 Mon Sep 17 00:00:00 2001 From: JeanGarf Date: Thu, 28 May 2020 11:50:31 +0200 Subject: [PATCH] #876 - Fix NPE when type switching on a new transaction --- .../transaction/TransactionFormFragment.java | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/gnucash/android/ui/transaction/TransactionFormFragment.java b/app/src/main/java/org/gnucash/android/ui/transaction/TransactionFormFragment.java index c11841b1d..a5f9b91e0 100644 --- a/app/src/main/java/org/gnucash/android/ui/transaction/TransactionFormFragment.java +++ b/app/src/main/java/org/gnucash/android/ui/transaction/TransactionFormFragment.java @@ -783,8 +783,11 @@ private void setListeners() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - // Compute balance signed value of saved transaction - final Money signedTransactionBalance = mTransaction.getBalance(mAccountUID); + // UI to Transaction + Transaction transaction = extractTransactionFromView(); + + // Compute balance signed value of transaction + final Money signedTransactionBalance = transaction.getBalance(mAccountUID); // Update Amount Signum updateAmountEditText(signedTransactionBalance); @@ -984,6 +987,13 @@ private List extractSplitsFromView() { transaction.setSplits(splits); transaction.setExported(false); //not necessary as exports use timestamps now. Because, legacy + if (mEditMode) { + // Editing an existing transaction + + // reset the transaction UID + transaction.setUID(mTransaction.getUID()); + } + return transaction; } @@ -1029,13 +1039,16 @@ private void saveNewTransaction() { return; } - Transaction transaction = extractTransactionFromView(); + // + // UI to Transaction, with same UID if transaction edit mode + // + + mTransaction = extractTransactionFromView(); - if (mEditMode) { //if editing an existing transaction - transaction.setUID(mTransaction.getUID()); - } + // + // Save transaction in DB + // - mTransaction = transaction; mAccountsDbAdapter.beginTransaction(); try {