Skip to content

The open alternative to Salesforce, designed for AI.

fix(front): preserve null currency amountMicros in CSV export (#26929)

Pranav Ganorkara048ce4281f4
diff --git a/packages/twenty-front/src/modules/object-record/object-options-dropdown/hooks/__tests__/useExportProcessRecordsForCSV.test.ts b/packages/twenty-front/src/modules/object-record/object-options-dropdown/hooks/__tests__/useExportProcessRecordsForCSV.test.ts
index 205b295b6a9..ca226858ad5 100644
--- a/packages/twenty-front/src/modules/object-record/object-options-dropdown/hooks/__tests__/useExportProcessRecordsForCSV.test.ts
+++ b/packages/twenty-front/src/modules/object-record/object-options-dropdown/hooks/__tests__/useExportProcessRecordsForCSV.test.ts
@@ -136,4 +136,58 @@ describe('useExportProcessRecordsForCSV', () => {
},
]);
});
+
+ it('preserves null or undefined amountMicros for currency fields instead of converting to 0', () => {
+ const { result } = renderHook(() =>
+ useExportProcessRecordsForCSV('someObject'),
+ );
+
+ const records = [
+ {
+ __typename: 'ObjectRecord',
+ id: '1',
+ price: { amountMicros: null, currencyCode: 'USD' },
+ name: 'Empty amount',
+ },
+ {
+ __typename: 'ObjectRecord',
+ id: '2',
+ price: { amountMicros: undefined, currencyCode: 'EUR' },
+ name: 'Undefined amount',
+ },
+ {
+ __typename: 'ObjectRecord',
+ id: '3',
+ price: { amountMicros: 0, currencyCode: 'GBP' },
+ name: 'Zero amount',
+ },
+ ];
+
+ let processedRecords;
+
+ act(() => {
+ processedRecords = result.current.processRecordsForCSVExport(records);
+ });
+
+ expect(processedRecords).toEqual([
+ {
+ __typename: 'ObjectRecord',
+ id: '1',
+ price: { amountMicros: null, currencyCode: 'USD' },
+ name: 'Empty amount',
+ },
+ {
+ __typename: 'ObjectRecord',
+ id: '2',
+ price: { amountMicros: null, currencyCode: 'EUR' },
+ name: 'Undefined amount',
+ },
+ {
+ __typename: 'ObjectRecord',
+ id: '3',
+ price: { amountMicros: 0, currencyCode: 'GBP' },
+ name: 'Zero amount',
+ },
+ ]);
+ });
});
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 9270dd7f673..dcaf777b829 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
@@ -25,9 +25,11 @@ export const useExportProcessRecordsForCSV = (objectNameSingular: string) => {
return {
...processedRecord,
[field.name]: {
- amountMicros: convertCurrencyMicrosToCurrencyAmount(
- record[field.name].amountMicros,
- ),
+ amountMicros: isDefined(record[field.name].amountMicros)
+ ? convertCurrencyMicrosToCurrencyAmount(
+ record[field.name].amountMicros,
+ )
+ : null,
currencyCode: record[field.name].currencyCode,
} satisfies FieldCurrencyValue,
};