Skip to content
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

[Due for payment 2025-02-13] [$250] $0 doesn't save in the Receipt required amount field in Workspaces #54290

Open
1 of 8 tasks
m-natarajan opened this issue Dec 18, 2024 · 33 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor

Comments

@m-natarajan
Copy link

m-natarajan commented Dec 18, 2024

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Version Number: 9.0.76-12
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught on HybridApp, is this reproducible on New Expensify Standalone?:
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by: @zsgreenwald
Slack conversation (hyperlinked to channel name): expensify_bugs

Action Performed:

  1. Enable Rules under more features in a controlled workspace
  2. Navigate to Rules in LHN
  3. Click Receipt required amount field and enter $0 as amount
  4. Click Save

Expected Result:

User able to save the amount. (In Classic, an admin has the ability to set the Receipt required amount to $0 to effective set a requirement on all imported CC transactions)

Actual Result:

User unable to save the $0 as amount

Workaround:

Unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • Android: Standalone
  • Android: HybridApp
  • Android: mWeb Chrome
  • iOS: Standalone
  • iOS: HybridApp
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Add any screenshot/video evidence
CleanShot.2024-12-16.at.15.14.23.mp4
Recording.852.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021869497589885449250
  • Upwork Job ID: 1869497589885449250
  • Last Price Increase: 2025-01-01
  • Automatic offers:
    • allgandalf | Reviewer | 105598691
    • nkdengineer | Contributor | 105598693
Issue OwnerCurrent Issue Owner: @JmillsExpensify
@m-natarajan m-natarajan added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Dec 18, 2024
Copy link

melvin-bot bot commented Dec 18, 2024

Triggered auto assignment to @stephanieelliott (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

@FitseTLT
Copy link
Contributor

FitseTLT commented Dec 18, 2024

Edited by proposal-police: This proposal was edited at 2024-12-18 13:05:49 UTC.

Proposal

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

$0 doesn't save in the Receipt required amount field in Workspaces

What is the root cause of that problem?

We are displaying empty string if the maxExpenseAmountNoReceipt is falsy here

if (policy?.maxExpenseAmountNoReceipt === CONST.DISABLED_MAX_EXPENSE_VALUE || !policy?.maxExpenseAmountNoReceipt) {
return '';

and also here
policy?.maxExpenseAmountNoReceipt === CONST.DISABLED_MAX_EXPENSE_VALUE || !policy?.maxExpenseAmountNoReceipt

but 0 is falsy

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

We should check for the type instead for both cases

        if (policy?.maxExpenseAmountNoReceipt === CONST.DISABLED_MAX_EXPENSE_VALUE || typeof policy?.maxExpenseAmountNoReceipt !== 'number') {

        policy?.maxExpenseAmountNoReceipt === CONST.DISABLED_MAX_EXPENSE_VALUE || typeof policy?.maxExpenseAmountNoReceipt !== 'number'

Note: I have seen similar problems with maxExpenseAmount here and here and for maxExpenseAge here and here policyCategory.maxExpenseAmount here and here. The BE allows the values to be set to 0 value but we are displaying empty string so we can apply similar fix as above for these cases too. But if this cases are different from maxExpenseAmountNoReceipt and we don't want to allow zero value then we should update the BE to disallow it and also update our FE code to disallow it and show error on validate but in the scope of this issue on maxExpenseAmountNoReceipt we are sure 0 is allowed so we can apply the above fix 👍

What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

We can test IndividualExpenseRulesSection and PolicyRulesPage by setting maxExpenseAmountNoReceipt to 0 and asserting 0 is displayed not empty string.

What alternative solutions did you explore? (Optional)

optionally use a check of undefined

@huult
Copy link
Contributor

huult commented Dec 18, 2024

Edited by proposal-police: This proposal was edited at 2025-01-02 04:46:31 UTC.

Proposal

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

$0 doesn't save in the Receipt required amount field in Workspaces

What is the root cause of that problem?

We are checking if !maxExpenseAmountNoReceipt, !maxExpenseAmount, and !maxExpenseAge, then return ''. Therefore, if the value is 0, these will return '' based on this condition.

if (policy?.maxExpenseAmountNoReceipt === CONST.DISABLED_MAX_EXPENSE_VALUE || !policy?.maxExpenseAmountNoReceipt) {
return '';
}

if (policy?.maxExpenseAmount === CONST.DISABLED_MAX_EXPENSE_VALUE || !policy?.maxExpenseAmount) {
return '';
}

if (policy?.maxExpenseAge === CONST.DISABLED_MAX_EXPENSE_VALUE || !policy?.maxExpenseAge) {
return '';
}

const defaultValue =
policy?.maxExpenseAmountNoReceipt === CONST.DISABLED_MAX_EXPENSE_VALUE || !policy?.maxExpenseAmountNoReceipt
? ''
: CurrencyUtils.convertToFrontendAmountAsString(policy?.maxExpenseAmountNoReceipt, policy?.outputCurrency);

const defaultValue =
policy?.maxExpenseAmount === CONST.DISABLED_MAX_EXPENSE_VALUE || !policy?.maxExpenseAmount
? ''
: CurrencyUtils.convertToFrontendAmountAsString(policy?.maxExpenseAmount, policy?.outputCurrency);

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

So we shouldn’t accept a 0 value when the user inputs it. We should validate the form and return an error like ‘Invalid amount’ if the value is 0. Something like this:

Add this function:

    const validate = useCallback(
        (values: FormOnyxValues<typeof ONYXKEYS.FORMS.RULES_REQUIRED_RECEIPT_AMOUNT_FORM>) => {
            const errors: FormInputErrors<typeof ONYXKEYS.FORMS.RULES_REQUIRED_RECEIPT_AMOUNT_FORM> = {};
            const maxExpenseAmountNoReceipt = values[INPUT_IDS.MAX_EXPENSE_AMOUNT_NO_RECEIPT];

            if (maxExpenseAmountNoReceipt === '0') {
                errors.maxExpenseAmountNoReceipt = translate('workspace.rules.individualExpenseRules.errors.invalidAmount');
            }

            return errors;
        },
        [translate],
    );

update ScreenWrapper to:

      <FormProvider
          style={[styles.flexGrow1, styles.ph5]}
          formID={ONYXKEYS.FORMS.RULES_REQUIRED_RECEIPT_AMOUNT_FORM}
          onSubmit={({maxExpenseAmountNoReceipt}) => {
              PolicyActions.setPolicyMaxExpenseAmountNoReceipt(policyID, maxExpenseAmountNoReceipt);
              Navigation.setNavigationActionToMicrotaskQueue(Navigation.goBack);
          }}
          submitButtonText={translate('workspace.editor.save')}
          enabledWhenOffline
          validate={validate}
      >

We can apply this solution to other similar cases, such as maxExpenseAmount ...

POC
  • Screenshot 2024-12-18 at 22 29 54

What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

We created a test for validate to check if the amount is 0. If it is, then errors.maxExpenseAmountNoReceipt should have a value. Otherwise, if the amount is not 0, the error should be {}.

What alternative solutions did you explore? (Optional)

Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

Or we can simply return '' for the case DISABLED_MAX_EXPENSE_VALUE (when the user inputs an empty value) to avoid displaying the default max expense value and apply the same logic to the other mentioned cases here and here

if (policy?.maxExpenseAmount === CONST.DISABLED_MAX_EXPENSE_VALUE || !policy?.maxExpenseAmount) {

        if (policy?.maxExpenseAmount === CONST.DISABLED_MAX_EXPENSE_VALUE) {
            return '';
        }

@FitseTLT
Copy link
Contributor

FitseTLT commented Dec 18, 2024

Updated to add similar fixes for maxExpenseAmount, maxExpenseAge and policyCategory.maxExpenseAmount

@stephanieelliott stephanieelliott added the External Added to denote the issue can be worked on by a contributor label Dec 18, 2024
@melvin-bot melvin-bot bot changed the title $0 doesn't save in the Receipt required amount field in Workspaces [$250] $0 doesn't save in the Receipt required amount field in Workspaces Dec 18, 2024
Copy link

melvin-bot bot commented Dec 18, 2024

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

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Dec 18, 2024
Copy link

melvin-bot bot commented Dec 18, 2024

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

@nkdengineer
Copy link
Contributor

Proposal

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

User unable to save the $0 as amount

What is the root cause of that problem?

When we enter 0 or 0.00, the parsedMaxExpenseAmountNoReceipt is 0

const parsedMaxExpenseAmountNoReceipt = maxExpenseAmountNoReceipt === '' ? CONST.DISABLED_MAX_EXPENSE_VALUE : CurrencyUtils.convertToBackendAmount(parseFloat(maxExpenseAmountNoReceipt));

Then we display an empty string here because !policy?.maxExpenseAmountNoReceipt is true

if (policy?.maxExpenseAmountNoReceipt === CONST.DISABLED_MAX_EXPENSE_VALUE || !policy?.maxExpenseAmountNoReceipt) {
return '';
}

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

We can simply remove !policy?.maxExpenseAmountNoReceipt since maxExpenseAmountNoReceipt will never be undefined

if (policy?.maxExpenseAmountNoReceipt === CONST.DISABLED_MAX_EXPENSE_VALUE || !policy?.maxExpenseAmountNoReceipt) {
return '';
}

We can do the same for maxExpenseAmount here and maxExpenseAge here

What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

NA

What alternative solutions did you explore? (Optional)

Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

@allgandalf
Copy link
Contributor

Will review today/ tomorrow

@caesaragen
Copy link

caesaragen commented Dec 24, 2024

Proposal

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

User unable to save the $0 as amount

What is the root cause of that problem?

The root cause lies in the conditional logic for rendering the field's value. Specifically:

  • The logic does not distinguish 0 (a valid amount) from null or CONST.DISABLED_MAX_EXPENSE_VALUE (invalid states).
  • As a result, 0 is treated as if no value were provided, leading to an empty field display.

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

To address this issue, I propose optimizing the conditional logic in the maxExpenseAmountNoReceiptText function to:

  • Explicitly check for null and CONST.DISABLED_MAX_EXPENSE_VALUE as invalid states that return an empty string.
  • Treat 0 as a valid value and pass it through CurrencyUtils.convertToDisplayString for proper formatting.
 const maxExpenseAmountNoReceiptText = useMemo(() => {
        const amount = policy?.maxExpenseAmountNoReceipt;
        if (amount == null || amount === CONST.DISABLED_MAX_EXPENSE_VALUE) {
            return '';
        }
        return CurrencyUtils.convertToDisplayString(amount, policyCurrency);
    }, [policy?.maxExpenseAmountNoReceipt, policyCurrency]);

What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

To prevent reintroducing this issue in the future, the following scenarios should be covered in automated tests:

  1. Saving $0 in the Field:

    • Verify that saving 0 in the "Receipt Required Amount" field displays $0 correctly.
  2. Saving Valid Non-Zero Values:

    • Ensure that valid amounts (e.g., $50) are displayed correctly after saving.
  3. Blank or Disabled Field States:

    • Test that saving a blank field or a value equivalent to CONST.DISABLED_MAX_EXPENSE_VALUE results in an empty display.
  4. Currency Formatting:

    • Confirm that the amount is correctly formatted based on the policy’s currency (e.g., $0 for USD, €0 for EUR).
  5. Edge Cases:

    • Test edge cases, such as null, extremely large values, and invalid characters, to ensure robustness.

Copy link

melvin-bot bot commented Dec 24, 2024

📣 @caesaragen! 📣
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>

@caesaragen
Copy link

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

Copy link

melvin-bot bot commented Dec 24, 2024

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

Copy link

melvin-bot bot commented Dec 25, 2024

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

Copy link

melvin-bot bot commented Dec 27, 2024

@JmillsExpensify, @allgandalf Whoops! This issue is 2 days overdue. Let's get this updated quick!

@melvin-bot melvin-bot bot added the Overdue label Dec 27, 2024
Copy link

melvin-bot bot commented Dec 31, 2024

@JmillsExpensify, @allgandalf Still overdue 6 days?! Let's take care of this!

Copy link

melvin-bot bot commented Jan 1, 2025

@JmillsExpensify @allgandalf 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!

Copy link

melvin-bot bot commented Jan 1, 2025

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

@allgandalf
Copy link
Contributor

Proposal from @nkdengineer LGTM, their RCA is correct and solution looks good

🎀👀🎀 C+ reviewed

@nkdengineer
Copy link
Contributor

My proposal only removes !policy?.maxExpenseAmountNoReceipt condition. Then it still returns an empty string if the value is the disabled value.

Optional: Another thing we can do here is we can also remove !policy?.maxExpenseAmountNoReceipt here to display 0 value in the input.

const defaultValue =
policy?.maxExpenseAmountNoReceipt === CONST.DISABLED_MAX_EXPENSE_VALUE || !policy?.maxExpenseAmountNoReceipt
? ''

@FitseTLT
Copy link
Contributor

FitseTLT commented Jan 2, 2025

Proposal from @nkdengineer LGTM, their RCA is correct and solution looks good

🎀👀🎀 C+ reviewed

@allgandalf How did you prove that props like maxExpenseAmountNoReceipt cannot be undefined. You can check the type definition of Policy here

App/src/types/onyx/Policy.ts

Lines 1843 to 1845 in c4b3297

/** Max amount for an expense with no receipt violation */
maxExpenseAmountNoReceipt?: number;

that the prop can be undefined and that's why the code was added in the first place to provide safety. I don't think we have enough info here to remove this safety check. I believe we should handle the root cause of the issue that is caused by using
!policy?.maxExpenseAmountNoReceipt instead of correctly checking the type is undefined like My Proposal because using !policy?.maxExpenseAmountNoReceipt will include the value 0 too.

cc @danieldoglas

@nkdengineer
Copy link
Contributor

nkdengineer commented Jan 2, 2025

The rule can be enabled only in the control workspace. When we upgrade a workspace these values are initialized here. And in the update flow, we also update this to none undefined value. So it's safe to remove this condition !policy?.maxExpenseAmountNoReceipt

maxExpenseAge: CONST.POLICY.DEFAULT_MAX_EXPENSE_AGE,
maxExpenseAmount: CONST.POLICY.DEFAULT_MAX_EXPENSE_AMOUNT,
maxExpenseAmountNoReceipt: CONST.POLICY.DEFAULT_MAX_AMOUNT_NO_RECEIPT,

Copy link

melvin-bot bot commented Jan 7, 2025

@JmillsExpensify, @danieldoglas, @allgandalf Huh... This is 4 days overdue. Who can take care of this?

@melvin-bot melvin-bot bot added the Overdue label Jan 7, 2025
@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Jan 7, 2025
Copy link

melvin-bot bot commented Jan 7, 2025

📣 @allgandalf 🎉 An offer has been automatically sent to your Upwork account for the Reviewer role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job

Copy link

melvin-bot bot commented Jan 7, 2025

📣 @nkdengineer 🎉 An offer has been automatically sent to your Upwork account for the Contributor role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job
Please accept the offer and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻
Keep in mind: Code of Conduct | Contributing 📖

@melvin-bot melvin-bot bot removed the Overdue label Jan 7, 2025
@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Daily KSv2 labels Jan 8, 2025
@JmillsExpensify
Copy link

Working through the PR.

@melvin-bot melvin-bot bot removed the Weekly KSv2 label Feb 3, 2025
Copy link

melvin-bot bot commented Feb 3, 2025

This issue has not been updated in over 15 days. @JmillsExpensify, @danieldoglas, @allgandalf, @nkdengineer eroding to Monthly issue.

P.S. Is everyone reading this sure this is really a near-term priority? Be brave: if you disagree, go ahead and close it out. If someone disagrees, they'll reopen it, and if they don't: one less thing to do!

@melvin-bot melvin-bot bot added Monthly KSv2 Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Monthly KSv2 labels Feb 3, 2025
@melvin-bot melvin-bot bot changed the title [$250] $0 doesn't save in the Receipt required amount field in Workspaces [Due for payment 2025-02-13] [$250] $0 doesn't save in the Receipt required amount field in Workspaces Feb 6, 2025
Copy link

melvin-bot bot commented Feb 6, 2025

Reviewing label has been removed, please complete the "BugZero Checklist".

@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Feb 6, 2025
Copy link

melvin-bot bot commented Feb 6, 2025

The solution for this issue has been 🚀 deployed to production 🚀 in version 9.0.94-25 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

If no regressions arise, payment will be issued on 2025-02-13. 🎊

For reference, here are some details about the assignees on this issue:

Copy link

melvin-bot bot commented Feb 6, 2025

@allgandalf @JmillsExpensify @allgandalf The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]

@allgandalf
Copy link
Contributor

BugZero Checklist:

  • [Contributor] Classify the bug:
Bug classification

Source of bug:

  • 1a. Result of the original design (eg. a case wasn't considered)
  • 1b. Mistake during implementation
  • 1c. Backend bug
  • 1z. Other:

Where bug was reported:

  • 2a. Reported on production (eg. bug slipped through the normal regression and PR testing process on staging)
  • 2b. Reported on staging (eg. found during regression or PR testing)
  • 2d. Reported on a PR
  • 2z. Other:

Who reported the bug:

  • 3a. Expensify user
  • 3b. Expensify employee
  • 3c. Contributor
  • 3d. QA
  • 3z. Other:
  • [Contributor] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.

    Link to comment: https://github.com/Expensify/App/pull/47409/files#r1948469643

  • [Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner.

    Link to discussion: N/A

  • [Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.

  • [BugZero Assignee] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.

    Link to issue:

Regression Test Proposal

Precondition:

  • N/A

Test:

  1. Enable Rules under more features in a controlled workspaceNavigate to Rules in LHN
  2. Click Receipt required amount field and enter $0 as amount
  3. Click Save

Verify that: User able to save the amount.

Do we agree 👍 or 👎

@melvin-bot melvin-bot bot added Daily KSv2 and removed Weekly KSv2 labels Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor
Projects
None yet
Development

No branches or pull requests

9 participants