From 2b1a4e278218ca40b73cda6724075dbbfb319b9d Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Thu, 1 Oct 2026 08:25:50 +0200 Subject: [PATCH] Fix interest of account for activities with quantity other than one --- .../app/portfolio/portfolio.service.spec.ts | 60 +++++++++++++++++++ .../src/app/portfolio/portfolio.service.ts | 2 +- 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/apps/api/src/app/portfolio/portfolio.service.spec.ts b/apps/api/src/app/portfolio/portfolio.service.spec.ts index ccd26e0345..8a13d52a9d 100644 --- a/apps/api/src/app/portfolio/portfolio.service.spec.ts +++ b/apps/api/src/app/portfolio/portfolio.service.spec.ts @@ -260,6 +260,66 @@ describe('PortfolioService', () => { AND: [whereActivityOfAssetClass, whereActivityOfTag] }); }); + + it('should calculate the dividend and the interest of an account as quantity times unit price', async () => { + jest.spyOn(accountService, 'accounts').mockResolvedValue([ + { + activities: [ + { + currency: 'USD', + date: new Date('2024-01-02'), + quantity: 2, + SymbolProfile: { currency: 'USD' }, + tags: [], + type: 'DIVIDEND', + unitPrice: 10 + }, + { + currency: 'USD', + date: new Date('2024-01-03'), + quantity: 2, + SymbolProfile: { currency: 'USD' }, + tags: [], + type: 'INTEREST', + unitPrice: 10 + } + ], + balance: 0, + currency: 'USD', + id: 'account-id', + name: 'Account' + } + ] as unknown as Awaited>); + + jest.spyOn(portfolioService, 'getDetails').mockResolvedValue({ + accounts: {} + } as unknown as Awaited>); + + jest.spyOn(userService, 'user').mockResolvedValue({ + settings: { settings: { baseCurrency: 'USD' } } + } as unknown as Awaited>); + + jest + .spyOn(exchangeRateDataService, 'toCurrencyAtDate') + .mockImplementation(async (value) => { + return value; + }); + + jest + .spyOn(exchangeRateDataService, 'toCurrency') + .mockImplementation((value) => { + return value; + }); + + const [account] = await portfolioService.getAccounts({ + userId: userDummyData.id + }); + + expect(account).toMatchObject({ + dividendInBaseCurrency: 20, + interestInBaseCurrency: 20 + }); + }); }); describe('getAggregatedMarkets', () => { diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index 72c5b5946a..d906fd6aef 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -334,7 +334,7 @@ export class PortfolioService { case ActivityType.INTEREST: interestInBaseCurrency += (await this.exchangeRateDataService.toCurrencyAtDate( - unitPrice, + new Big(quantity).mul(unitPrice).toNumber(), currency ?? SymbolProfile.currency, userCurrency, date