Feature/allow account for activity of type item (#1641)

* Support linking wealth items to account

* Update changelog
pull/1643/head
Thomas Kaul 1 year ago committed by GitHub
parent cfffb99f52
commit 2e7f46ad78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased
### Added
- Added support to link a (wealth) item to an account
### Changed
- Improved the language localization for German (`de`)

@ -37,8 +37,7 @@ export class AccountController {
private readonly accountService: AccountService,
private readonly impersonationService: ImpersonationService,
private readonly portfolioService: PortfolioService,
@Inject(REQUEST) private readonly request: RequestWithUser,
private readonly userService: UserService
@Inject(REQUEST) private readonly request: RequestWithUser
) {}
@Delete(':id')

@ -76,23 +76,21 @@ export class OrderService {
userId: string;
}
): Promise<Order> {
const defaultAccount = (
await this.accountService.getAccounts(data.userId)
).find((account) => {
return account.isDefault === true;
});
let Account;
if (data.accountId) {
Account = {
connect: {
id_userId: {
userId: data.userId,
id: data.accountId
}
}
};
}
const tags = data.tags ?? [];
let Account = {
connect: {
id_userId: {
userId: data.userId,
id: data.accountId ?? defaultAccount?.id
}
}
};
if (data.type === 'ITEM') {
const assetClass = data.assetClass;
const assetSubClass = data.assetSubClass;
@ -101,7 +99,6 @@ export class OrderService {
const id = uuidv4();
const name = data.SymbolProfile.connectOrCreate.create.symbol;
Account = undefined;
data.id = id;
data.SymbolProfile.connectOrCreate.create.assetClass = assetClass;
data.SymbolProfile.connectOrCreate.create.assetSubClass = assetSubClass;

@ -573,7 +573,6 @@ export class PortfolioService {
const cashPositions = await this.getCashPositions({
cashDetails,
userCurrency,
investment: totalInvestmentInBaseCurrency,
value: filteredValueInBaseCurrency
});
@ -599,7 +598,6 @@ export class PortfolioService {
const cashPositions = await this.getCashPositions({
cashDetails,
userCurrency,
investment: totalInvestmentInBaseCurrency,
value: filteredValueInBaseCurrency
});
@ -1209,12 +1207,10 @@ export class PortfolioService {
private async getCashPositions({
cashDetails,
investment,
userCurrency,
value
}: {
cashDetails: CashDetails;
investment: Big;
userCurrency: string;
value: Big;
}) {
@ -1692,6 +1688,14 @@ export class PortfolioService {
userId: string;
withExcludedAccounts?: boolean;
}) {
const ordersOfTypeItem = await this.orderService.getOrders({
filters,
userCurrency,
userId,
withExcludedAccounts,
types: ['ITEM']
});
const accounts: PortfolioDetails['accounts'] = {};
let currentAccounts: (Account & {
@ -1722,10 +1726,18 @@ export class PortfolioService {
});
for (const account of currentAccounts) {
const ordersByAccount = orders.filter(({ accountId }) => {
let ordersByAccount = orders.filter(({ accountId }) => {
return accountId === account.id;
});
const ordersOfTypeItemByAccount = ordersOfTypeItem.filter(
({ accountId }) => {
return accountId === account.id;
}
);
ordersByAccount = ordersByAccount.concat(ordersOfTypeItemByAccount);
accounts[account.id] = {
balance: account.balance,
currency: account.currency,
@ -1745,7 +1757,9 @@ export class PortfolioService {
for (const order of ordersByAccount) {
let currentValueOfSymbolInBaseCurrency =
order.quantity *
portfolioItemsNow[order.SymbolProfile.symbol]?.marketPrice ?? 0;
(portfolioItemsNow[order.SymbolProfile.symbol]?.marketPrice ??
order.unitPrice ??
0);
let originalValueOfSymbolInBaseCurrency =
this.exchangeRateDataService.toCurrency(
order.quantity * order.unitPrice,

@ -18,12 +18,14 @@
</mat-select>
</mat-form-field>
</div>
<div
[ngClass]="{ 'd-none': !activityForm.controls['accountId'].hasValidator(Validators.required) }"
>
<div>
<mat-form-field appearance="outline" class="w-100">
<mat-label i18n>Account</mat-label>
<mat-select formControlName="accountId">
<mat-option
*ngIf="!activityForm.controls['accountId'].hasValidator(Validators.required)"
[value]="null"
></mat-option>
<mat-option *ngFor="let account of data.accounts" [value]="account.id"
>{{ account.name }}</mat-option
>

Loading…
Cancel
Save