Skip to content

The open alternative to Salesforce, designed for AI.

fix(shared): round currency filter amounts to whole micros (#26690)

breken99045d695732
diff --git a/packages/twenty-front/src/modules/object-record/object-options-dropdown/hooks/useExportProcessRecordsForCSV.ts b/packages/twenty-front/src/modules/object-record/object-options-dropdown/hooks/useExportProcessRecordsForCSV.ts
index 817d6ea9107..9270dd7f673 100644
--- a/packages/twenty-front/src/modules/object-record/object-options-dropdown/hooks/useExportProcessRecordsForCSV.ts
+++ b/packages/twenty-front/src/modules/object-record/object-options-dropdown/hooks/useExportProcessRecordsForCSV.ts
@@ -1,9 +1,11 @@
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { type FieldCurrencyValue } from '@/object-record/record-field/ui/types/FieldMetadata';
import { type ObjectRecord } from '@/object-record/types/ObjectRecord';
-import { isDefined } from 'twenty-shared/utils';
+import {
+ convertCurrencyMicrosToCurrencyAmount,
+ isDefined,
+} from 'twenty-shared/utils';
import { FieldMetadataType } from '~/generated-metadata/graphql';
-import { convertCurrencyMicrosToCurrencyAmount } from '~/utils/convertCurrencyToCurrencyMicros';
export const useExportProcessRecordsForCSV = (objectNameSingular: string) => {
const { objectMetadataItem } = useObjectMetadataItem({
diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/form-types/components/FormCurrencyAmountFieldInput.tsx b/packages/twenty-front/src/modules/object-record/record-field/ui/form-types/components/FormCurrencyAmountFieldInput.tsx
index d8ab7af6eb8..4f2bf9a9d87 100644
--- a/packages/twenty-front/src/modules/object-record/record-field/ui/form-types/components/FormCurrencyAmountFieldInput.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-field/ui/form-types/components/FormCurrencyAmountFieldInput.tsx
@@ -1,11 +1,11 @@
+import {
+ convertCurrencyAmountToCurrencyMicros,
+ convertCurrencyMicrosToCurrencyAmount,
+} from 'twenty-shared/utils';
import { FormNumberFieldInput } from '@/object-record/record-field/ui/form-types/components/FormNumberFieldInput';
import { isNonEmptyString, isNumber } from '@sniptt/guards';
import { type ComponentProps } from 'react';
import { isStandaloneVariableString } from 'twenty-shared/workflow';
-import {
- convertCurrencyAmountToCurrencyMicros,
- convertCurrencyMicrosToCurrencyAmount,
-} from '~/utils/convertCurrencyToCurrencyMicros';
type FormCurrencyAmountFieldInputProps = Pick<
ComponentProps<typeof FormNumberFieldInput>,
diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/CurrencyFieldInput.tsx b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/CurrencyFieldInput.tsx
index aaedf12c2e3..1f6c62e006b 100644
--- a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/CurrencyFieldInput.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/CurrencyFieldInput.tsx
@@ -13,8 +13,10 @@ import { hasCurrencyValueChanged } from '@/object-record/record-field/ui/meta-ty
import { isFieldCurrencyValue } from '@/object-record/record-field/ui/types/guards/isFieldCurrencyValue';
import { useAvailableComponentInstanceIdOrThrow } from '@/ui/utilities/state/component-state/hooks/useAvailableComponentInstanceIdOrThrow';
import { useContext } from 'react';
-import { convertCurrencyAmountToCurrencyMicros } from '~/utils/convertCurrencyToCurrencyMicros';
-import { isDefined } from 'twenty-shared/utils';
+import {
+ convertCurrencyAmountToCurrencyMicros,
+ isDefined,
+} from 'twenty-shared/utils';
export const CurrencyFieldInput = () => {
const { fieldValue, draftValue, setDraftValue, defaultValue } =
diff --git a/packages/twenty-front/src/modules/object-record/record-table/utils/buildValueFromFilter.ts b/packages/twenty-front/src/modules/object-record/record-table/utils/buildValueFromFilter.ts
index 7de3a1c74d1..0a7cb6ea5f6 100644
--- a/packages/twenty-front/src/modules/object-record/record-table/utils/buildValueFromFilter.ts
+++ b/packages/twenty-front/src/modules/object-record/record-table/utils/buildValueFromFilter.ts
@@ -17,13 +17,13 @@ import {
} from 'twenty-shared/types';
import {
assertUnreachable,
+ convertCurrencyAmountToCurrencyMicros,
FILTER_OPERANDS_MAP,
parseJson,
parseToInstantOrThrow,
parseToPlainDateOrThrow,
} from 'twenty-shared/utils';
import { RelationType } from '~/generated-metadata/graphql';
-import { convertCurrencyAmountToCurrencyMicros } from '~/utils/convertCurrencyToCurrencyMicros';
type FilterOption = {
label: string;
diff --git a/packages/twenty-front/src/modules/object-record/spreadsheet-import/utils/buildRecordFromImportedStructuredRow.ts b/packages/twenty-front/src/modules/object-record/spreadsheet-import/utils/buildRecordFromImportedStructuredRow.ts
index ca63818eeca..4df419b4f3e 100644
--- a/packages/twenty-front/src/modules/object-record/spreadsheet-import/utils/buildRecordFromImportedStructuredRow.ts
+++ b/packages/twenty-front/src/modules/object-record/spreadsheet-import/utils/buildRecordFromImportedStructuredRow.ts
@@ -11,9 +11,10 @@ import { parsePhoneNumberWithError, type CountryCode } from 'libphonenumber-js';
import { type FieldMetadataSettings } from 'twenty-shared/types';
import {
assertUnreachable,
+ convertCurrencyAmountToCurrencyMicros,
+ getLinkUrlNormalizer,
isDefined,
isEmptyObject,
- getLinkUrlNormalizer,
normalizeUrlOrigin,
parseToPlainDateOrThrow,
turnJSDateToPlainDate,
@@ -21,7 +22,6 @@ import {
import { z } from 'zod';
import { FieldMetadataType, RelationType } from '~/generated-metadata/graphql';
import { castToString } from '~/utils/castToString';
-import { convertCurrencyAmountToCurrencyMicros } from '~/utils/convertCurrencyToCurrencyMicros';
import { stripSimpleQuotesFromString } from '~/utils/string/stripSimpleQuotesFromString';
type BuildRecordFromImportedStructuredRowArgs = {
diff --git a/packages/twenty-front/src/utils/convertCurrencyToCurrencyMicros.ts b/packages/twenty-front/src/utils/convertCurrencyToCurrencyMicros.ts
deleted file mode 100644
index d5ab628a288..00000000000
--- a/packages/twenty-front/src/utils/convertCurrencyToCurrencyMicros.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-export const convertCurrencyAmountToCurrencyMicros = (
- currencyAmount: number,
-) => {
- return Math.round(currencyAmount * 1000000);
-};
-
-export const convertCurrencyMicrosToCurrencyAmount = (
- currencyAmountMicros: number,
-) => {
- return currencyAmountMicros / 1000000;
-};
diff --git a/packages/twenty-front/src/utils/__tests__/convert-currency-amount.test.ts b/packages/twenty-shared/src/utils/currency/__tests__/convertCurrencyAmountToCurrencyMicros.test.ts
similarity index 73%
rename from packages/twenty-front/src/utils/__tests__/convert-currency-amount.test.ts
rename to packages/twenty-shared/src/utils/currency/__tests__/convertCurrencyAmountToCurrencyMicros.test.ts
index e44bda018ee..22960bfdd58 100644
--- a/packages/twenty-front/src/utils/__tests__/convert-currency-amount.test.ts
+++ b/packages/twenty-shared/src/utils/currency/__tests__/convertCurrencyAmountToCurrencyMicros.test.ts
@@ -1,7 +1,5 @@
-import {
- convertCurrencyAmountToCurrencyMicros,
- convertCurrencyMicrosToCurrencyAmount,
-} from '~/utils/convertCurrencyToCurrencyMicros';
+import { convertCurrencyAmountToCurrencyMicros } from '@/utils/currency/convertCurrencyAmountToCurrencyMicros';
+import { convertCurrencyMicrosToCurrencyAmount } from '@/utils/currency/convertCurrencyMicrosToCurrencyAmount';
describe('convertCurrencyAmountToCurrencyMicros', () => {
it('should convert currencyAmount to micros', () => {
diff --git a/packages/twenty-shared/src/utils/currency/convertCurrencyAmountToCurrencyMicros.ts b/packages/twenty-shared/src/utils/currency/convertCurrencyAmountToCurrencyMicros.ts
new file mode 100644
index 00000000000..20657beaf48
--- /dev/null
+++ b/packages/twenty-shared/src/utils/currency/convertCurrencyAmountToCurrencyMicros.ts
@@ -0,0 +1,5 @@
+export const convertCurrencyAmountToCurrencyMicros = (
+ currencyAmount: number,
+) => {
+ return Math.round(currencyAmount * 1000000);
+};
diff --git a/packages/twenty-shared/src/utils/currency/convertCurrencyMicrosToCurrencyAmount.ts b/packages/twenty-shared/src/utils/currency/convertCurrencyMicrosToCurrencyAmount.ts
new file mode 100644
index 00000000000..2bebe3c9924
--- /dev/null
+++ b/packages/twenty-shared/src/utils/currency/convertCurrencyMicrosToCurrencyAmount.ts
@@ -0,0 +1,5 @@
+export const convertCurrencyMicrosToCurrencyAmount = (
+ currencyAmountMicros: number,
+) => {
+ return currencyAmountMicros / 1000000;
+};
diff --git a/packages/twenty-shared/src/utils/filter/__tests__/turnRecordFilterIntoGqlOperationFilter.test.ts b/packages/twenty-shared/src/utils/filter/__tests__/turnRecordFilterIntoGqlOperationFilter.test.ts
index 6c78fc7e8fc..8db2569dcd3 100644
--- a/packages/twenty-shared/src/utils/filter/__tests__/turnRecordFilterIntoGqlOperationFilter.test.ts
+++ b/packages/twenty-shared/src/utils/filter/__tests__/turnRecordFilterIntoGqlOperationFilter.test.ts
@@ -801,6 +801,77 @@ describe('turnRecordFilterIntoRecordGqlOperationFilter', () => {
revenue: { amountMicros: { neq: 1000000000 } },
});
});
+
+ it('should convert a decimal amount to integer micros for IS', () => {
+ const result = turnRecordFilterIntoRecordGqlOperationFilter({
+ filterValueDependencies,
+ recordFilter: makeFilter(
+ 'f-currency',
+ RecordFilterOperand.IS,
+ '2.01',
+ 'CURRENCY',
+ 'amountMicros',
+ ),
+ fieldMetadataItemById,
+ });
+
+ expect(result).toEqual({
+ revenue: { amountMicros: { eq: 2010000 } },
+ });
+ });
+
+ it('should convert a decimal amount to integer micros for IS_NOT', () => {
+ const result = turnRecordFilterIntoRecordGqlOperationFilter({
+ filterValueDependencies,
+ recordFilter: makeFilter(
+ 'f-currency',
+ RecordFilterOperand.IS_NOT,
+ '4.03',
+ 'CURRENCY',
+ 'amountMicros',
+ ),
+ fieldMetadataItemById,
+ });
+
+ expect(result).toEqual({
+ revenue: { amountMicros: { neq: 4030000 } },
+ });
+ });
+
+ it('should convert a decimal amount to integer micros for range operands', () => {
+ const lessThanOrEqualResult =
+ turnRecordFilterIntoRecordGqlOperationFilter({
+ filterValueDependencies,
+ recordFilter: makeFilter(
+ 'f-currency',
+ RecordFilterOperand.LESS_THAN_OR_EQUAL,
+ '2.01',
+ 'CURRENCY',
+ 'amountMicros',
+ ),
+ fieldMetadataItemById,
+ });
+
+ const greaterThanOrEqualResult =
+ turnRecordFilterIntoRecordGqlOperationFilter({
+ filterValueDependencies,
+ recordFilter: makeFilter(
+ 'f-currency',
+ RecordFilterOperand.GREATER_THAN_OR_EQUAL,
+ '4.03',
+ 'CURRENCY',
+ 'amountMicros',
+ ),
+ fieldMetadataItemById,
+ });
+
+ expect(lessThanOrEqualResult).toEqual({
+ revenue: { amountMicros: { lte: 2010000 } },
+ });
+ expect(greaterThanOrEqualResult).toEqual({
+ revenue: { amountMicros: { gte: 4030000 } },
+ });
+ });
});
describe('FULL_NAME filter', () => {
diff --git a/packages/twenty-shared/src/utils/filter/turnRecordFilterIntoGqlOperationFilter.ts b/packages/twenty-shared/src/utils/filter/turnRecordFilterIntoGqlOperationFilter.ts
index cdab80e2a91..0da8e075d1f 100644
--- a/packages/twenty-shared/src/utils/filter/turnRecordFilterIntoGqlOperationFilter.ts
+++ b/packages/twenty-shared/src/utils/filter/turnRecordFilterIntoGqlOperationFilter.ts
@@ -52,6 +52,7 @@ import {
resolveRelativeDateFilterStringified,
type RecordFilter,
} from '@/utils';
+import { convertCurrencyAmountToCurrencyMicros } from '@/utils/currency/convertCurrencyAmountToCurrencyMicros';
import { arrayOfStringsOrVariablesSchema } from '@/utils/filter/utils/validation-schemas/arrayOfStringsOrVariablesSchema';
import {
actorSourceFilterValueSchema,
@@ -804,7 +805,9 @@ const buildDirectFieldGqlOperationFilter = ({
return {
[fieldMetadataItem.name]: {
amountMicros: {
- gte: parseNumericFilterValue(recordFilter.value) * 1000000,
+ gte: convertCurrencyAmountToCurrencyMicros(
+ parseNumericFilterValue(recordFilter.value),
+ ),
},
} as CurrencyFilter,
};
@@ -812,7 +815,9 @@ const buildDirectFieldGqlOperationFilter = ({
return {
[fieldMetadataItem.name]: {
amountMicros: {
- lte: parseNumericFilterValue(recordFilter.value) * 1000000,
+ lte: convertCurrencyAmountToCurrencyMicros(
+ parseNumericFilterValue(recordFilter.value),
+ ),
},
} as CurrencyFilter,
};
@@ -820,7 +825,9 @@ const buildDirectFieldGqlOperationFilter = ({
return {
[fieldMetadataItem.name]: {
amountMicros: {
- eq: parseNumericFilterValue(recordFilter.value) * 1000000,
+ eq: convertCurrencyAmountToCurrencyMicros(
+ parseNumericFilterValue(recordFilter.value),
+ ),
},
} as CurrencyFilter,
};
@@ -828,7 +835,9 @@ const buildDirectFieldGqlOperationFilter = ({
return {
[fieldMetadataItem.name]: {
amountMicros: {
- neq: parseNumericFilterValue(recordFilter.value) * 1000000,
+ neq: convertCurrencyAmountToCurrencyMicros(
+ parseNumericFilterValue(recordFilter.value),
+ ),
},
} as CurrencyFilter,
};
diff --git a/packages/twenty-shared/src/utils/index.ts b/packages/twenty-shared/src/utils/index.ts
index 4d58aa937f6..735a9f2e3fa 100644
--- a/packages/twenty-shared/src/utils/index.ts
+++ b/packages/twenty-shared/src/utils/index.ts
@@ -32,6 +32,8 @@ export { safeGetNestedProperty } from './command-menu-items/safeGetNestedPropert
export { computeDiffBetweenObjects } from './compute-diff-between-objects';
export { formatValueForCSV } from './csv/formatValueForCSV';
export { sanitizeValueForCSVExport } from './csv/sanitizeValueForCSVExport';
+export { convertCurrencyAmountToCurrencyMicros } from './currency/convertCurrencyAmountToCurrencyMicros';
+export { convertCurrencyMicrosToCurrencyAmount } from './currency/convertCurrencyMicrosToCurrencyAmount';
export {
NON_ISO_DATE_FORMATS,
ACCEPTED_DATE_FORMATS,