From f2d431a6b89ef2064b02ec01c46d1aede8e3e5ff Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Tue, 27 Feb 2024 20:42:23 +0100 Subject: [PATCH 1/4] Bugfix/improve asset profile validation in activities import (#3057) * Improve asset profile validation * Update changelog --- CHANGELOG.md | 6 +++ apps/api/src/app/import/import.service.ts | 59 +++++++++-------------- 2 files changed, 30 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c8cb065c2..73683ccbf 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 asset profile validation in the activities import + ## 2.57.0 - 2024-02-25 ### Changed diff --git a/apps/api/src/app/import/import.service.ts b/apps/api/src/app/import/import.service.ts index e33bab347..a4895cf73 100644 --- a/apps/api/src/app/import/import.service.ts +++ b/apps/api/src/app/import/import.service.ts @@ -570,17 +570,10 @@ export class ImportService { [assetProfileIdentifier: string]: Partial; } = {}; - const uniqueActivitiesDto = uniqBy( - activitiesDto, - ({ dataSource, symbol }) => { - return getAssetProfileIdentifier({ dataSource, symbol }); - } - ); - for (const [ index, { currency, dataSource, symbol, type } - ] of uniqueActivitiesDto.entries()) { + ] of activitiesDto.entries()) { if (!this.configurationService.get('DATA_SOURCES').includes(dataSource)) { throw new Error( `activities.${index}.dataSource ("${dataSource}") is not valid` @@ -602,37 +595,33 @@ export class ImportService { } } - const assetProfile = { - currency, - ...( - await this.dataProviderService.getAssetProfiles([ - { dataSource, symbol } - ]) - )?.[symbol] - }; + if (!assetProfiles[getAssetProfileIdentifier({ dataSource, symbol })]) { + const assetProfile = { + currency, + ...( + await this.dataProviderService.getAssetProfiles([ + { dataSource, symbol } + ]) + )?.[symbol] + }; - if (type === 'BUY' || type === 'DIVIDEND' || type === 'SELL') { - if (!assetProfile?.name) { - throw new Error( - `activities.${index}.symbol ("${symbol}") is not valid for the specified data source ("${dataSource}")` - ); - } + if (type === 'BUY' || type === 'DIVIDEND' || type === 'SELL') { + if (!assetProfile?.name) { + throw new Error( + `activities.${index}.symbol ("${symbol}") is not valid for the specified data source ("${dataSource}")` + ); + } - if ( - assetProfile.currency !== currency && - !this.exchangeRateDataService.hasCurrencyPair( - currency, - assetProfile.currency - ) - ) { - throw new Error( - `activities.${index}.currency ("${currency}") does not match with "${assetProfile.currency}" and no exchange rate is available from "${currency}" to "${assetProfile.currency}"` - ); + if (assetProfile.currency !== currency) { + throw new Error( + `activities.${index}.currency ("${currency}") does not match with currency of ${assetProfile.symbol} ("${assetProfile.currency}")` + ); + } } - } - assetProfiles[getAssetProfileIdentifier({ dataSource, symbol })] = - assetProfile; + assetProfiles[getAssetProfileIdentifier({ dataSource, symbol })] = + assetProfile; + } } return assetProfiles; From d3679d41b31cb31e9ac2718cd519a4158dffe8cb Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Tue, 27 Feb 2024 20:58:04 +0100 Subject: [PATCH 2/4] Bugfix/fix query to filter activities of excluded accounts (#3059) * Fix query to filter activities of excluded accounts * Update changelog --- CHANGELOG.md | 1 + apps/api/src/app/order/order.service.ts | 15 +++++---------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73683ccbf..2020f58d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Fixed the query to filter activities of excluded accounts - Improved the asset profile validation in the activities import ## 2.57.0 - 2024-02-25 diff --git a/apps/api/src/app/order/order.service.ts b/apps/api/src/app/order/order.service.ts index e60309856..a88aa4462 100644 --- a/apps/api/src/app/order/order.service.ts +++ b/apps/api/src/app/order/order.service.ts @@ -292,19 +292,14 @@ export class OrderService { } if (types) { - where.OR = types.map((type) => { - return { - type: { - equals: type - } - }; - }); + where.type = { in: types }; } if (withExcludedAccounts === false) { - where.Account = { - NOT: { isExcluded: true } - }; + where.OR = [ + { Account: null }, + { Account: { NOT: { isExcluded: true } } } + ]; } const [orders, count] = await Promise.all([ From 3615e2f0571e4c32608c1ddf39e255b0579c7352 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Tue, 27 Feb 2024 20:58:28 +0100 Subject: [PATCH 3/4] Feature/improve handling of activities without account (#3060) * Improve handling of activities without account * Update changelog --- CHANGELOG.md | 4 ++++ apps/api/src/app/portfolio/portfolio.service.ts | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2020f58d0..b81f59c7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Changed + +- Improved the handling of activities without account + ### Fixed - Fixed the query to filter activities of excluded accounts diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index 3fafa6795..92461dce8 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -749,7 +749,9 @@ export class PortfolioService { } = position; const accounts: PortfolioPositionDetail['accounts'] = uniqBy( - orders, + orders.filter(({ Account }) => { + return Account; + }), 'Account.id' ).map(({ Account }) => { return Account; From 2cabd2131582f96f93db091906d95faf41e65650 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Tue, 27 Feb 2024 20:59:44 +0100 Subject: [PATCH 4/4] Release 2.58.0 (#3061) --- CHANGELOG.md | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b81f59c7c..f8d47dd37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ 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 +## 2.58.0 - 2024-02-27 ### Changed diff --git a/package.json b/package.json index c85458bd2..8f0b18ba9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ghostfolio", - "version": "2.57.0", + "version": "2.58.0", "homepage": "https://ghostfol.io", "license": "AGPL-3.0", "repository": "https://github.com/ghostfolio/ghostfolio",