App icon indicating copy to clipboard operation
App copied to clipboard

[$175] Invoices - Internal Bill created from a submitted Invoice can't find the domain primary contact's "Submits To" and routes to the primary contact for approval first

Open m-natarajan opened this issue 3 weeks ago • 16 comments

If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.


Version Number: 9.5.27-2 Reproducible in staging?: Needs Reproduction (Reproduction blocked) Reproducible in production?: Needs Reproduction If this was caught during regression testing, add the test name, ID and link from BrowserStack: Email or phone of affected tester (no customers): Logs: https://stackoverflow.com/c/expensify/questions/4856 Expensify/Expensify Issue URL: Issue reported by: @abbagail Slack conversation (hyperlinked to channel name): #Expensify Bugs

Action Performed:

  1. A third party/contractor submits an Invoice to [email protected].
  2. The system automatically creates an internal Bill.
  3. The internal Bill is submitted to the "Submits To" of the domain's primary contact.

Expected Result:

The internal Bill goes straight into the approval process starting at the primary contact's "Submits To". After approval, the primary contact goes to the Invoice and marks it as paid.

Actual Result:

When the internal Bill is created, the system fails to find the primary contact's "Submits To". The Bill instead shows up as an Outstanding Bill for the primary contact to approve. Only after the primary contact approves does it move on to their "Submits To".

This adds an extra approval step by the primary contact that shouldn't exist.

Workaround:

Unknown

Platforms:

Select the officially supported platforms where the issue was reproduced:

  • [ ] Android: App
  • [ ] Android: mWeb Chrome
  • [ ] iOS: App
  • [ ] iOS: mWeb Safari
  • [ ] iOS: mWeb Chrome
  • [x] Windows: Chrome
  • [x] MacOS: Chrome / Safari

Screenshots/Videos

The screenshot for the issue is in Slack thread

View all open jobs on GitHub

Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @AndrewGable

m-natarajan avatar Nov 04 '26 13:11 m-natarajan

🤖 Web test steps verification results: ⚠️ partial

Reproduction blocked on dev NewDot web: this session has no workspaces or configured domains. No invoices were sent and no payments were approved.

Domains empty state with no configured domain
Step Status
Access a domain configured to receive contractor invoices at [email protected]Workspaces displayed “No workspaces yet.” Domains displayed only “Enhance your security with domains” and “New domain,” with no configured domain available.
Domains empty state with no configured domain
❌
Inspect an automatically created internal Bill and its initial approval routingBlocked by the unavailable domain prerequisite; no corresponding internal Bill or approval routing could be inspected. A normal invoice flow was not substituted.
❌

view run

MelvinBot avatar Nov 04 '26 13:11 MelvinBot

⚠️ Preliminary analysis (low confidence) — no routing defect confirmed.

Finding: Primary-contact-first routing matches the documented Bill Pay sequence. Confirm the intended behavior before proposing a fix.

Evidence and alternative explanations

To confirm: Clarify emailed attachment versus native invoice submission. Share the affected bill’s history and workspace approval settings internally. Confirm whether bypassing primary-contact review is intended. If so, escalate bill routing to an internal engineer; an App fix is not justified yet.


Next Steps: Reply with @MelvinBot <your feedback> to refine this analysis.


view run · no recording available

MelvinBot avatar Nov 04 '26 13:11 MelvinBot

Triggered auto assignment to Contributor-plus team member for initial proposal review - @QichenZhu (External)

melvin-bot[bot] avatar Nov 04 '26 13:11 melvin-bot[bot]

Job added to Upwork: https://www.upwork.com/jobs/~022117978554261919880

melvin-bot[bot] avatar Nov 04 '26 13:11 melvin-bot[bot]

Proposal

Please re-state the problem that we are trying to solve in this issue.

An invoice submitted to a domain billing address reportedly generates an internal bill requiring the domain primary contact’s approval before reaching their configured “Submits To” approver. The requested behavior is to begin approval directly with that configured approver.

Triage verdict: insufficient evidence for a defensible implementation proposal. Reproduction remains unconfirmed, and no affected implementation or execution traces were supplied.

What is the root cause of that problem?

The root cause is not established. “Fails to find Submits To” is a hypothesis; the additional approval step does not prove a lookup failure.

There is also a material requirements conflict: Expensify’s official Classic Bill Pay documentation describes initial submission to the domain primary contact, followed by the workspace approval process. This makes intended behavior versus a regression a necessary product clarification. The documentation does not establish whether this particular submitted-invoice conversion should behave differently. Official Bill Pay workflow

The evidence does not distinguish between:

  • A missing approver configuration in the workspace actually selected for the bill.
  • Incorrect identity or workspace selection during conversion.
  • Incorrect persisted approval routing.
  • Correct persisted routing displayed incorrectly by the client.
  • An intentional initial review step.

No verified defective file or line number is available. Source retrieval at 9.5.27-2 failed, and the private logs and screenshot were not available for inspection. Assigning this to a particular TypeScript function—or conclusively to the backend—would be speculation.

What changes do you think we should make in order to solve the problem?

No TypeScript diff is justified yet. Inventing paths, line numbers, fields, or routing mutations would fail the required evidence standard.

The minimum investigation needed to produce a surgical patch is:

  1. Reproduce with controlled accounts: contractor, domain primary contact P, and configured approver A, where P ≠ A.
  2. Record the selected workspace, its approval mode, and P’s effective “Submits To” configuration before submission.
  3. Capture the generated bill’s persisted owner, current approver, status, and approval history immediately after creation and after P approves.
  4. Compare persisted data with the displayed approval action to locate the defect.
  5. Confirm that this conversion is intended to bypass P’s initial review.

If persisted routing is wrong, fix the conversion or submission code that writes it. If persistence is correct, fix the specific client derivation that misrepresents it. Preserve invoice payment ownership separately from bill approval routing.

Expensify’s contribution rules require reproduction and access to the affected repository before a solution proposal can be accepted. Contribution requirements

What alternative solutions did you explore? (Optional)

No MelvinBot proposal was supplied, so there is no substantiated counterproposal to dismantle.

Reject these unsupported approaches:

  • Hide P’s Approve button: leaves incorrect persisted routing unresolved.
  • Automatically approve as P: records an approval that P did not perform.
  • Globally skip primary contacts: could remove legitimate approval steps from unrelated workflows.
  • Change an optimistic client value alone: cannot establish that automatic bill creation persists the correct route.

Existing proposals, fixes, and duplicate issues were not verified; originality cannot be claimed.

What automated tests can you add to prevent this from re-occurring?

Once the responsible implementation and intended behavior are confirmed, add a regression test at the layer that creates and routes the bill.

Proposed case: routes an invoice-generated bill directly to the primary contact's configured approver.

  • Arrange P and distinct approver A in the selected workspace.
  • Execute the actual invoice-to-bill conversion.
  • Assert that the persisted first approver is A.
  • Assert that no approval by P was recorded.
  • Assert that invoice payment permissions remain correct.
  • Assert that A’s approval follows the remaining configured workflow.

Also cover missing approver configuration, workspace-specific configuration, and configurations where P legitimately belongs in the approval chain. Their expected outcomes must follow confirmed product rules.

A Jest test that mocks the conversion response with an already-correct approver would not test the suspected routing defect. A server-owned conversion requires a server integration test; Jest can additionally verify client rendering.

Validation status: no reproduction, patch, or automated test was executed. An executable test file and exact diff cannot honestly be supplied from the available evidence.

Contributor details
Your Expensify account email: [email protected]
Upwork Profile Link: https://www.upwork.com/freelancers/~01b60d704ba377be83

camesenin avatar Nov 04 '26 18:11 camesenin

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Nov 04 '26 18:11 melvin-bot[bot]

📣 @ronanchnlps-bit! 📣 Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork. Please follow these steps:

  1. Make sure you've read and understood the contributing guidelines.
  2. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
  3. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
  4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details. Screen Shot 2022-11-16 at 4 42 54 PM Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>

melvin-bot[bot] avatar Nov 07 '26 10:11 melvin-bot[bot]

Proposal

Please re-state the problem that we are trying to solve in this issue.

When a workspace has an approval workflow where the domain's primary contact (technicalContactEmail / workspace owner) is configured to submit to another admin (Submits To: Admin B), and a vendor sends an Invoice to that domain ([email protected]), the internal Bill created in the receiver's workspace fails to route directly to Admin B. Instead, it routes to the domain's primary contact as an Outstanding Bill first, and only forwards to Admin B after the primary contact approves it.

What is the root cause of that problem?

There are two bugs in the approval workflow and employeeList lookup logic that cause the primary contact's submitsTo target to be lost or missed:

  1. updateApprovalWorkflow overwrites the default approver's custom submitsTo with self-submission (src/libs/actions/Workflow.ts, lines 179–194): In src/libs/actions/Workflow.ts (lines 179–194), whenever the Default Workflow is created or updated (or when another workflow is saved while the primary contact is the Default Workflow's first approver, i.e. newDefaultApprover), updateApprovalWorkflow runs a backstop check on updatedEmployees[newDefaultApprover]:

    if (newDefaultApprover) {
        const existing = updatedEmployees[newDefaultApprover] ?? previousEmployeeList[newDefaultApprover];
        if (!existing || existing.submitsTo !== newDefaultApprover) {
            updatedEmployees[newDefaultApprover] = {
                ...existing,
                email: newDefaultApprover,
                submitsTo: newDefaultApprover,
                pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
            };
            ...
        }
    }
    
    • When the primary contact (newDefaultApprover) has their own custom approval workflow (submitsTo: managerEmail), they are not in the Default Workflow's approvalWorkflow.members.
    • If the Default Workflow has a second-stage approver (forwardsTo: managerEmail), convertApprovalWorkflowToPolicyEmployees creates updatedEmployees[newDefaultApprover] with forwardsTo: managerEmail and submitsTo: undefined.
    • Even if existing falls back to previousEmployeeList[newDefaultApprover] (where existing.submitsTo === managerEmail), the condition existing.submitsTo !== newDefaultApprover evaluates to true!
    • As a result, updateApprovalWorkflow unconditionally overwrites updatedEmployees[newDefaultApprover].submitsTo to newDefaultApprover (self-submission) while keeping forwardsTo: managerEmail. When an Invoice is received and converted into an internal Bill owned by the primary contact, the primary contact's submitsTo is now themselves (newDefaultApprover), so the Bill routes to the primary contact first and only routes to forwardsTo after they approve.
  2. Case-sensitive policy.employeeList lookups in src/libs/PolicyUtils/approvals.ts (lines 325, 366, 399, and 432): In getApprovalWorkflow (line 325), getManagerAccountID (line 366), getManagerAccountEmail (line 399), and getReportApproverAccountID (line 432), policy.employeeList is indexed directly with the raw ownerLogin / submitterLogin (policy?.employeeList?.[ownerLogin ?? '']). However, policy.employeeList keys are normalized to lowercase emails, whereas a domain invoice receiver or contact email (such as [email protected] or a mixed-case login) may contain uppercase characters. Unlike isPolicyMember and getPolicyRole in src/libs/PolicyUtils/permissions.ts (which fall back to policy.employeeList[login.toLowerCase()]), approvals.ts misses the employee entry when casing differs and falls back to getDefaultApprover(policy) (the primary contact).

What changes do you think we should make in order to solve the problem?

  1. In src/libs/actions/Workflow.ts (lines 179–194): Only apply the submitsTo: newDefaultApprover fallback when newDefaultApprover does not already have a custom submitsTo target in previousEmployeeList (and preserve previousEmployeeList[newDefaultApprover]?.submitsTo when convertApprovalWorkflowToPolicyEmployees touches updatedEmployees[newDefaultApprover] only to set forwardsTo / overLimitForwardsTo):

    if (newDefaultApprover) {
        const previousDefaultApproverEmployee = previousEmployeeList[newDefaultApprover];
        const existing = updatedEmployees[newDefaultApprover] ?? previousDefaultApproverEmployee;
        const existingSubmitsTo = updatedEmployees[newDefaultApprover]?.submitsTo ?? previousDefaultApproverEmployee?.submitsTo;
        if (!existing || !existingSubmitsTo) {
            updatedEmployees[newDefaultApprover] = {
                ...previousDefaultApproverEmployee,
                ...existing,
                email: newDefaultApprover,
                submitsTo: newDefaultApprover,
                pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
            };
            if (previousDefaultApproverEmployee) {
                previousEmployees[newDefaultApprover] = previousDefaultApproverEmployee;
            }
            employeesToClear[newDefaultApprover] = {pendingAction: null};
        } else if (!updatedEmployees[newDefaultApprover]?.submitsTo && previousDefaultApproverEmployee?.submitsTo) {
            updatedEmployees[newDefaultApprover] = {
                ...updatedEmployees[newDefaultApprover],
                submitsTo: previousDefaultApproverEmployee.submitsTo,
            };
        }
    }
    
  2. In src/libs/PolicyUtils/approvals.ts (lines 325, 366, 399, and 432): Add a helper getPolicyEmployee(policy, login) that checks policy?.employeeList?.[login] ?? policy?.employeeList?.[login.toLowerCase()] and use it in getApprovalWorkflow, getManagerAccountID, getManagerAccountEmail, and getReportApproverAccountID.

  3. In tests/unit/WorkflowTest.ts and tests/unit/PolicyUtilsTest.ts: Add unit tests verifying that:

    • Updating the Default Workflow when newDefaultApprover already has a custom submitsTo does not overwrite submitsTo with newDefaultApprover.
    • getManagerAccountEmail and getManagerAccountID resolve submitsTo case-insensitively.

What alternative solutions did you explore?

We considered skipping the newDefaultApprover block in updateApprovalWorkflow only when approvalWorkflow.isDefault is true, but if an admin edits the Default Workflow's second approver (forwardsTo) after configuring a custom workflow for the default approver, convertApprovalWorkflowToPolicyEmployees still creates updatedEmployees[newDefaultApprover] without submitsTo. Preserving previousEmployeeList[newDefaultApprover]?.submitsTo handles both Default and non-Default workflow edits.

e5ash avatar Nov 07 '26 14:11 e5ash

📣 @pa-khan! 📣 Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork. Please follow these steps:

  1. Make sure you've read and understood the contributing guidelines.
  2. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
  3. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
  4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details. Screen Shot 2022-11-16 at 4 42 54 PM Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>

melvin-bot[bot] avatar Nov 07 '26 14:11 melvin-bot[bot]

Proposal

Please re-state the problem that we are trying to solve in this issue.

When an external party sends an invoice to a company domain address ([email protected]), the system converts the incoming invoice into an internal Bill under the domain's primary contact's default workspace. Instead of routing directly to the primary contact's configured Submits To approver in the workspace approval workflow, the Bill first routes to the domain primary contact for approval (saying it cannot find the Submits To target) and only advances to the rest of the workspace approval chain after the primary contact approves it.

What is the root cause of that problem?

The invoice-to-bill conversion and initial approver assignment happen entirely on the backend (Auth / Web-Expensify), not in the Expensify/App frontend:

  1. In src/libs/actions/IOU/SendInvoice.ts, the frontend SendInvoice command only creates the sender's invoice report and transaction (getSendInvoiceInformation). It has no access to the recipient domain's internal workspace or approval workflow.
  2. When an invoice is sent to [email protected], the backend automatically generates a corresponding internal Bill report on the recipient's default workspace on behalf of the domain_primary_contact.
  3. Under Expensify's Bill Pay routing logic (or a backend lookup bug during auto-bill creation), the backend sets the domain_primary_contact as the initial managerID / first approver on the newly created Bill report rather than resolving the submitsTo rule from the primary contact's policyEmployeeList entry before the first approval step.

What changes do you think we should make in order to solve the problem?

No frontend changes in Expensify/App are required:

  1. If product intends for bills created via [email protected] to bypass the domain primary contact's initial review and route straight to their Submits To approver, the backend invoice-to-bill creation handler in Web-Expensify / Auth should resolve the domain_primary_contact's submitsTo target from the destination policy's employeeList (falling back to policy.approver / domain_primary_contact only when no submitsTo rule exists) when initializing the Bill report's managerID and NEXT_ACTION system message.
  2. If routing to the domain_primary_contact first is intentional (so the primary contact confirms receipt of the vendor invoice before forwarding it into the internal approval chain), then only the system message copy generated by the backend should be updated so it does not falsely claim that the Submits To approver could not be found.

What alternative solutions did you explore? (Optional)

We checked whether the client ever triggers SubmitReport or sets managerID on the recipient's internal Bill report in src/libs/actions/IOU/SendInvoice.ts or src/libs/actions/Report/index.ts, and confirmed the recipient's Bill report is created asynchronously on the server without client involvement.

ghost avatar Nov 08 '26 15:11 ghost

📣 @jeff-graham-ai! 📣 Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork. Please follow these steps:

  1. Make sure you've read and understood the contributing guidelines.
  2. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
  3. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
  4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details. Screen Shot 2022-11-16 at 4 42 54 PM Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>

melvin-bot[bot] avatar Nov 08 '26 15:11 melvin-bot[bot]

The bug is reported in both ND and Classic, so this is likely an Internal issue.

QichenZhu avatar Nov 09 '26 02:11 QichenZhu

The bug is reported in both ND and Classic, so this is likely an Internal issue.

🎀 👀 🎀 C+ reviewed

QichenZhu avatar Nov 09 '26 02:11 QichenZhu

Triggered auto assignment to @AndrewGable, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

melvin-bot[bot] avatar Nov 09 '26 02:11 melvin-bot[bot]

Discussing in Slack here https://expensify.slack.com/archives/C049HHMV9SM/p1793734473118239

AndrewGable avatar Nov 12 '26 00:11 AndrewGable

@AndrewGable @QichenZhu this issue was created 2 weeks ago. Are we close to a solution? Let's make sure we're treating this as a top priority. Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!