-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Update getSubmitToAccountID with category and tag approver #51196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2af0515
c93c19d
7d36a2b
3682b9f
7b22022
bf5d6f5
2de4fee
b75c056
de7e6a6
cbaee21
4dbb1a4
9a789f3
62c0db1
4faba7f
0e6c35a
e2c5d24
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ import CONST from '@src/CONST'; | |
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import ROUTES from '@src/ROUTES'; | ||
| import INPUT_IDS from '@src/types/form/NetSuiteCustomFieldForm'; | ||
| import type {OnyxInputOrEntry, Policy, PolicyCategories, PolicyEmployeeList, PolicyTagLists, PolicyTags, TaxRate} from '@src/types/onyx'; | ||
| import type {OnyxInputOrEntry, Policy, PolicyCategories, PolicyEmployeeList, PolicyTagLists, PolicyTags, Report, TaxRate} from '@src/types/onyx'; | ||
| import type {CardFeedData} from '@src/types/onyx/CardFeeds'; | ||
| import type {ErrorFields, PendingAction, PendingFields} from '@src/types/onyx/OnyxCommon'; | ||
| import type { | ||
|
|
@@ -31,10 +31,12 @@ import type { | |
| import type PolicyEmployee from '@src/types/onyx/PolicyEmployee'; | ||
| import {isEmptyObject} from '@src/types/utils/EmptyObject'; | ||
| import {hasSynchronizationErrorMessage} from './actions/connections'; | ||
| import {getCategoryApproverRule} from './CategoryUtils'; | ||
| import * as Localize from './Localize'; | ||
| import Navigation from './Navigation/Navigation'; | ||
| import * as NetworkStore from './Network/NetworkStore'; | ||
| import {getAccountIDsByLogins, getLoginsByAccountIDs, getPersonalDetailByEmail} from './PersonalDetailsUtils'; | ||
| import {getAllReportTransactions, getCategory, getTag} from './TransactionUtils'; | ||
|
|
||
| type MemberEmailsToAccountIDs = Record<string, number>; | ||
|
|
||
|
|
@@ -526,12 +528,37 @@ function getDefaultApprover(policy: OnyxEntry<Policy>): string { | |
| } | ||
|
|
||
| /** | ||
| * Returns the accountID to whom the given employeeAccountID submits reports to in the given Policy. | ||
| * Returns the accountID to whom the given expenseReport submits reports to in the given Policy. | ||
| */ | ||
| function getSubmitToAccountID(policy: OnyxEntry<Policy>, employeeAccountID: number): number { | ||
| function getSubmitToAccountID(policy: OnyxEntry<Policy>, expenseReport: OnyxEntry<Report>): number { | ||
|
Beamanator marked this conversation as resolved.
|
||
| const employeeAccountID = expenseReport?.ownerAccountID ?? -1; | ||
| const employeeLogin = getLoginsByAccountIDs([employeeAccountID]).at(0) ?? ''; | ||
| const defaultApprover = getDefaultApprover(policy); | ||
|
Beamanator marked this conversation as resolved.
|
||
|
|
||
| let categoryAppover; | ||
| let tagApprover; | ||
| const allTransactions = getAllReportTransactions(expenseReport?.reportID).sort((transA, transB) => (transA.created < transB.created ? -1 : 1)); | ||
|
|
||
| // Before submitting to their `submitsTo` (in a policy on Advanced Approvals), submit to category/tag approvers. | ||
| // Category approvers are prioritized, then tag approvers. | ||
| for (let i = 0; i < allTransactions.length; i++) { | ||
|
nkdengineer marked this conversation as resolved.
|
||
| const transaction = allTransactions.at(i); | ||
| const tag = getTag(transaction); | ||
| const category = getCategory(transaction); | ||
| categoryAppover = getCategoryApproverRule(policy?.rules?.approvalRules ?? [], category)?.approver; | ||
| if (categoryAppover) { | ||
| return getAccountIDsByLogins([categoryAppover]).at(0) ?? -1; | ||
| } | ||
|
|
||
| if (!tagApprover && getTagApproverRule(policy?.id ?? '-1', tag)?.approver) { | ||
| tagApprover = getTagApproverRule(policy?.id ?? '-1', tag)?.approver; | ||
| } | ||
| } | ||
|
|
||
| if (tagApprover) { | ||
| return getAccountIDsByLogins([tagApprover]).at(0) ?? -1; | ||
| } | ||
|
|
||
| // For policy using the optional or basic workflow, the manager is the policy default approver. | ||
| if (([CONST.POLICY.APPROVAL_MODE.OPTIONAL, CONST.POLICY.APPROVAL_MODE.BASIC] as Array<ValueOf<typeof CONST.POLICY.APPROVAL_MODE>>).includes(getApprovalWorkflow(policy))) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. aah I was looking for this! @nkdengineer - shouldn't we move this up above the new logic since none of the loops
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Beamanator When I tested by adding the category/tag rules and didn't upgrade to advanced-approval, the category/tag rules is still applied.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's great! But still isn't it better to return early via this check BEFORE looping through transactions? Not fixing a bug, but more efficient to return early
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Beamanator I mean that the category/tag rule should still apply for non-advanced-approval policies. If we move this after this condition, the error appears when we submit the report of non-advanced-approval policies that has transaction match category/tag approver rule.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh hmmmm i assumed category/tag approvals were only supported w/ Advanced approval settings, do you know if that's incorrect @garrettmknight ?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok so I guessed wrong 😅 You're right @nkdengineer - category/tag rule approvers should still apply for non-advanced-approval Control policies |
||
| return getAccountIDsByLogins([defaultApprover]).at(0) ?? -1; | ||
|
|
@@ -545,8 +572,8 @@ function getSubmitToAccountID(policy: OnyxEntry<Policy>, employeeAccountID: numb | |
| return getAccountIDsByLogins([employee.submitsTo ?? defaultApprover]).at(0) ?? -1; | ||
| } | ||
|
|
||
| function getSubmitToEmail(policy: OnyxEntry<Policy>, employeeAccountID: number): string { | ||
| const submitToAccountID = getSubmitToAccountID(policy, employeeAccountID); | ||
| function getSubmitToEmail(policy: OnyxEntry<Policy>, expenseReport: OnyxEntry<Report>): string { | ||
| const submitToAccountID = getSubmitToAccountID(policy, expenseReport); | ||
| return getLoginsByAccountIDs([submitToAccountID]).at(0) ?? ''; | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.