Browse Source

fix(import): scope duplicate detection to target account and normalize currency comparison

- Fixes duplicate detection incorrectly matching activities across
  different accounts (IS_DUPLICATE flag on wrong account's activities).
  When an accountId is specified in the import, the duplicate check now
  only considers existing activities within that same account.

- Fixes identical activities being persisted without a duplicate error
  by normalizing null/undefined currency values before comparison.
  Strict equality (null === undefined) silently failed to match
  activities where currency was stored as null in the DB but arrived
  as undefined from the import DTO.

Fixes #7728
Fixes #7406
pull/7796/head
Shreya 5 days ago
parent
commit
b3e8918612
  1. 27
      apps/api/src/app/import/import.service.ts

27
apps/api/src/app/import/import.service.ts

@ -1075,19 +1075,20 @@ export class ImportService {
const date = parseISO(dateString);
const isDuplicate = existingActivities.some((activity) => {
return (
(activity.comment || null) === (comment || null) &&
(activity.currency === currency ||
activity.assetProfile.currency === currency) &&
activity.assetProfile.dataSource === dataSource &&
isSameSecond(activity.date, date) &&
activity.fee === fee &&
activity.quantity === quantity &&
activity.assetProfile.symbol === symbol &&
activity.type === type &&
activity.unitPrice === unitPrice
);
});
return (
(!accountId || activity.accountId === accountId) &&
(activity.comment || null) === (comment || null) &&
((activity.currency || null) === (currency || null) ||
activity.assetProfile.currency === currency) &&
activity.assetProfile.dataSource === dataSource &&
isSameSecond(activity.date, date) &&
activity.fee === fee &&
activity.quantity === quantity &&
activity.assetProfile.symbol === symbol &&
activity.type === type &&
activity.unitPrice === unitPrice
);
});
const error: ActivityError = isDuplicate
? { code: 'IS_DUPLICATE' }

Loading…
Cancel
Save