if (emptyAmountAccounts.size() > 0) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
emptyAmountAccounts.forEach((currency, accounts) -> {
- if (accounts.size() != 1)
+ final Float balance = emptyAmountAccountBalance.get(currency);
+
+ if (balance != null && !Misc.isZero(balance) && accounts.size() != 1) {
throw new RuntimeException(String.format(Locale.US,
- "Should not happen: approved transaction has %d accounts for " +
- "currency %s", accounts.size(), currency));
- accounts.get(0)
- .setAmount(-emptyAmountAccountBalance.get(currency));
+ "Should not happen: approved transaction has %d accounts " +
+ "without amounts for currency '%s'", accounts.size(), currency));
+ }
+ accounts.forEach(acc -> acc.setAmount(balance == null ? 0 : -balance));
});
}
else {
for (String currency : emptyAmountAccounts.keySet()) {
List<LedgerTransactionAccount> accounts =
Objects.requireNonNull(emptyAmountAccounts.get(currency));
-
- if (accounts.size() != 1)
+ final Float balance = emptyAmountAccountBalance.get(currency);
+ if (balance != null && !Misc.isZero(balance) && accounts.size() != 1)
throw new RuntimeException(String.format(Locale.US,
"Should not happen: approved transaction has %d accounts for " +
"currency %s", accounts.size(), currency));
- accounts.get(0)
- .setAmount(-emptyAmountAccountBalance.get(currency));
+ for (LedgerTransactionAccount acc : accounts) {
+ acc.setAmount(balance == null ? 0 : -balance);
+ }
}
}
}
int singleNegativeIndex = -1;
int singlePositiveIndex = -1;
int negativeCount = 0;
+ boolean hasCurrency = false;
for (int i = 0; i < accounts.size(); i++) {
LedgerTransactionAccount acc = accounts.get(i);
TransactionAccount item = new TransactionAccount(acc.getAccountName(),
}
else
item.resetAmount();
+
+ if (item.getCurrency()
+ .length() > 0)
+ hasCurrency = true;
}
if (BuildConfig.DEBUG)
dumpItemList("Loaded previous transaction", newList);
moveItemLast(newList, singlePositiveIndex);
}
+ final boolean foundTransactionHasCurrency = hasCurrency;
Misc.onMainThread(() -> {
setItems(newList);
noteFocusChanged(1, FocusedElement.Amount);
+ if (foundTransactionHasCurrency)
+ showCurrency.setValue(true);
});
}
/**
!Misc.equalStrings(acc.getAmountHint(), hint))
{
Logger.debug("submittable",
- String.format("Setting amount hint of {%s} to %s [%s]",
- acc.toString(), hint, balCurrency));
+ String.format("Setting amount hint of {%s} to %s [%s]", acc,
+ hint, balCurrency));
acc.setAmountHint(hint);
listChanged = true;
}
b.append(String.format(" '%s'", description));
if (date != null)
- b.append(String.format("@%s", date.toString()));
+ b.append(String.format("@%s", date));
if (!TextUtils.isEmpty(comment))
b.append(String.format(" /%s/", comment));
equal = equal && Misc.equalStrings(currency, other.currency) && isLast == other.isLast;
Logger.debug("new-trans",
- String.format("Comparing {%s} and {%s}: %s", this.toString(), other.toString(),
- equal));
+ String.format("Comparing {%s} and {%s}: %s", this, other, equal));
return equal;
}
public int getAccountNameCursorPosition() {