diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c1dfc486..851dcd1e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Fixed + +- Improved the holdings table by showing the cash position also when the filter contains the accounts, so that we can see the total allocation for that account + ## 1.261.0 - 2023-04-25 ### Added diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index ff29ccd57..8e368d667 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -462,10 +462,17 @@ export class PortfolioService { }); const holdings: PortfolioDetails['holdings'] = {}; - const totalInvestmentInBaseCurrency = currentPositions.totalInvestment.plus( + const totalValueInBaseCurrency = currentPositions.currentValue.plus( cashDetails.balanceInBaseCurrency ); - let filteredValueInBaseCurrency = currentPositions.currentValue; + + const isFilteredByAccount = filters.some((filter) => { + return filter.type === 'ACCOUNT'; + }); + + let filteredValueInBaseCurrency = isFilteredByAccount + ? totalValueInBaseCurrency + : currentPositions.currentValue; if ( filters?.length === 0 || @@ -564,12 +571,11 @@ export class PortfolioService { }; } - if ( - filters?.length === 0 || - (filters?.length === 1 && - filters[0].type === 'ASSET_CLASS' && - filters[0].id === 'CASH') - ) { + const isFilteredByCash = filters.some((filter) => { + return filter.type === 'ASSET_CLASS' && filter.id === 'CASH'; + }); + + if (filters.length === 0 || isFilteredByCash || isFilteredByAccount) { const cashPositions = await this.getCashPositions({ cashDetails, userCurrency, @@ -595,7 +601,7 @@ export class PortfolioService { filters[0].id === EMERGENCY_FUND_TAG_ID && filters[0].type === 'TAG' ) { - const cashPositions = await this.getCashPositions({ + const emergencyFundCashPositions = await this.getCashPositions({ cashDetails, userCurrency, value: filteredValueInBaseCurrency @@ -620,7 +626,7 @@ export class PortfolioService { }; holdings[userCurrency] = { - ...cashPositions[userCurrency], + ...emergencyFundCashPositions[userCurrency], investment: emergencyFundInCash, value: emergencyFundInCash };