Skip to content

Commit

Permalink
codinguser#876 - ** Allow null to enter SplitEditor + Transfert if fr…
Browse files Browse the repository at this point in the history
…om TransactionFormFragment.extractSplitsFromView to Money.setAmount()
  • Loading branch information
JeanGarf committed Jun 14, 2020
1 parent 453252e commit 3e333ec
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 54 deletions.
13 changes: 13 additions & 0 deletions app/src/main/java/org/gnucash/android/model/Money.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,19 @@ public Money negate(){
* @param amount {@link BigDecimal} amount to be set
*/
private void setAmount(@NonNull BigDecimal amount) {

if (amount != null) {
// Amount is not null

// NTD

} else {
// Amount is null

// init to 0
amount = new BigDecimal(0);
}

mAmount = amount.setScale(mCommodity.getSmallestFractionDigits(), ROUNDING_MODE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -716,59 +716,51 @@ private void updateTransferAccountsList(){
*/
private void openSplitEditor() {

if (mAmountEditText.getValue() == null) {
String baseAmountString;

Toast.makeText(getActivity(),
R.string.toast_enter_amount_to_split,
Toast.LENGTH_SHORT)
.show();

} else {

String baseAmountString;

if (mTransaction == null) {
// we are creating a new transaction (not editing an existing one)
if (mTransaction == null) {
// we are creating a new transaction (not editing an existing one)

BigDecimal enteredAmount = mAmountEditText.getValue();
BigDecimal enteredAmount = mAmountEditText.getValue() != null
? mAmountEditText.getValue()
: new BigDecimal(0);

baseAmountString = enteredAmount.toPlainString();
baseAmountString = enteredAmount.toPlainString();

} else {
// we are editing an existing transaction
} else {
// we are editing an existing transaction

//
// Find splits biggest amount (in absolute value)
//
//
// Find splits biggest amount (in absolute value)
//

Money biggestAmount = Money.createZeroInstance(mTransaction.getCurrencyCode());
Money biggestAmount = Money.createZeroInstance(mTransaction.getCurrencyCode());

for (Split split : mTransaction.getSplits()) {
if (split.getValue()
.asBigDecimal()
.compareTo(biggestAmount.asBigDecimal()) > 0) {
biggestAmount = split.getValue();
}
} // for
for (Split split : mTransaction.getSplits()) {
if (split.getValue()
.asBigDecimal()
.compareTo(biggestAmount.asBigDecimal()) > 0) {
biggestAmount = split.getValue();
}
} // for

baseAmountString = biggestAmount.toPlainString();
}
baseAmountString = biggestAmount.toPlainString();
}

Intent intent = new Intent(getActivity(),
FormActivity.class);
intent.putExtra(UxArgument.FORM_TYPE,
FormActivity.FormType.SPLIT_EDITOR.name());
intent.putExtra(UxArgument.SELECTED_ACCOUNT_UID,
mAccountUID);
intent.putExtra(UxArgument.AMOUNT_STRING,
baseAmountString);
Intent intent = new Intent(getActivity(),
FormActivity.class);
intent.putExtra(UxArgument.FORM_TYPE,
FormActivity.FormType.SPLIT_EDITOR.name());
intent.putExtra(UxArgument.SELECTED_ACCOUNT_UID,
mAccountUID);
intent.putExtra(UxArgument.AMOUNT_STRING,
baseAmountString);

intent.putParcelableArrayListExtra(UxArgument.SPLIT_LIST,
(ArrayList<Split>) extractSplitsFromView());
intent.putParcelableArrayListExtra(UxArgument.SPLIT_LIST,
(ArrayList<Split>) extractSplitsFromView());

startActivityForResult(intent,
REQUEST_SPLIT_EDITOR);
}
startActivityForResult(intent,
REQUEST_SPLIT_EDITOR);
}

/**
Expand Down Expand Up @@ -869,18 +861,6 @@ private List<Split> extractSplitsFromView() {

BigDecimal amountBigD = mAmountEditText.getValue();

if (amountBigD != null) {
// Amount is null

// RAF

} else {
// Amount is not null

// init to 0
amountBigD=new BigDecimal(0);
}

String baseCurrencyCode = mTransactionsDbAdapter.getAccountCurrencyCode(mAccountUID);

// Store signed amount
Expand Down

0 comments on commit 3e333ec

Please sign in to comment.