From b2b3fde80e209b5b8fbd079ed8f0acedaa6f15bb Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Mon, 10 Jan 2022 21:23:47 +0100 Subject: [PATCH] Bugfix/support multiple accounts with the same name (#623) * Support multiple accounts with the same name * Update changelog --- CHANGELOG.md | 6 ++++++ apps/api/src/app/portfolio/portfolio.service.ts | 14 ++++++++------ .../allocations/allocations-page.component.ts | 4 ++-- .../lib/interfaces/portfolio-details.interface.ts | 3 ++- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6983303d2..2cceba33c 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 + +- Fixed the support for multiple accounts with the same name + ## 1.101.0 - 08.01.2022 ### Added diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index 1902fd137..9ed19810f 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -107,7 +107,7 @@ export class PortfolioService { account.currency, userCurrency ), - value: details.accounts[account.name]?.current ?? 0 + value: details.accounts[account.id]?.current ?? 0 }; delete result.Order; @@ -1091,10 +1091,11 @@ export class PortfolioService { account.currency, userCurrency ); - accounts[account.name] = { + accounts[account.id] = { balance: convertedBalance, currency: account.currency, current: convertedBalance, + name: account.name, original: convertedBalance }; @@ -1108,16 +1109,17 @@ export class PortfolioService { originalValueOfSymbol *= -1; } - if (accounts[order.Account?.name || UNKNOWN_KEY]?.current) { - accounts[order.Account?.name || UNKNOWN_KEY].current += + if (accounts[order.Account?.id || UNKNOWN_KEY]?.current) { + accounts[order.Account?.id || UNKNOWN_KEY].current += currentValueOfSymbol; - accounts[order.Account?.name || UNKNOWN_KEY].original += + accounts[order.Account?.id || UNKNOWN_KEY].original += originalValueOfSymbol; } else { - accounts[order.Account?.name || UNKNOWN_KEY] = { + accounts[order.Account?.id || UNKNOWN_KEY] = { balance: 0, currency: order.Account?.currency, current: currentValueOfSymbol, + name: account.name, original: originalValueOfSymbol }; } diff --git a/apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts b/apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts index 5ab8ba1b5..c19af7fb4 100644 --- a/apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts +++ b/apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts @@ -162,10 +162,10 @@ export class AllocationsPageComponent implements OnDestroy, OnInit { } }; - for (const [name, { current, original }] of Object.entries( + for (const [id, { current, name, original }] of Object.entries( this.portfolioDetails.accounts )) { - this.accounts[name] = { + this.accounts[id] = { name, value: aPeriod === 'original' ? original : current }; diff --git a/libs/common/src/lib/interfaces/portfolio-details.interface.ts b/libs/common/src/lib/interfaces/portfolio-details.interface.ts index 2cbf1c6fa..17430438b 100644 --- a/libs/common/src/lib/interfaces/portfolio-details.interface.ts +++ b/libs/common/src/lib/interfaces/portfolio-details.interface.ts @@ -2,10 +2,11 @@ import { PortfolioPosition } from '@ghostfolio/common/interfaces'; export interface PortfolioDetails { accounts: { - [name: string]: { + [id: string]: { balance: number; currency: string; current: number; + name: string; original: number; }; };