+ if (emptyAmountAccounts.size() > 0) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+ emptyAmountAccounts.forEach((currency, accounts) -> {
+ 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 " +
+ "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));
+ 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));
+ for (LedgerTransactionAccount acc : accounts) {
+ acc.setAmount(balance == null ? 0 : -balance);
+ }
+ }
+ }
+ }