Fix total account value calculation for liabilities (#2184)

* Fix calculation

* Update changelog

---------

Co-authored-by: Thomas <4159106+dtslvr@users.noreply.github.com>
This commit is contained in:
Hugo Persson 2023-07-28 19:42:57 +02:00 committed by GitHub
parent ca05397dcd
commit cef7fa79de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 14 deletions

View File

@ -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/), 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). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## Unreleased
### Fixed
- Considered liabilities in the total account value calculation
## 1.293.0 - 2023-07-26 ## 1.293.0 - 2023-07-26
### Added ### Added

View File

@ -1830,12 +1830,12 @@ export class PortfolioService {
userId: string; userId: string;
withExcludedAccounts?: boolean; withExcludedAccounts?: boolean;
}) { }) {
const ordersOfTypeItem = await this.orderService.getOrders({ const ordersOfTypeItemOrLiability = await this.orderService.getOrders({
filters, filters,
userCurrency, userCurrency,
userId, userId,
withExcludedAccounts, withExcludedAccounts,
types: ['ITEM'] types: ['ITEM', 'LIABILITY']
}); });
const accounts: PortfolioDetails['accounts'] = {}; const accounts: PortfolioDetails['accounts'] = {};
@ -1875,13 +1875,14 @@ export class PortfolioService {
return accountId === account.id; return accountId === account.id;
}); });
const ordersOfTypeItemByAccount = ordersOfTypeItem.filter( const ordersOfTypeItemOrLiabilityByAccount =
({ accountId }) => { ordersOfTypeItemOrLiability.filter(({ accountId }) => {
return accountId === account.id; return accountId === account.id;
} });
);
ordersByAccount = ordersByAccount.concat(ordersOfTypeItemByAccount); ordersByAccount = ordersByAccount.concat(
ordersOfTypeItemOrLiabilityByAccount
);
accounts[account.id] = { accounts[account.id] = {
balance: account.balance, balance: account.balance,
@ -1921,7 +1922,7 @@ export class PortfolioService {
order.unitPrice ?? order.unitPrice ??
0); 0);
if (order.type === 'SELL') { if (order.type === 'LIABILITY' || order.type === 'SELL') {
currentValueOfSymbolInBaseCurrency *= -1; currentValueOfSymbolInBaseCurrency *= -1;
} }

View File

@ -383,13 +383,14 @@ export class ActivitiesTableComponent implements OnChanges, OnDestroy, OnInit {
} }
private getTotalValue() { private getTotalValue() {
let totalValue = new Big(0);
const paginatedData = this.getPaginatedData(); const paginatedData = this.getPaginatedData();
for (const activity of paginatedData) { let totalValue = new Big(0);
if (isNumber(activity.valueInBaseCurrency)) {
if (activity.type === 'BUY' || activity.type === 'ITEM') { for (const { type, valueInBaseCurrency } of paginatedData) {
totalValue = totalValue.plus(activity.valueInBaseCurrency); if (isNumber(valueInBaseCurrency)) {
} else if (activity.type === 'SELL') { if (type === 'BUY' || type === 'ITEM') {
totalValue = totalValue.plus(valueInBaseCurrency);
} else if (type === 'LIABILITY' || type === 'SELL') {
return null; return null;
} }
} else { } else {