START bookings optimizations

This commit is contained in:
2020-11-14 00:29:17 +01:00
parent 549535ee4c
commit 3b93a70a29
3 changed files with 16 additions and 1 deletions

View File

@@ -36,8 +36,13 @@ public class AccountStatisticService {
public void calculateStatistics(Transaction transaction) {
final Account fromAccount = transaction.getFromAccount();
final Account toAccount = transaction.getToAccount();
final long amount = transaction.getAmount();
final List<AccountStatistic> resultList = new ArrayList<>();
long amount = transaction.getAmount();
// Special case: START bookings should not increase 'spendings current period'
if (AccountType.START.equals(fromAccount.getType())) {
amount = 0;
}
for (final Period period : transaction.getPeriods()) {
resultList.add(calculateInternal(fromAccount, period, amount, true, 1));

View File

@@ -98,6 +98,12 @@ public class TransactionService {
.getMultiplierToAccount(toAccount) * amount));
}
// Special case: START bookings should not be counted towards 'expenses current period'
// as booking e.g. a mortgage of 250,000 looks kinda ugly then
if (AccountType.START.equals(fromAccount.getType())) {
transaction.setExpenseNeutral(true);
}
this.transactionRepository.save(transaction);
this.accountStatisticService.calculateStatistics(transaction);