Skip to content
Snippets Groups Projects
Commit 399b29e8 authored by Robert Goldmann's avatar Robert Goldmann
Browse files

Fixed #485 - new default account is not set on deletion of a default account;...

Fixed #485 - new default account is not set on deletion of a default account; error when deleting repeating transactions
parent 95279025
No related branches found
No related tags found
No related merge requests found
Pipeline #2221 passed
......@@ -50,15 +50,15 @@ public class AccountService implements Resetable
transactionService.deleteTransactionsWithAccount(accountToDelete);
accountToDelete.setReferringTransactions(new ArrayList<>());
List<Account> accounts = accountRepository.findAll();
accounts.remove(accountToDelete);
Account newSelectedAccount = accounts.get(0);
selectAccount(newSelectedAccount.getID());
// select "all accounts" as selected account
selectAccount(accountRepository.findAllByType(AccountType.ALL).get(0).getID());
// set new default if necessary
if(accountToDelete.isDefault())
{
setAsDefaultAccount(accountRepository.findAllByType(AccountType.CUSTOM).get(0).getID());
List<Account> accounts = accountRepository.findAllByType(AccountType.CUSTOM);
accounts.remove(accountToDelete);
setAsDefaultAccount(accounts.get(0).getID());
}
accountRepository.delete(ID);
......
......@@ -23,6 +23,7 @@ import java.util.List;
@Service
public class TransactionService implements Resetable
{
private final Logger LOGGER = LoggerFactory.getLogger(this.getClass());
private TransactionRepository transactionRepository;
private RepeatingOptionRepository repeatingOptionRepository;
private CategoryRepository categoryRepository;
......@@ -141,6 +142,12 @@ public class TransactionService implements Resetable
private void deleteTransactionInRepo(Integer ID)
{
Transaction transactionToDelete = transactionRepository.findOne(ID);
if(transactionToDelete == null)
{
LOGGER.debug("Skipping already deleted transaction with ID: " + ID);
return;
}
// handle repeating transactions
if(transactionToDelete.getRepeatingOption() == null)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment