App icon indicating copy to clipboard operation
App copied to clipboard

[$175] [Exploratory] Invoice - Billable toggle auto-off after creating the invoice

Open applause-bot[bot] opened this issue 1 month ago • 29 comments

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


Version Number: v9.5.26-0 Reproducible in staging?: Yes Reproducible in production?: Yes If this was caught during regression testing, add the test name, ID and link from BrowserStack: https://test-management.browserstack.com/projects/2219752/test-runs/81348517/folder/57600901/41237194/1926749759?sort=%2Bidentifier Email or phone of affected tester (no customers): [email protected] Issue reported by: Applause Internal Team Bug source: Exploratory - Significant User Experience Deterioration Device used: Windows 11/Chrome App Component: Chat Report View

Action Performed:

Preconditions: Tester has already set up the Control Workspace to be tested in NewDot Enable Rules and Set Billable default to "Billable", turn on Invoice Steps:

  1. Open the NewDot app
  2. Click on FAB - Send Invoice
  3. Select a user - Create the invoice
  4. Click on the View button on Growl

Expected Result:

The Billable toggle is enabled

Actual Result:

On the confirmation page, the Billable toggle is on, but after creating and reopening, it turns off

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

https://github.com/user-attachments/assets/c6931a9c-931a-482f-bafe-d14c05e3d536

View all open jobs on GitHub

Applause Internal Information Exported by: Rizky Gunawan Bug ID: 7300203

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

applause-bot[bot] avatar Oct 30 '26 06:10 applause-bot[bot]

While Applause doesn't embed attachments for this bug, here are the links for quick view: https://platform.applause.com/services/links/v1/external/0fda652d849fe8d3a49b3eafb01f48e5169f47883795194a82db51c84a7b728b

applause-bot[bot] avatar Oct 30 '26 06:10 applause-bot[bot]

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

Proposal

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

When sending an invoice from a workspace that has Rules enabled and the default set to "Billable", the Billable toggle displays as enabled on the confirmation screen, but after creating the invoice and reopening it, the Billable toggle reverts to disabled (off).

What is the root cause of that problem?

In src/libs/actions/IOU/SendInvoice.ts:

  1. In sendInvoice() (lines 855–878), the parameters payload constructed for API.writeWhenReady(WRITE_COMMANDS.SEND_INVOICE, parameters, ...) fails to forward billable: transaction?.billable (and in src/libs/API/parameters/SendInvoiceParams.ts, the billable?: boolean property is omitted from the SendInvoiceParams type definition).
  2. While getSendInvoiceInformation() correctly assigns billable to the optimistic transaction object (line 706), the backend SendInvoice command never receives the billable parameter. When the backend executes and persists the transaction and syncs back down to Onyx, the transaction's billable state is reset back to false.

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

  1. In src/libs/API/parameters/SendInvoiceParams.ts:
    • Add billable?: boolean to the SendInvoiceParams type definition.
  2. In src/libs/actions/IOU/SendInvoice.ts:
    • In sendInvoice(), pass billable: transaction?.billable inside parameters alongside amount, comment, category, and other transaction fields so that the backend SendInvoice command persists the billable status selected on the invoice.

What alternative solutions did you explore? (Optional)

None needed. Forwarding billable in SendInvoiceParams matches the standard pattern used across all other IOU transaction flows (e.g., MoneyRequest, TrackExpense, PerDiem).

edotwedo avatar Oct 31 '26 12:10 edotwedo

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

melvin-bot[bot] avatar Oct 31 '26 12:10 melvin-bot[bot]

Proposal

What is the root cause of that problem?

The SendInvoice request never sends billable to the server.

  1. On the confirmation page, the draft transaction gets billable from the workspace default. So the toggle shows on.
  2. sendInvoice() copies billable onto the optimistic transaction (SendInvoice.ts:706).
  3. The API parameters leave billable out (SendInvoice.ts:849-871). The SendInvoiceParams type has no billable field either (SendInvoiceParams.ts:3-29).
  4. The server saves the invoice as not billable. Its copy replaces the optimistic transaction, so the toggle in MoneyRequestView shows off.

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

  1. Add an optional billable field to SendInvoiceParams, like RequestMoneyParams and TrackExpenseParams do.
  2. In sendInvoice(), send transaction?.billable in the SEND_INVOICE parameters, next to category.

Both callers pass the full draft transaction, so this one change covers both.

Backend check needed: I could not confirm that the backend SendInvoice command reads a billable parameter. If it doesn't, an internal engineer must add that before the App change takes effect.

What alternative solutions did you explore? (Optional)

None. Note that tag, taxCode, and taxAmount have the same gap: they go on the optimistic transaction but not in the request. Fix those in the same PR if invoices should keep them.

Code references

Next Steps for Contributor+ team: To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/105460) to create a draft PR. To refine: @MelvinBot <your feedback> To reject: Explain why you are rejecting Melvin's proposal.


view run

MelvinBot avatar Nov 03 '26 00:11 MelvinBot

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

melvin-bot[bot] avatar Nov 03 '26 00:11 melvin-bot[bot]

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

melvin-bot[bot] avatar Nov 03 '26 00:11 melvin-bot[bot]

@expensify/product Is billable toggle for invoices intentional? I am curious if we need to hide billable toggle for invoices since invoice is only a document to collect payment. What do you think?

rojiphil avatar Nov 05 '26 17:11 rojiphil

Is billable toggle for invoices intentional? I am curious if we need to hide billable toggle for invoices since invoice is only a document to collect payment. Note that tag, taxCode, and taxAmount have the same gap: they go on the optimistic transaction but not in the request. Fix those in the same PR if invoices should keep them.

@heyjennahay could you confirm the expected results on all three of these? @rojiphil you could also check an invoice in Classic in the meantime.

trjExpensify avatar Nov 06 '26 01:11 trjExpensify

Proposal

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

When creating an invoice from the confirmation page with the "Billable" toggle enabled, opening the newly created invoice details shows the "Billable" toggle turned on momentarily (optimistically) and then automatically flipping off once the SendInvoice network request finishes.

What is the root cause of that problem?

In src/libs/actions/IOU/SendInvoice.ts:

  1. getSendInvoiceInformation() builds the optimistic transaction with billable preserved from the draft transaction, so the UI initially displays "Billable" as enabled.
  2. However, in sendInvoice() (src/libs/actions/IOU/SendInvoice.ts, lines 855–878), the parameters object constructed for API.write(WRITE_COMMANDS.SEND_INVOICE, parameters, onyxData) omits billable: transaction?.billable (and src/libs/API/parameters/SendInvoiceParams.ts does not declare billable?: boolean). Because billable is never sent to the backend in SendInvoice, the server creates the invoice transaction with billable: false and returns that in the response Onyx updates, overwriting the optimistic billable: true state.

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

  1. In src/libs/API/parameters/SendInvoiceParams.ts, add billable?: boolean; to SendInvoiceParams.
  2. In src/libs/actions/IOU/SendInvoice.ts (around lines 855–878), include billable: transaction?.billable in the parameters object passed to API.write(WRITE_COMMANDS.SEND_INVOICE, parameters, onyxData).
  3. Update tests/actions/IOUTest.ts to assert that SendInvoice passes billable in the API write parameters when creating an invoice.

What alternative solutions did you explore? (Optional)

None—passing billable in the SendInvoice API parameters directly aligns sendInvoice() with requestMoney() and trackExpense(), both of which already pass billable in their respective API parameters.

jeffrey-graham avatar Nov 07 '26 06:11 jeffrey-graham

📣 @jeffrey-graham! 📣 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 06:11 melvin-bot[bot]

Proposal

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

When creating an invoice on a workspace that has tags/categories and a default billable setting enabled (so the Billable toggle is ON on the confirmation page), after clicking Send invoice and opening the newly created invoice's transaction details, the Billable toggle automatically turns OFF.

What is the root cause of that problem?

In src/libs/actions/IOU/SendInvoice.ts (getSendInvoiceInformation and sendInvoice, lines 622–875):

  1. getSendInvoiceInformation (line 706) passes billable into buildOptimisticTransaction, so optimisticTransaction.billable is true while the request is in flight (which is why the Billable toggle initially appears ON right after creation).
  2. However, in sendInvoice (src/libs/actions/IOU/SendInvoice.ts lines 849–870) and SendInvoiceParams (src/libs/API/parameters/SendInvoiceParams.ts), the parameters object sent to API.write(WRITE_COMMANDS.SEND_INVOICE, parameters, onyxData) omits billable: transaction?.billable (unlike requestMoney and trackExpense, which explicitly include billable in their API parameters).
  3. Because billable is never sent in the SendInvoice API payload, the backend creates the invoice transaction with billable: false and returns that transaction in the response/Pusher update, overwriting the optimistic billable: true value and flipping the Billable switch to OFF.

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

  1. Add billable?: boolean to SendInvoiceParams in src/libs/API/parameters/SendInvoiceParams.ts.
  2. Include billable: transaction?.billable in parameters inside sendInvoice (src/libs/actions/IOU/SendInvoice.ts lines 849–870):
    • Pass billable: transaction?.billable in the SendInvoiceParams payload so the backend persists the billable flag selected on the confirmation step and returns billable: true in the server response.

What alternative solutions did you explore? (Optional)

Preserving billable client-side by ignoring the server response was considered and rejected because the server is the source of truth for invoice transaction fields and other devices/receivers rely on the persisted backend billable property.

tungnguyen84 avatar Nov 07 '26 09:11 tungnguyen84

@rojiphil Eep! 4 days overdue now. Issues have feelings too...

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

@rojiphil 6 days overdue. This is scarier than being forced to listen to Vogon poetry!

melvin-bot[bot] avatar Nov 12 '26 21:11 melvin-bot[bot]

@rojiphil this issue was created 2 weeks ago. Are we close to approving a proposal? If not, what's blocking us from getting this issue assigned? Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!

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

Proposal

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

When creating an invoice from a Control workspace with Rules enabled and Default billable set to Billable, the confirmation screen (InvoiceConfirmationList) shows the Billable toggle enabled (on), and right after sending the invoice it initially renders enabled optimistically—but as soon as the SendInvoice request resolves (or on reopen), the Billable toggle turns off (even though MoneyRequestView continues to render and allow toggling Billable on that invoice via UpdateMoneyRequestBillable).

What is the root cause of that problem?

  1. SendInvoice builds the optimistic transaction with billable, tag, taxCode, and taxAmount, yet omits them from the SendInvoice API payload:

  2. Codebase verification on how NewDot treats billable, tag, and taxCode/taxAmount on Invoices (addressing @rojiphil & @trjExpensify's question in #issuecomment-6655297431): Tracing both the creation (InvoiceConfirmationList) and detail/edit (MoneyRequestView) surfaces shows an existing asymmetry across those three field groups:

    • billable IS surfaced and editable on created invoices in MoneyRequestView: In src/components/ReportActionItem/MoneyRequestView.tsx:314-315, 562, 1770-1810, isPolicyExpenseChat is isGroupPolicyByType(reportPolicyType) (true for the sender's Control workspace). Notice line 568 (shouldShowReimbursable) and line 601 (shouldShowVendor) explicitly exclude !isInvoice, whereas shouldShowBillable (line 562) does not exclude isInvoice—and toggling it in MoneyRequestView calls updateMoneyRequestBillable (UpdateMoneyRequest.ts), which persists billable on the invoice transaction! (Conversely, if Product decides invoices should not carry billable, hiding it requires guarding three places—not just confirmation—otherwise ExpenseDefaultsSetter still stamps billable: true and MoneyRequestView still renders the toggle whenever isBillableEnabledOnPolicy(policy) is true; see Alternative below.)
    • tag and taxCode/taxAmount are ALREADY hidden during invoice creation, yet MoneyRequestView leaks them post-creation and FieldAutoSelector mutates tag silently:
      • On IOURequestStepConfirmation/index.tsx:348-370, isPolicyExpenseChat is false for iouType === CONST.IOU.TYPE.INVOICE (an invoice's participants are {accountID} + {policyID, isSender: true}, and the room has chatType: 'invoice', not 'policyExpenseChat'). Therefore on InvoiceConfirmationList:
        • shouldShowTags (useFooterDerivedFlags.ts:83: (isPolicyExpenseChat || isUnreported || isCreatingTrackExpense) && hasEnabledTags(policyTagLists)) is already false.
        • shouldShowTax (useConfirmationListData.ts:128: isTaxTrackingEnabled(isPolicyExpenseChat || isTrackExpense, policy, ...)) is already false, so TaxController.tsx:83, 100 (if (!shouldShowTax) return;) never populates taxCode/taxAmount on invoice creation.
      • Hidden bug in FieldAutoSelector.tsx:84-103: Even though shouldShowTags is false on InvoiceConfirmationList, InvoiceConfirmationList.tsx:22 mounts <FieldAutoSelector {...data.fieldAutoSelectProps} />, whose second useEffect (FieldAutoSelector.tsx:84-103) does not check shouldShowTags (unlike the category useEffect above it, which checks shouldShowCategories at line 73)! When the sender workspace has a required tag list with a single enabled tag, FieldAutoSelector silently writes tag onto the draft invoice transaction even though Tags are hidden on the invoice confirmation form.
      • And once the invoice is created, MoneyRequestView.tsx:315 sets isPolicyExpenseChat = isGroupPolicyByType(reportPolicyType) (true!), which causes Category, Tag, Tax, and Billable to appear on the sent invoice detail view even when Tag/Tax were hidden during creation.

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

Depending on Product's confirmation (@heyjennahay / @trjExpensify), here is the exact, complete fix for either direction:

Path A — Keep billable (and optionally tag / taxCode / taxAmount) working end-to-end on Invoices (matches current InvoiceConfirmationList + MoneyRequestView behavior and the QA test expectation):

  1. src/libs/API/parameters/SendInvoiceParams.ts: Add billable?: boolean; (and tag?: string; taxCode?: string; taxAmount?: number; if backend SendInvoice supports them alongside RequestMoneyParams.ts:24-27):
    category?: string;
    tag?: string;
    taxCode?: string;
    taxAmount?: number;
    billable?: boolean;
    
  2. src/libs/actions/IOU/SendInvoice.ts: Return the resolved taxCode (or read optimisticTransaction fields) from getSendInvoiceInformation and forward billable: transaction?.billable (plus tag: transaction?.tag, taxCode, taxAmount: transaction?.taxAmount if supported by Auth/Web-E SendInvoice) in parameters passed to API.writeWhenReady(WRITE_COMMANDS.SEND_INVOICE, parameters, ...).
  3. src/components/MoneyRequestConfirmationList/FieldAutoSelector.tsx:84: Pass shouldShowTags into FieldAutoSelector and guard the tag auto-selection effect (if (!transactionID || !shouldShowTags) { return; }), matching shouldShowCategories at line 73, so hidden tag fields are never silently populated on flows where shouldShowTags is false.
  4. Tests (tests/actions/IOUTest/SendInvoiceTest.ts): Assert that sendInvoice forwards billable: true (and billable: false) in the WRITE_COMMANDS.SEND_INVOICE API parameters and preserves optimisticTransaction.billable. (Note: If Web-E/Auth SendInvoice does not yet persist billable onto the created invoice transaction, an internal backend update is also needed so the server response echoes billable.)

What alternative solutions did you explore? (Optional)

  • Path B — If Product confirms Invoices should NOT have billable (nor tag / tax) at all (@rojiphil's hypothesis): Simply hiding the switch in one component is insufficient because three separate layers touch billable on invoices. All four places below must be gated with !isTypeInvoice / !isInvoice:
    1. useFooterDerivedFlags.ts:94: const shouldShowBillable = isBillableEnabledOnPolicy(policy) && !isTypeInvoice; (hides Billable on InvoiceConfirmationList).
    2. ExpenseDefaultsSetter.tsx:27 (called from IOURequestStepConfirmation/index.tsx:711): skip setMoneyRequestBillable(transactionID, defaultBillable) when iouType === CONST.IOU.TYPE.INVOICE so draft invoices never inherit policy.defaultBillable = true.
    3. MoneyRequestView.tsx:562 (and :556, :633 if tag and tax should also be excluded from sent invoices, matching InvoiceConfirmationList): add && !isInvoice to shouldShowBillable (matching shouldShowReimbursable at line 568 and shouldShowVendor at line 601) so MoneyRequestView does not display the Billable toggle on opened invoices.
    4. FieldAutoSelector.tsx:84: guard tag auto-selection with shouldShowTags.

cocvn157 avatar Nov 14 '26 00:11 cocvn157

@rojiphil 12 days overdue. Walking. Toward. The. Light...

@rojiphil please review these.

garrettmknight avatar Nov 19 '26 18:11 garrettmknight

This issue has not been updated in over 14 days. @rojiphil eroding to Weekly issue.

Is billable toggle for invoices intentional? I am curious if we need to hide billable toggle for invoices since invoice is only a document to collect payment. Note that tag, taxCode, and taxAmount have the same gap: they go on the optimistic transaction but not in the request. Fix those in the same PR if invoices should keep them.

@rojiphil you could also check an invoice in Classic in the meantime.

@trjExpensify Yeah... Billable option is not displayed in Classic as well. Whereas tag, taxCode and taxAmount remain displayed. I think we can go ahead and hide the billable toggle for invoices unless someone thinks differently.

https://github.com/user-attachments/assets/e8fe2109-28c3-406e-817e-fee3e8edce27

rojiphil avatar Nov 24 '26 02:11 rojiphil

@MelvinBot Please refine the proposal. The objective is to hide the billable toggle for invoices.

rojiphil avatar Nov 24 '26 03:11 rojiphil