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

Fixed #655 - prefill new transaction from template without account with...

Fixed #655 - prefill new transaction from template without account with selected account if possible
parent 6538b7d6
No related branches found
No related tags found
No related merge requests found
...@@ -259,4 +259,15 @@ public class AccountService implements Resettable, AccessAllEntities<Account>, A ...@@ -259,4 +259,15 @@ public class AccountService implements Resettable, AccessAllEntities<Account>, A
selectAccount(accountRepository.findAllByType(AccountType.ALL).get(0).getID()); selectAccount(accountRepository.findAllByType(AccountType.ALL).get(0).getID());
} }
} }
public Account getSelectedAccountOrDefaultAsFallback()
{
final Account selectedAccount = accountRepository.findByIsSelected(true);
if(selectedAccount != null)
{
return selectedAccount;
}
return accountRepository.findByIsDefault(true);
}
} }
...@@ -85,19 +85,19 @@ public class TemplateService implements Resettable, AccessAllEntities<Template>, ...@@ -85,19 +85,19 @@ public class TemplateService implements Resettable, AccessAllEntities<Template>,
if(prepareAccount && template.getAccount() == null) if(prepareAccount && template.getAccount() == null)
{ {
template.setAccount(accountService.getRepository().findByIsDefault(true)); template.setAccount(accountService.getSelectedAccountOrDefaultAsFallback());
} }
final Account account = template.getAccount(); final Account account = template.getAccount();
if(account != null && account.getAccountState() != AccountState.FULL_ACCESS) if(account != null && account.getAccountState() != AccountState.FULL_ACCESS)
{ {
template.setAccount(accountService.getRepository().findByIsDefault(true)); template.setAccount(accountService.getSelectedAccountOrDefaultAsFallback());
} }
final Account transferAccount = template.getTransferAccount(); final Account transferAccount = template.getTransferAccount();
if(transferAccount != null && transferAccount.getAccountState() != AccountState.FULL_ACCESS) if(transferAccount != null && transferAccount.getAccountState() != AccountState.FULL_ACCESS)
{ {
template.setTransferAccount(accountService.getRepository().findByIsDefault(true)); template.setTransferAccount(accountService.getSelectedAccountOrDefaultAsFallback());
} }
} }
......
...@@ -25,7 +25,7 @@ class TemplateServiceTest ...@@ -25,7 +25,7 @@ class TemplateServiceTest
{ {
private static final Category CATEGORY_NONE = new Category("No category", "#FFFFFF", CategoryType.NONE); private static final Category CATEGORY_NONE = new Category("No category", "#FFFFFF", CategoryType.NONE);
private static final Account ACCOUNT_DEFAULT = new Account("Default Account", AccountType.CUSTOM); private static final Account ACCOUNT_SELECTED = new Account("Selected Account", AccountType.CUSTOM);
@Mock @Mock
private TemplateRepository templateRepository; private TemplateRepository templateRepository;
...@@ -91,11 +91,11 @@ class TemplateServiceTest ...@@ -91,11 +91,11 @@ class TemplateServiceTest
template.setAccount(account); template.setAccount(account);
Mockito.when(accountService.getRepository()).thenReturn(accountRepository); Mockito.when(accountService.getRepository()).thenReturn(accountRepository);
Mockito.when(accountRepository.findByIsDefault(true)).thenReturn(ACCOUNT_DEFAULT); Mockito.when(accountService.getSelectedAccountOrDefaultAsFallback()).thenReturn(ACCOUNT_SELECTED);
final Template expectedTemplate = new Template(); final Template expectedTemplate = new Template();
expectedTemplate.setCategory(CATEGORY_NONE); expectedTemplate.setCategory(CATEGORY_NONE);
expectedTemplate.setAccount(ACCOUNT_DEFAULT); expectedTemplate.setAccount(ACCOUNT_SELECTED);
templateService.prepareTemplateForNewTransaction(template, false); templateService.prepareTemplateForNewTransaction(template, false);
assertThat(template).isEqualTo(expectedTemplate); assertThat(template).isEqualTo(expectedTemplate);
...@@ -139,12 +139,12 @@ class TemplateServiceTest ...@@ -139,12 +139,12 @@ class TemplateServiceTest
template.setTransferAccount(transferAccount); template.setTransferAccount(transferAccount);
Mockito.when(accountService.getRepository()).thenReturn(accountRepository); Mockito.when(accountService.getRepository()).thenReturn(accountRepository);
Mockito.when(accountRepository.findByIsDefault(true)).thenReturn(ACCOUNT_DEFAULT); Mockito.when(accountService.getSelectedAccountOrDefaultAsFallback()).thenReturn(ACCOUNT_SELECTED);
final Template expectedTemplate = new Template(); final Template expectedTemplate = new Template();
expectedTemplate.setCategory(CATEGORY_NONE); expectedTemplate.setCategory(CATEGORY_NONE);
expectedTemplate.setAccount(account); expectedTemplate.setAccount(account);
expectedTemplate.setTransferAccount(ACCOUNT_DEFAULT); expectedTemplate.setTransferAccount(ACCOUNT_SELECTED);
templateService.prepareTemplateForNewTransaction(template, false); templateService.prepareTemplateForNewTransaction(template, false);
assertThat(template).isEqualTo(expectedTemplate); assertThat(template).isEqualTo(expectedTemplate);
...@@ -157,11 +157,11 @@ class TemplateServiceTest ...@@ -157,11 +157,11 @@ class TemplateServiceTest
template.setCategory(CATEGORY_NONE); template.setCategory(CATEGORY_NONE);
Mockito.when(accountService.getRepository()).thenReturn(accountRepository); Mockito.when(accountService.getRepository()).thenReturn(accountRepository);
Mockito.when(accountRepository.findByIsDefault(true)).thenReturn(ACCOUNT_DEFAULT); Mockito.when(accountService.getSelectedAccountOrDefaultAsFallback()).thenReturn(ACCOUNT_SELECTED);
final Template expectedTemplate = new Template(); final Template expectedTemplate = new Template();
expectedTemplate.setCategory(CATEGORY_NONE); expectedTemplate.setCategory(CATEGORY_NONE);
expectedTemplate.setAccount(ACCOUNT_DEFAULT); expectedTemplate.setAccount(ACCOUNT_SELECTED);
templateService.prepareTemplateForNewTransaction(template, true); templateService.prepareTemplateForNewTransaction(template, true);
assertThat(template).isEqualTo(expectedTemplate); assertThat(template).isEqualTo(expectedTemplate);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment