Browse Source

Fix exception in value of account calculation caused by liabilities

pull/3109/head
Thomas Kaul 1 year ago
parent
commit
48ca184c72
  1. 17
      apps/api/src/app/portfolio/portfolio.service.ts

17
apps/api/src/app/portfolio/portfolio.service.ts

@ -1941,7 +1941,7 @@ export class PortfolioService {
private async getTransactionPoints({ private async getTransactionPoints({
filters, filters,
includeDrafts = false, includeDrafts = false,
types = ['BUY', 'ITEM', 'SELL'], types = ['BUY', 'ITEM', 'LIABILITY', 'SELL'],
userId, userId,
withExcludedAccounts = false withExcludedAccounts = false
}: { }: {
@ -2076,19 +2076,10 @@ export class PortfolioService {
}); });
for (const account of currentAccounts) { for (const account of currentAccounts) {
let ordersByAccount = orders.filter(({ accountId }) => { const ordersByAccount = orders.filter(({ accountId }) => {
return accountId === account.id; return accountId === account.id;
}); });
const ordersOfTypeItemOrLiabilityByAccount =
ordersOfTypeItemOrLiability.filter(({ accountId }) => {
return accountId === account.id;
});
ordersByAccount = ordersByAccount.concat(
ordersOfTypeItemOrLiabilityByAccount
);
accounts[account.id] = { accounts[account.id] = {
balance: account.balance, balance: account.balance,
currency: account.currency, currency: account.currency,
@ -2128,8 +2119,8 @@ export class PortfolioService {
} of ordersByAccount) { } of ordersByAccount) {
let currentValueOfSymbolInBaseCurrency = let currentValueOfSymbolInBaseCurrency =
quantity * quantity *
portfolioItemsNow[SymbolProfile.symbol] (portfolioItemsNow[SymbolProfile.symbol]?.marketPriceInBaseCurrency ??
?.marketPriceInBaseCurrency ?? 0; 0);
if (['LIABILITY', 'SELL'].includes(type)) { if (['LIABILITY', 'SELL'].includes(type)) {
currentValueOfSymbolInBaseCurrency *= getFactor(type); currentValueOfSymbolInBaseCurrency *= getFactor(type);

Loading…
Cancel
Save