Browse Source

Bugfix/interest of account for activities with quantity other than one (#7989)

* Fix interest of account for activities with quantity other than one

* Update changelog
pull/8018/head
Thomas Kaul 1 week ago
committed by GitHub
parent
commit
0bee7f5cf1
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 60
      apps/api/src/app/portfolio/portfolio.service.spec.ts
  3. 2
      apps/api/src/app/portfolio/portfolio.service.ts

1
CHANGELOG.md

@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ### Fixed
- Fixed the calculation of the interest in the account detail dialog for activities with a quantity other than one
- Fixed the positive performance from the all time high in the watchlist - Fixed the positive performance from the all time high in the watchlist
- Fixed the portfolio calculation for holdings with historical market prices between the chart dates - Fixed the portfolio calculation for holdings with historical market prices between the chart dates
- Fixed the asset profile identifier in the historical market data gathering of the `POST api/v1/activities` endpoint - Fixed the asset profile identifier in the historical market data gathering of the `POST api/v1/activities` endpoint

60
apps/api/src/app/portfolio/portfolio.service.spec.ts

@ -260,6 +260,66 @@ describe('PortfolioService', () => {
AND: [whereActivityOfAssetClass, whereActivityOfTag] 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: 3,
SymbolProfile: { currency: 'USD' },
tags: [],
type: 'INTEREST',
unitPrice: 5
}
],
balance: 0,
currency: 'USD',
id: 'account-id',
name: 'Account'
}
] as unknown as Awaited<ReturnType<typeof accountService.accounts>>);
jest.spyOn(portfolioService, 'getDetails').mockResolvedValue({
accounts: {}
} as unknown as Awaited<ReturnType<typeof portfolioService.getDetails>>);
jest.spyOn(userService, 'user').mockResolvedValue({
settings: { settings: { baseCurrency: 'USD' } }
} as unknown as Awaited<ReturnType<typeof userService.user>>);
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: 15
});
});
}); });
describe('getAggregatedMarkets', () => { describe('getAggregatedMarkets', () => {

2
apps/api/src/app/portfolio/portfolio.service.ts

@ -334,7 +334,7 @@ export class PortfolioService {
case ActivityType.INTEREST: case ActivityType.INTEREST:
interestInBaseCurrency += interestInBaseCurrency +=
(await this.exchangeRateDataService.toCurrencyAtDate( (await this.exchangeRateDataService.toCurrencyAtDate(
unitPrice, new Big(quantity).mul(unitPrice).toNumber(),
currency ?? SymbolProfile.currency, currency ?? SymbolProfile.currency,
userCurrency, userCurrency,
date date

Loading…
Cancel
Save