Feature/allow account for activity of type item (#1641)
* Support linking wealth items to account * Update changelog
This commit is contained in:
parent
cfffb99f52
commit
2e7f46ad78
@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Added support to link a (wealth) item to an account
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Improved the language localization for German (`de`)
|
- Improved the language localization for German (`de`)
|
||||||
|
@ -37,8 +37,7 @@ export class AccountController {
|
|||||||
private readonly accountService: AccountService,
|
private readonly accountService: AccountService,
|
||||||
private readonly impersonationService: ImpersonationService,
|
private readonly impersonationService: ImpersonationService,
|
||||||
private readonly portfolioService: PortfolioService,
|
private readonly portfolioService: PortfolioService,
|
||||||
@Inject(REQUEST) private readonly request: RequestWithUser,
|
@Inject(REQUEST) private readonly request: RequestWithUser
|
||||||
private readonly userService: UserService
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@Delete(':id')
|
@Delete(':id')
|
||||||
|
@ -76,23 +76,21 @@ export class OrderService {
|
|||||||
userId: string;
|
userId: string;
|
||||||
}
|
}
|
||||||
): Promise<Order> {
|
): Promise<Order> {
|
||||||
const defaultAccount = (
|
let Account;
|
||||||
await this.accountService.getAccounts(data.userId)
|
|
||||||
).find((account) => {
|
if (data.accountId) {
|
||||||
return account.isDefault === true;
|
Account = {
|
||||||
});
|
connect: {
|
||||||
|
id_userId: {
|
||||||
|
userId: data.userId,
|
||||||
|
id: data.accountId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const tags = data.tags ?? [];
|
const tags = data.tags ?? [];
|
||||||
|
|
||||||
let Account = {
|
|
||||||
connect: {
|
|
||||||
id_userId: {
|
|
||||||
userId: data.userId,
|
|
||||||
id: data.accountId ?? defaultAccount?.id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (data.type === 'ITEM') {
|
if (data.type === 'ITEM') {
|
||||||
const assetClass = data.assetClass;
|
const assetClass = data.assetClass;
|
||||||
const assetSubClass = data.assetSubClass;
|
const assetSubClass = data.assetSubClass;
|
||||||
@ -101,7 +99,6 @@ export class OrderService {
|
|||||||
const id = uuidv4();
|
const id = uuidv4();
|
||||||
const name = data.SymbolProfile.connectOrCreate.create.symbol;
|
const name = data.SymbolProfile.connectOrCreate.create.symbol;
|
||||||
|
|
||||||
Account = undefined;
|
|
||||||
data.id = id;
|
data.id = id;
|
||||||
data.SymbolProfile.connectOrCreate.create.assetClass = assetClass;
|
data.SymbolProfile.connectOrCreate.create.assetClass = assetClass;
|
||||||
data.SymbolProfile.connectOrCreate.create.assetSubClass = assetSubClass;
|
data.SymbolProfile.connectOrCreate.create.assetSubClass = assetSubClass;
|
||||||
|
@ -573,7 +573,6 @@ export class PortfolioService {
|
|||||||
const cashPositions = await this.getCashPositions({
|
const cashPositions = await this.getCashPositions({
|
||||||
cashDetails,
|
cashDetails,
|
||||||
userCurrency,
|
userCurrency,
|
||||||
investment: totalInvestmentInBaseCurrency,
|
|
||||||
value: filteredValueInBaseCurrency
|
value: filteredValueInBaseCurrency
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -599,7 +598,6 @@ export class PortfolioService {
|
|||||||
const cashPositions = await this.getCashPositions({
|
const cashPositions = await this.getCashPositions({
|
||||||
cashDetails,
|
cashDetails,
|
||||||
userCurrency,
|
userCurrency,
|
||||||
investment: totalInvestmentInBaseCurrency,
|
|
||||||
value: filteredValueInBaseCurrency
|
value: filteredValueInBaseCurrency
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1209,12 +1207,10 @@ export class PortfolioService {
|
|||||||
|
|
||||||
private async getCashPositions({
|
private async getCashPositions({
|
||||||
cashDetails,
|
cashDetails,
|
||||||
investment,
|
|
||||||
userCurrency,
|
userCurrency,
|
||||||
value
|
value
|
||||||
}: {
|
}: {
|
||||||
cashDetails: CashDetails;
|
cashDetails: CashDetails;
|
||||||
investment: Big;
|
|
||||||
userCurrency: string;
|
userCurrency: string;
|
||||||
value: Big;
|
value: Big;
|
||||||
}) {
|
}) {
|
||||||
@ -1692,6 +1688,14 @@ export class PortfolioService {
|
|||||||
userId: string;
|
userId: string;
|
||||||
withExcludedAccounts?: boolean;
|
withExcludedAccounts?: boolean;
|
||||||
}) {
|
}) {
|
||||||
|
const ordersOfTypeItem = await this.orderService.getOrders({
|
||||||
|
filters,
|
||||||
|
userCurrency,
|
||||||
|
userId,
|
||||||
|
withExcludedAccounts,
|
||||||
|
types: ['ITEM']
|
||||||
|
});
|
||||||
|
|
||||||
const accounts: PortfolioDetails['accounts'] = {};
|
const accounts: PortfolioDetails['accounts'] = {};
|
||||||
|
|
||||||
let currentAccounts: (Account & {
|
let currentAccounts: (Account & {
|
||||||
@ -1722,10 +1726,18 @@ export class PortfolioService {
|
|||||||
});
|
});
|
||||||
|
|
||||||
for (const account of currentAccounts) {
|
for (const account of currentAccounts) {
|
||||||
const ordersByAccount = orders.filter(({ accountId }) => {
|
let ordersByAccount = orders.filter(({ accountId }) => {
|
||||||
return accountId === account.id;
|
return accountId === account.id;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const ordersOfTypeItemByAccount = ordersOfTypeItem.filter(
|
||||||
|
({ accountId }) => {
|
||||||
|
return accountId === account.id;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
ordersByAccount = ordersByAccount.concat(ordersOfTypeItemByAccount);
|
||||||
|
|
||||||
accounts[account.id] = {
|
accounts[account.id] = {
|
||||||
balance: account.balance,
|
balance: account.balance,
|
||||||
currency: account.currency,
|
currency: account.currency,
|
||||||
@ -1745,7 +1757,9 @@ export class PortfolioService {
|
|||||||
for (const order of ordersByAccount) {
|
for (const order of ordersByAccount) {
|
||||||
let currentValueOfSymbolInBaseCurrency =
|
let currentValueOfSymbolInBaseCurrency =
|
||||||
order.quantity *
|
order.quantity *
|
||||||
portfolioItemsNow[order.SymbolProfile.symbol]?.marketPrice ?? 0;
|
(portfolioItemsNow[order.SymbolProfile.symbol]?.marketPrice ??
|
||||||
|
order.unitPrice ??
|
||||||
|
0);
|
||||||
let originalValueOfSymbolInBaseCurrency =
|
let originalValueOfSymbolInBaseCurrency =
|
||||||
this.exchangeRateDataService.toCurrency(
|
this.exchangeRateDataService.toCurrency(
|
||||||
order.quantity * order.unitPrice,
|
order.quantity * order.unitPrice,
|
||||||
|
@ -18,12 +18,14 @@
|
|||||||
</mat-select>
|
</mat-select>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div>
|
||||||
[ngClass]="{ 'd-none': !activityForm.controls['accountId'].hasValidator(Validators.required) }"
|
|
||||||
>
|
|
||||||
<mat-form-field appearance="outline" class="w-100">
|
<mat-form-field appearance="outline" class="w-100">
|
||||||
<mat-label i18n>Account</mat-label>
|
<mat-label i18n>Account</mat-label>
|
||||||
<mat-select formControlName="accountId">
|
<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"
|
<mat-option *ngFor="let account of data.accounts" [value]="account.id"
|
||||||
>{{ account.name }}</mat-option
|
>{{ account.name }}</mat-option
|
||||||
>
|
>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user