diff --git a/src/CONST.ts b/src/CONST.ts index c7f6f12a0419..4ca9b45f13df 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -2186,7 +2186,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/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 db4fa4d417f6..8f8bba8e916f 100644 --- a/src/libs/actions/Policy/Policy.ts +++ b/src/libs/actions/Policy/Policy.ts @@ -4160,9 +4160,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; } @@ -4238,17 +4239,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, @@ -4274,7 +4266,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, }, @@ -4367,7 +4359,7 @@ function setPolicyAutoReimbursementLimit(policyID: string, limit: string) { ]; const parameters: SetPolicyAutoReimbursementLimitParams = { - autoReimbursement: {limit: parsedLimit}, + limit: parsedLimit, policyID, }; @@ -4380,6 +4372,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 */ @@ -4390,16 +4383,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, @@ -4424,7 +4409,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, }, diff --git a/src/pages/workspace/rules/ExpenseReportRulesSection.tsx b/src/pages/workspace/rules/ExpenseReportRulesSection.tsx index f719fad11145..6b793e5e4588 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: [ , 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 (