Bugfix/Use currency conversion for fees and values (#3672)
* Use currency conversion for fees and values * Update changelog
This commit is contained in:
parent
6c79ccb2a9
commit
12c722afe1
@ -5,6 +5,13 @@ 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
|
||||||
|
|
||||||
|
- Fixed the currency conversion for fees and values in the dividend import by applying the correct rate based on the activity date
|
||||||
|
- Fixed the currency conversion for fees and values in the activities service by applying the correct rate based on the activity date
|
||||||
|
|
||||||
## 2.104.1 - 2024-08-17
|
## 2.104.1 - 2024-08-17
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
@ -82,60 +82,64 @@ export class ImportService {
|
|||||||
|
|
||||||
const Account = this.isUniqueAccount(accounts) ? accounts[0] : undefined;
|
const Account = this.isUniqueAccount(accounts) ? accounts[0] : undefined;
|
||||||
|
|
||||||
return Object.entries(dividends).map(([dateString, { marketPrice }]) => {
|
return await Promise.all(
|
||||||
const quantity =
|
Object.entries(dividends).map(async ([dateString, { marketPrice }]) => {
|
||||||
historicalData.find((historicalDataItem) => {
|
const quantity =
|
||||||
return historicalDataItem.date === dateString;
|
historicalData.find((historicalDataItem) => {
|
||||||
})?.quantity ?? 0;
|
return historicalDataItem.date === dateString;
|
||||||
|
})?.quantity ?? 0;
|
||||||
|
|
||||||
const value = new Big(quantity).mul(marketPrice).toNumber();
|
const value = new Big(quantity).mul(marketPrice).toNumber();
|
||||||
|
|
||||||
const date = parseDate(dateString);
|
const date = parseDate(dateString);
|
||||||
const isDuplicate = orders.some((activity) => {
|
const isDuplicate = orders.some((activity) => {
|
||||||
return (
|
return (
|
||||||
activity.accountId === Account?.id &&
|
activity.accountId === Account?.id &&
|
||||||
activity.SymbolProfile.currency === assetProfile.currency &&
|
activity.SymbolProfile.currency === assetProfile.currency &&
|
||||||
activity.SymbolProfile.dataSource === assetProfile.dataSource &&
|
activity.SymbolProfile.dataSource === assetProfile.dataSource &&
|
||||||
isSameSecond(activity.date, date) &&
|
isSameSecond(activity.date, date) &&
|
||||||
activity.quantity === quantity &&
|
activity.quantity === quantity &&
|
||||||
activity.SymbolProfile.symbol === assetProfile.symbol &&
|
activity.SymbolProfile.symbol === assetProfile.symbol &&
|
||||||
activity.type === 'DIVIDEND' &&
|
activity.type === 'DIVIDEND' &&
|
||||||
activity.unitPrice === marketPrice
|
activity.unitPrice === marketPrice
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
const error: ActivityError = isDuplicate
|
const error: ActivityError = isDuplicate
|
||||||
? { code: 'IS_DUPLICATE' }
|
? { code: 'IS_DUPLICATE' }
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
Account,
|
Account,
|
||||||
date,
|
date,
|
||||||
error,
|
error,
|
||||||
quantity,
|
quantity,
|
||||||
value,
|
|
||||||
accountId: Account?.id,
|
|
||||||
accountUserId: undefined,
|
|
||||||
comment: undefined,
|
|
||||||
currency: undefined,
|
|
||||||
createdAt: undefined,
|
|
||||||
fee: 0,
|
|
||||||
feeInBaseCurrency: 0,
|
|
||||||
id: assetProfile.id,
|
|
||||||
isDraft: false,
|
|
||||||
SymbolProfile: assetProfile,
|
|
||||||
symbolProfileId: assetProfile.id,
|
|
||||||
type: 'DIVIDEND',
|
|
||||||
unitPrice: marketPrice,
|
|
||||||
updatedAt: undefined,
|
|
||||||
userId: Account?.userId,
|
|
||||||
valueInBaseCurrency: this.exchangeRateDataService.toCurrency(
|
|
||||||
value,
|
value,
|
||||||
assetProfile.currency,
|
accountId: Account?.id,
|
||||||
userCurrency
|
accountUserId: undefined,
|
||||||
)
|
comment: undefined,
|
||||||
};
|
currency: undefined,
|
||||||
});
|
createdAt: undefined,
|
||||||
|
fee: 0,
|
||||||
|
feeInBaseCurrency: 0,
|
||||||
|
id: assetProfile.id,
|
||||||
|
isDraft: false,
|
||||||
|
SymbolProfile: assetProfile,
|
||||||
|
symbolProfileId: assetProfile.id,
|
||||||
|
type: 'DIVIDEND',
|
||||||
|
unitPrice: marketPrice,
|
||||||
|
updatedAt: undefined,
|
||||||
|
userId: Account?.userId,
|
||||||
|
valueInBaseCurrency:
|
||||||
|
await this.exchangeRateDataService.toCurrencyAtDate(
|
||||||
|
value,
|
||||||
|
assetProfile.currency,
|
||||||
|
userCurrency,
|
||||||
|
date
|
||||||
|
)
|
||||||
|
};
|
||||||
|
})
|
||||||
|
);
|
||||||
} catch {
|
} catch {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@ -432,18 +436,21 @@ export class ImportService {
|
|||||||
...order,
|
...order,
|
||||||
error,
|
error,
|
||||||
value,
|
value,
|
||||||
feeInBaseCurrency: this.exchangeRateDataService.toCurrency(
|
feeInBaseCurrency: await this.exchangeRateDataService.toCurrencyAtDate(
|
||||||
fee,
|
fee,
|
||||||
assetProfile.currency,
|
assetProfile.currency,
|
||||||
userCurrency
|
userCurrency,
|
||||||
|
date
|
||||||
),
|
),
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
SymbolProfile: assetProfile,
|
SymbolProfile: assetProfile,
|
||||||
valueInBaseCurrency: this.exchangeRateDataService.toCurrency(
|
valueInBaseCurrency:
|
||||||
value,
|
await this.exchangeRateDataService.toCurrencyAtDate(
|
||||||
assetProfile.currency,
|
value,
|
||||||
userCurrency
|
assetProfile.currency,
|
||||||
)
|
userCurrency,
|
||||||
|
date
|
||||||
|
)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -483,34 +483,38 @@ export class OrderService {
|
|||||||
assetProfileIdentifiers
|
assetProfileIdentifiers
|
||||||
);
|
);
|
||||||
|
|
||||||
const activities = orders.map((order) => {
|
const activities = await Promise.all(
|
||||||
const assetProfile = assetProfiles.find(({ dataSource, symbol }) => {
|
orders.map(async (order) => {
|
||||||
return (
|
const assetProfile = assetProfiles.find(({ dataSource, symbol }) => {
|
||||||
dataSource === order.SymbolProfile.dataSource &&
|
return (
|
||||||
symbol === order.SymbolProfile.symbol
|
dataSource === order.SymbolProfile.dataSource &&
|
||||||
);
|
symbol === order.SymbolProfile.symbol
|
||||||
});
|
);
|
||||||
|
});
|
||||||
|
|
||||||
const value = new Big(order.quantity).mul(order.unitPrice).toNumber();
|
const value = new Big(order.quantity).mul(order.unitPrice).toNumber();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...order,
|
...order,
|
||||||
value,
|
|
||||||
// TODO: Use exchange rate of date
|
|
||||||
feeInBaseCurrency: this.exchangeRateDataService.toCurrency(
|
|
||||||
order.fee,
|
|
||||||
order.SymbolProfile.currency,
|
|
||||||
userCurrency
|
|
||||||
),
|
|
||||||
SymbolProfile: assetProfile,
|
|
||||||
// TODO: Use exchange rate of date
|
|
||||||
valueInBaseCurrency: this.exchangeRateDataService.toCurrency(
|
|
||||||
value,
|
value,
|
||||||
order.SymbolProfile.currency,
|
feeInBaseCurrency:
|
||||||
userCurrency
|
await this.exchangeRateDataService.toCurrencyAtDate(
|
||||||
)
|
order.fee,
|
||||||
};
|
order.SymbolProfile.currency,
|
||||||
});
|
userCurrency,
|
||||||
|
order.date
|
||||||
|
),
|
||||||
|
SymbolProfile: assetProfile,
|
||||||
|
valueInBaseCurrency:
|
||||||
|
await this.exchangeRateDataService.toCurrencyAtDate(
|
||||||
|
value,
|
||||||
|
order.SymbolProfile.currency,
|
||||||
|
userCurrency,
|
||||||
|
order.date
|
||||||
|
)
|
||||||
|
};
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
return { activities, count };
|
return { activities, count };
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user