Skip to content

Commit 957ae86

Browse files
pnemonic78rivaldi8
authored andcommitted
For transactions that have only 2 splits, re-creating the splits loses all other attributes.
Fixes #701
1 parent badbe14 commit 957ae86

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

app/src/main/java/org/gnucash/android/ui/transaction/TransactionFormFragment.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ private List<Split> extractSplitsFromView(){
698698

699699
BigDecimal amountBigd = mAmountEditText.getValue();
700700
String baseCurrencyCode = mTransactionsDbAdapter.getAccountCurrencyCode(mAccountUID);
701-
Money value = new Money(amountBigd, Commodity.getInstance(baseCurrencyCode)).abs();
701+
Money value = new Money(amountBigd, Commodity.getInstance(baseCurrencyCode));
702702
Money quantity = new Money(value);
703703

704704
String transferAcctUID = getTransferAccountUID();
@@ -719,9 +719,24 @@ private List<Split> extractSplitsFromView(){
719719
}
720720
}
721721

722-
Split split1 = new Split(value, mAccountUID);
722+
Split split1;
723+
Split split2;
724+
// Try to preserve the other split attributes.
725+
if (mSplitsList.size() >= 2) {
726+
split1 = mSplitsList.get(0);
727+
split1.setValue(value);
728+
split1.setQuantity(value);
729+
split1.setAccountUID(mAccountUID);
730+
731+
split2 = mSplitsList.get(1);
732+
split2.setValue(value);
733+
split2.setQuantity(quantity);
734+
split2.setAccountUID(transferAcctUID);
735+
} else {
736+
split1 = new Split(value, mAccountUID);
737+
split2 = new Split(value, quantity, transferAcctUID);
738+
}
723739
split1.setType(mTransactionTypeSwitch.getTransactionType());
724-
Split split2 = new Split(value, quantity, transferAcctUID);
725740
split2.setType(mTransactionTypeSwitch.getTransactionType().invert());
726741

727742
List<Split> splitList = new ArrayList<>();

0 commit comments

Comments
 (0)