From 0953ba3e08adc6f54dac98ce9c8de58aebeda3c6 Mon Sep 17 00:00:00 2001
From: alberto <alberto@expensify.com>
Date: Mon, 16 Jun 2025 13:49:05 +0200
Subject: [PATCH 1/5] Add helper functions

---
 src/libs/actions/IOU.ts       | 15 +++++++++++++++
 src/types/onyx/Transaction.ts | 10 ++++++++++
 2 files changed, 25 insertions(+)

diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts
index fef8f7f1398d..f15e457e15d2 100644
--- a/src/libs/actions/IOU.ts
+++ b/src/libs/actions/IOU.ts
@@ -1061,6 +1061,21 @@ function setCustomUnitRateID(transactionID: string, customUnitRateID: string | u
     });
 }
 
+/**
+ * Set custom unit rateID for the transaction draft
+ */
+function setCustomUnitRate(transactionID: string, customUnitRate: string | undefined) {
+    const isFakeP2PRate = customUnitRateID === CONST.CUSTOM_UNITS.FAKE_P2P_ID;
+    Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {
+        comment: {
+            customUnit: {
+                customUnitRateID,
+                ...(!isFakeP2PRate && {defaultP2PRate: null}),
+            },
+        },
+    });
+}
+
 /**
  * Revert custom unit of the draft transaction to the original transaction's value
  */
diff --git a/src/types/onyx/Transaction.ts b/src/types/onyx/Transaction.ts
index 75983b0ef1fa..c3660dcfb0ba 100644
--- a/src/types/onyx/Transaction.ts
+++ b/src/types/onyx/Transaction.ts
@@ -111,6 +111,16 @@ type TransactionCustomUnit = {
     /** ID of the custom unit rate */
     customUnitRateID?: string;
 
+    /** Full Rate of the custom unit */
+    customUnitRate?: Array<{
+
+        /** ID of the custom unit sub rate */
+        id: string;
+
+        /** Custom unit name */
+        name: string;
+    }>;
+
     /** Custom unit amount */
     quantity?: number | null;
 

From f8faf8bd67b765c7765205a47c3f89e2e1f07896 Mon Sep 17 00:00:00 2001
From: alberto <alberto@expensify.com>
Date: Mon, 16 Jun 2025 13:59:15 +0200
Subject: [PATCH 2/5] pass new param

---
 src/libs/PolicyUtils.ts |  9 +++++++++
 src/libs/actions/IOU.ts | 25 +++++++++----------------
 2 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts
index 69a6c43fba82..d578f31469fe 100644
--- a/src/libs/PolicyUtils.ts
+++ b/src/libs/PolicyUtils.ts
@@ -192,6 +192,14 @@ function getDistanceRateCustomUnitRate(policy: OnyxEntry<Policy>, customUnitRate
     return distanceUnit?.rates[customUnitRateID];
 }
 
+/**
+ * Retrieves custom unit rate object from the given customUnitRateID
+ */
+function getPerDiemRateCustomUnitRate(policy: OnyxEntry<Policy>, customUnitRateID: string): Rate | undefined {
+    const perDiemUnit = getPerDiemCustomUnit(policy);
+    return perDiemUnit?.rates[customUnitRateID];
+}
+
 function getRateDisplayValue(value: number, toLocaleDigit: (arg: string) => string, withDecimals?: boolean): string {
     const numValue = getNumericValue(value, toLocaleDigit);
     if (Number.isNaN(numValue)) {
@@ -1508,6 +1516,7 @@ export {
     getDistanceRateCustomUnit,
     getPerDiemCustomUnit,
     getDistanceRateCustomUnitRate,
+    getPerDiemRateCustomUnitRate,
     sortWorkspacesBySelected,
     removePendingFieldsFromCustomUnit,
     goBackWhenEnableFeature,
diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts
index f15e457e15d2..f526b838e38a 100644
--- a/src/libs/actions/IOU.ts
+++ b/src/libs/actions/IOU.ts
@@ -65,7 +65,7 @@ import {addSMSDomainIfPhoneNumber} from '@libs/PhoneNumber';
 import {
     getCorrectedAutoReportingFrequency,
     getMemberAccountIDsForWorkspace,
-    getPerDiemCustomUnit,
+    getPerDiemCustomUnit, getPerDiemRateCustomUnitRate,
     getPersonalPolicy,
     getPolicy,
     getSubmitToAccountID,
@@ -1061,21 +1061,6 @@ function setCustomUnitRateID(transactionID: string, customUnitRateID: string | u
     });
 }
 
-/**
- * Set custom unit rateID for the transaction draft
- */
-function setCustomUnitRate(transactionID: string, customUnitRate: string | undefined) {
-    const isFakeP2PRate = customUnitRateID === CONST.CUSTOM_UNITS.FAKE_P2P_ID;
-    Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {
-        comment: {
-            customUnit: {
-                customUnitRateID,
-                ...(!isFakeP2PRate && {defaultP2PRate: null}),
-            },
-        },
-    });
-}
-
 /**
  * Revert custom unit of the draft transaction to the original transaction's value
  */
@@ -5369,10 +5354,18 @@ function submitPerDiemExpense(submitPerDiemExpenseInformation: PerDiemExpenseInf
     });
     const activeReportID = isMoneyRequestReport ? report?.reportID : chatReport.reportID;
 
+    const customUnitRate = getPerDiemRateCustomUnitRate(policyParams.policy, customUnit.customUnitRateID);
+
+    const customUnitRateParam = {
+        id: customUnitRate?.customUnitRateID,
+        name: customUnitRate?.name,
+    };
+
     const parameters: CreatePerDiemRequestParams = {
         policyID: policyParams.policy.id,
         customUnitID: customUnit.customUnitID,
         customUnitRateID: customUnit.customUnitRateID,
+        customUnitRate: customUnitRateParam,
         subRates: JSON.stringify(customUnit.subRates),
         startDateTime: customUnit.attributes.dates.start,
         endDateTime: customUnit.attributes.dates.end,

From b9e71dcdb163fca949d8c7eaee03acb84b04e009 Mon Sep 17 00:00:00 2001
From: alberto <alberto@expensify.com>
Date: Mon, 16 Jun 2025 17:11:54 +0200
Subject: [PATCH 3/5] Add to type

---
 src/libs/API/parameters/CreatePerDiemRequestParams.ts | 1 +
 src/libs/actions/IOU.ts                               | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/libs/API/parameters/CreatePerDiemRequestParams.ts b/src/libs/API/parameters/CreatePerDiemRequestParams.ts
index 480acd9ca23d..d1981c5f3123 100644
--- a/src/libs/API/parameters/CreatePerDiemRequestParams.ts
+++ b/src/libs/API/parameters/CreatePerDiemRequestParams.ts
@@ -2,6 +2,7 @@ type CreatePerDiemRequestParams = {
     policyID: string;
     created: string;
     customUnitID: string;
+    customUnitRate: string;
     customUnitRateID: string;
     subRates: string;
     currency: string;
diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts
index f526b838e38a..fe21a8581f93 100644
--- a/src/libs/actions/IOU.ts
+++ b/src/libs/actions/IOU.ts
@@ -5365,7 +5365,7 @@ function submitPerDiemExpense(submitPerDiemExpenseInformation: PerDiemExpenseInf
         policyID: policyParams.policy.id,
         customUnitID: customUnit.customUnitID,
         customUnitRateID: customUnit.customUnitRateID,
-        customUnitRate: customUnitRateParam,
+        customUnitRate: JSON.stringify(customUnitRateParam),
         subRates: JSON.stringify(customUnit.subRates),
         startDateTime: customUnit.attributes.dates.start,
         endDateTime: customUnit.attributes.dates.end,

From 16cc16cdc64f576fd96d51e9f2a44bc27072c513 Mon Sep 17 00:00:00 2001
From: alberto <alberto@expensify.com>
Date: Mon, 16 Jun 2025 17:21:07 +0200
Subject: [PATCH 4/5] prettier

---
 src/libs/actions/IOU.ts       | 3 ++-
 src/types/onyx/Transaction.ts | 1 -
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts
index fe21a8581f93..5e60de9bf4b4 100644
--- a/src/libs/actions/IOU.ts
+++ b/src/libs/actions/IOU.ts
@@ -65,7 +65,8 @@ import {addSMSDomainIfPhoneNumber} from '@libs/PhoneNumber';
 import {
     getCorrectedAutoReportingFrequency,
     getMemberAccountIDsForWorkspace,
-    getPerDiemCustomUnit, getPerDiemRateCustomUnitRate,
+    getPerDiemCustomUnit,
+    getPerDiemRateCustomUnitRate,
     getPersonalPolicy,
     getPolicy,
     getSubmitToAccountID,
diff --git a/src/types/onyx/Transaction.ts b/src/types/onyx/Transaction.ts
index c3660dcfb0ba..2d7d394e8bbb 100644
--- a/src/types/onyx/Transaction.ts
+++ b/src/types/onyx/Transaction.ts
@@ -113,7 +113,6 @@ type TransactionCustomUnit = {
 
     /** Full Rate of the custom unit */
     customUnitRate?: Array<{
-
         /** ID of the custom unit sub rate */
         id: string;
 

From e60a508de019918797e5999db48b80b9743b2b2e Mon Sep 17 00:00:00 2001
From: alberto <alberto@expensify.com>
Date: Mon, 16 Jun 2025 17:22:23 +0200
Subject: [PATCH 5/5] remove uneeded type

---
 src/types/onyx/Transaction.ts | 9 ---------
 1 file changed, 9 deletions(-)

diff --git a/src/types/onyx/Transaction.ts b/src/types/onyx/Transaction.ts
index 2d7d394e8bbb..75983b0ef1fa 100644
--- a/src/types/onyx/Transaction.ts
+++ b/src/types/onyx/Transaction.ts
@@ -111,15 +111,6 @@ type TransactionCustomUnit = {
     /** ID of the custom unit rate */
     customUnitRateID?: string;
 
-    /** Full Rate of the custom unit */
-    customUnitRate?: Array<{
-        /** ID of the custom unit sub rate */
-        id: string;
-
-        /** Custom unit name */
-        name: string;
-    }>;
-
     /** Custom unit amount */
     quantity?: number | null;
 
