From f5d39d8f3a1e3a9a632a4fbee9471a06586c1846 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Mon, 16 Sep 2024 14:01:18 -1000 Subject: [PATCH 1/4] Use float instead of int for auditRate percentage --- src/CONST.ts | 2 +- src/libs/actions/Policy/Policy.ts | 5 +++-- src/pages/workspace/rules/ExpenseReportRulesSection.tsx | 2 +- src/pages/workspace/rules/RulesRandomReportAuditPage.tsx | 3 +-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index ead9a9eda8ee..20eab24cf856 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -2173,7 +2173,7 @@ const CONST = { AUTO_REIMBURSEMENT_MAX_LIMIT_CENTS: 2000000, AUTO_REIMBURSEMENT_DEFAULT_LIMIT_CENTS: 10000, AUTO_APPROVE_REPORTS_UNDER_DEFAULT_CENTS: 10000, - RANDOM_AUDIT_DEFAULT_PERCENTAGE: 5, + RANDOM_AUDIT_DEFAULT_PERCENTAGE: 0.05, AUTO_REPORTING_FREQUENCIES: { INSTANT: 'instant', diff --git a/src/libs/actions/Policy/Policy.ts b/src/libs/actions/Policy/Policy.ts index e30ddaf97e1f..18f5a3495304 100644 --- a/src/libs/actions/Policy/Policy.ts +++ b/src/libs/actions/Policy/Policy.ts @@ -4248,9 +4248,10 @@ function setPolicyAutomaticApprovalLimit(policyID: string, limit: string) { function setPolicyAutomaticApprovalRate(policyID: string, auditRate: string) { const policy = getPolicy(policyID); const fallbackAuditRate = auditRate === '' ? '0' : auditRate; - const parsedAuditRate = parseInt(fallbackAuditRate, 10); + const parsedAuditRate = parseInt(fallbackAuditRate, 10) / 100; - if (parsedAuditRate === policy?.autoApproval?.auditRate ?? CONST.POLICY.RANDOM_AUDIT_DEFAULT_PERCENTAGE) { + // The auditRate arrives as an int to this method so we will convert it to a float before sending it to the API. + if (parsedAuditRate === (policy?.autoApproval?.auditRate ?? CONST.POLICY.RANDOM_AUDIT_DEFAULT_PERCENTAGE)) { return; } diff --git a/src/pages/workspace/rules/ExpenseReportRulesSection.tsx b/src/pages/workspace/rules/ExpenseReportRulesSection.tsx index 71fdc0a29eeb..d4d51eaeaeeb 100644 --- a/src/pages/workspace/rules/ExpenseReportRulesSection.tsx +++ b/src/pages/workspace/rules/ExpenseReportRulesSection.tsx @@ -133,7 +133,7 @@ function ExpenseReportRulesSection({policyID}: ExpenseReportRulesSectionProps) { Navigation.navigate(ROUTES.RULES_RANDOM_REPORT_AUDIT.getRoute(policyID))} diff --git a/src/pages/workspace/rules/RulesRandomReportAuditPage.tsx b/src/pages/workspace/rules/RulesRandomReportAuditPage.tsx index b127063251d3..ad5e24191ce9 100644 --- a/src/pages/workspace/rules/RulesRandomReportAuditPage.tsx +++ b/src/pages/workspace/rules/RulesRandomReportAuditPage.tsx @@ -32,8 +32,7 @@ function RulesRandomReportAuditPage({route}: RulesRandomReportAuditPageProps) { const styles = useThemeStyles(); const workflowApprovalsUnavailable = PolicyUtils.getWorkflowApprovalsUnavailable(policy); - const defaultValue = policy?.autoApproval?.auditRate ?? CONST.POLICY.RANDOM_AUDIT_DEFAULT_PERCENTAGE; - + const defaultValue = Math.round((policy?.autoApproval?.auditRate ?? CONST.POLICY.RANDOM_AUDIT_DEFAULT_PERCENTAGE) * 100); return ( Date: Mon, 16 Sep 2024 16:08:57 -1000 Subject: [PATCH 2/4] Simplify logic for autoReimbursement --- src/libs/actions/Policy/Policy.ts | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/src/libs/actions/Policy/Policy.ts b/src/libs/actions/Policy/Policy.ts index 18f5a3495304..04c8e76f2d07 100644 --- a/src/libs/actions/Policy/Policy.ts +++ b/src/libs/actions/Policy/Policy.ts @@ -4327,17 +4327,8 @@ function enableAutoApprovalOptions(policyID: string, enabled: boolean) { return; } - const autoApprovalCleanupValues = !enabled - ? { - pendingFields: { - limit: null, - auditRate: null, - }, - } - : {}; - const autoApprovalValues = !enabled ? {auditRate: CONST.POLICY.RANDOM_AUDIT_DEFAULT_PERCENTAGE, limit: CONST.POLICY.AUTO_APPROVE_REPORTS_UNDER_DEFAULT_CENTS} : {}; - const autoApprovalFailureValues = !enabled ? {autoApproval: {limit: policy?.autoApproval?.limit, auditRate: policy?.autoApproval?.auditRate, ...autoApprovalCleanupValues}} : {}; - + const autoApprovalValues = {auditRate: CONST.POLICY.RANDOM_AUDIT_DEFAULT_PERCENTAGE, limit: CONST.POLICY.AUTO_APPROVE_REPORTS_UNDER_DEFAULT_CENTS}; + const autoApprovalFailureValues = {autoApproval: {limit: policy?.autoApproval?.limit, auditRate: policy?.autoApproval?.auditRate, pendingFields: null}}; const optimisticData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -4363,7 +4354,7 @@ function enableAutoApprovalOptions(policyID: string, enabled: boolean) { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { - autoApproval: {...autoApprovalCleanupValues}, + autoApproval: {pendingFields: null}, pendingFields: { shouldShowAutoApprovalOptions: null, }, @@ -4469,6 +4460,7 @@ function setPolicyAutoReimbursementLimit(policyID: string, limit: string) { /** * Call the API to enable auto-payment for the reports in the given policy + * * @param policyID - id of the policy to apply the limit to * @param enabled - whether auto-payment for the reports is enabled in the given policy */ @@ -4479,16 +4471,8 @@ function enablePolicyAutoReimbursementLimit(policyID: string, enabled: boolean) return; } - const autoReimbursementCleanupValues = !enabled - ? { - pendingFields: { - limit: null, - }, - } - : {}; - const autoReimbursementFailureValues = !enabled ? {autoReimbursement: {limit: policy?.autoReimbursement?.limit, ...autoReimbursementCleanupValues}} : {}; - const autoReimbursementValues = !enabled ? {limit: CONST.POLICY.AUTO_REIMBURSEMENT_DEFAULT_LIMIT_CENTS} : {}; - + const autoReimbursementFailureValues = {autoReimbursement: {limit: policy?.autoReimbursement?.limit, pendingFields: null}}; + const autoReimbursementValues = {limit: CONST.POLICY.AUTO_REIMBURSEMENT_DEFAULT_LIMIT_CENTS}; const optimisticData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -4513,7 +4497,7 @@ function enablePolicyAutoReimbursementLimit(policyID: string, enabled: boolean) onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { - autoReimbursement: {...autoReimbursementCleanupValues}, + autoReimbursement: {pendingFields: null}, pendingFields: { shouldShowAutoReimbursementLimitOption: null, }, From f527d62b2927e9d08bf1d87355c592ffe43679da Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Tue, 17 Sep 2024 17:12:41 -1000 Subject: [PATCH 3/4] Fix the params for SetPolicyAutoReimbursementLimit as they are incorrect --- src/libs/API/parameters/SetPolicyAutoReimbursementLimit.ts | 2 +- src/libs/actions/Policy/Policy.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/API/parameters/SetPolicyAutoReimbursementLimit.ts b/src/libs/API/parameters/SetPolicyAutoReimbursementLimit.ts index 7c6a721e03b0..b743369db926 100644 --- a/src/libs/API/parameters/SetPolicyAutoReimbursementLimit.ts +++ b/src/libs/API/parameters/SetPolicyAutoReimbursementLimit.ts @@ -1,6 +1,6 @@ type SetPolicyAutoReimbursementLimitParams = { policyID: string; - autoReimbursement: {limit: number}; + limit: number; }; export default SetPolicyAutoReimbursementLimitParams; diff --git a/src/libs/actions/Policy/Policy.ts b/src/libs/actions/Policy/Policy.ts index 04c8e76f2d07..042e5f9ad0ad 100644 --- a/src/libs/actions/Policy/Policy.ts +++ b/src/libs/actions/Policy/Policy.ts @@ -4447,7 +4447,7 @@ function setPolicyAutoReimbursementLimit(policyID: string, limit: string) { ]; const parameters: SetPolicyAutoReimbursementLimitParams = { - autoReimbursement: {limit: parsedLimit}, + limit: parsedLimit, policyID, }; From 6f58877aacf7702f1a7b5b7e8bb1948fc3672966 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Thu, 26 Sep 2024 10:13:10 -1000 Subject: [PATCH 4/4] Fix expected missing field in ExpenseReportRulesSection --- .../workspace/rules/ExpenseReportRulesSection.tsx | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/pages/workspace/rules/ExpenseReportRulesSection.tsx b/src/pages/workspace/rules/ExpenseReportRulesSection.tsx index 9f2f3d7a80e3..88b5b71cecfd 100644 --- a/src/pages/workspace/rules/ExpenseReportRulesSection.tsx +++ b/src/pages/workspace/rules/ExpenseReportRulesSection.tsx @@ -48,6 +48,7 @@ function ExpenseReportRulesSection({policyID}: ExpenseReportRulesSectionProps) { ); }; + const reportTitlePendingFields = policy?.fieldList?.[CONST.POLICY.FIELDS.FIELD_LIST_TITLE]?.pendingFields ?? {}; const optionItems = [ { title: translate('workspace.rules.expenseReportRules.customReportNamesTitle'), @@ -62,11 +63,7 @@ function ExpenseReportRulesSection({policyID}: ExpenseReportRulesSectionProps) { onToggle: (isEnabled: boolean) => PolicyActions.enablePolicyDefaultReportTitle(policyID, isEnabled), subMenuItems: [ ,