Fix/holdings always include cash position (#1897)

* Improved holdings table showing cash position also when the filter contains accounts

* Update changelog
pull/1898/head^2
Francisco Silva 2 years ago committed by GitHub
parent 0464adccce
commit 672d8dfab2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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

@ -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
};

Loading…
Cancel
Save