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

[$250] Expense - Pay with Expensify button appears for Employee after admin disconnects bank account #46738

Open
6 tasks done
lanitochka17 opened this issue Aug 2, 2024 · 62 comments
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. Internal Requires API changes or must be handled by Expensify staff Monthly KSv2

Comments

@lanitochka17
Copy link

lanitochka17 commented Aug 2, 2024

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: 9.0.16-0
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught during regression testing, add the test name, ID and link from TestRail: N/A
Issue reported by: Applause - Internal Team

Action Performed:

Precondition:

  • Delayed submission is enabled in Workflows
  • Workspace has an approver (admin)
  • Workspace has set up with bank account
  • Employee does not have bank account
  1. Go to staging.new.expensify.com
  2. [Employee] Go to workspace chat
  3. [Employee] Submit an expense over $100
  4. [Employee] Click on the submit button and stay on the main chat
  5. [Admin] Click Approve button on the expense preview
  6. [Admin] Go to workspace settings > Workflows
  7. [Admin] Click on the bank account
  8. [Admin] Disconnect bank account
  9. [Employee] Note that "Pay with Expensify" button shows up on expense preview on employee end after admin has disconnected bank account

Expected Result:

"Pay with Expensify" button will not appear on expense preview on employee end after admin has disconnected bank account

Actual Result:

"Pay with Expensify" button shows up on expense preview on employee end after admin has disconnected bank account.
When clicking on the expense preview and returning to main chat, the button disappears

Workaround:

Unknown

Platforms:

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

  • Android: Native
  • Android: mWeb Chrome
  • iOS: Native
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Add any screenshot/video evidence

Bug6560213_1722605179858.20240802_211830.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01e26750961886bca4
  • Upwork Job ID: 1821153286159845456
  • Last Price Increase: 2024-08-28
  • Automatic offers:
    • jjcoffee | Reviewer | 103796028
Issue OwnerCurrent Issue Owner: @teneeto
@lanitochka17 lanitochka17 added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Aug 2, 2024
Copy link

melvin-bot bot commented Aug 2, 2024

Triggered auto assignment to @miljakljajic (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.

@lanitochka17
Copy link
Author

@miljakljajic FYI I haven't added the External label as I wasn't 100% sure about this issue. Please take a look and add the label if you agree it's a bug and can be handled by external contributors

@lanitochka17
Copy link
Author

We think that this bug might be related to #wave-collect - Release 1

@melvin-bot melvin-bot bot added the Overdue label Aug 5, 2024
Copy link

melvin-bot bot commented Aug 5, 2024

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

@miljakljajic miljakljajic added the External Added to denote the issue can be worked on by a contributor label Aug 7, 2024
@melvin-bot melvin-bot bot changed the title Expense - Pay with Expensify button appears for Employee after admin disconnects bank account [$250] Expense - Pay with Expensify button appears for Employee after admin disconnects bank account Aug 7, 2024
Copy link

melvin-bot bot commented Aug 7, 2024

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

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

melvin-bot bot commented Aug 7, 2024

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

Copy link

melvin-bot bot commented Aug 12, 2024

@jjcoffee, @miljakljajic Huh... This is 4 days overdue. Who can take care of this?

@melvin-bot melvin-bot bot added the Overdue label Aug 12, 2024
@jjcoffee
Copy link
Contributor

Waiting for proposals!

@melvin-bot melvin-bot bot removed the Overdue label Aug 13, 2024
Copy link

melvin-bot bot commented Aug 14, 2024

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

@jjcoffee
Copy link
Contributor

Bumped on Slack to hopefully get some proposals in!

Copy link

melvin-bot bot commented Aug 16, 2024

@jjcoffee @miljakljajic 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!

@jjcoffee
Copy link
Contributor

jjcoffee commented Aug 19, 2024

@miljakljajic Maybe we should try bumping the price to get more eyes on this?

Copy link

melvin-bot bot commented Aug 21, 2024

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

@melvin-bot melvin-bot bot added the Overdue label Aug 21, 2024
@jjcoffee
Copy link
Contributor

This isn't getting any attention, let's bump the price @miljakljajic

@melvin-bot melvin-bot bot removed the Overdue label Aug 22, 2024
Copy link

melvin-bot bot commented Aug 27, 2024

@jjcoffee, @miljakljajic Huh... This is 4 days overdue. Who can take care of this?

@teneeto
Copy link
Contributor

teneeto commented Oct 1, 2024

@twisterdotcom @jjcoffee a PR is raised here: #49969

Here are my thoughts on my solution and possible alternatives (if needed).

Problem

On these lines:
https://github.com/teneeto/Expensify/blob/dcf1a0cac762ef658ebfa8f692331f04828d6716/src/libs/ReportUtils.ts#L1641 and https://github.com/teneeto/Expensify/blob/dcf1a0cac762ef658ebfa8f692331f04828d6716/src/libs/ReportUtils.ts#L1645, we are doing condition to check for payer and depending on whether or not a bank account is connected, those conditions are triggered. The issue is when a bank account is disconnected, the second condition is not immediately triggered because policy?.reimbursementChoice is not immediately or optimistically updated when the bank account is disconnected - except you force a page reload or the endpoint is re-triggered.

Soution

I found another field policy?.reimbursement?.choice?.reimbursementChoice which updates as expected. policy?.reimbursementChoice is now used as a fallback.
const reimbursementChoice = policy?.reimbursement?.choice?.reimbursementChoice ?? policy?.reimbursementChoice;

alternate solution

We can find out why policy?.reimbursementChoice doesn't optimistically update, fix it and then use it again.

Screenshot

The video below shows a log of policy objects and the variation in the reimbursement choice fields after the bank account is disconnected.


Screen.Recording.2024-10-01.at.08.20.42.mov

@jjcoffee
Copy link
Contributor

jjcoffee commented Oct 1, 2024

@teneeto Thanks for the investigation and for the detailed write-up! I just need to clarify a few points before proceeding.

when a bank account is disconnected, the second condition is not immediately triggered

Are you saying that once the bank account is disconnected, the reimbursementChoice should be CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_MANUAL?

I think the main confusion for me here is that the employee shouldn't be seeing the pay button at all as they are not the "reimburser" (in either condition). So it seems like once the bank account is disconnected, the employee is treated as the reimburser for some reason.

App/src/libs/ReportUtils.ts

Lines 1641 to 1647 in dcf1a0c

if (policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES) {
const isReimburser = session?.email === policy?.achAccount?.reimburser;
return (!policy?.achAccount?.reimburser || isReimburser) && (isApproved || isManager);
}
if (policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_MANUAL) {
return isAdmin && (isApproved || isManager);
}

@teneeto
Copy link
Contributor

teneeto commented Oct 1, 2024

Yes, reimbursementChoice should be CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_MANUAL. For the second point, I can't say I'm 100% sure of what the flow should be but yes, that contributed to the issue as well, I also stated it here: #46738 (comment). Either way, it involves the values being updated from BE.

Overall, the conditions with reimbursementChoice are the parent issue. If that is solved properly then it handles the confusing part as well.

@jjcoffee
Copy link
Contributor

jjcoffee commented Oct 1, 2024

That makes sense, thanks! I guess policy?.achAccount?.reimburser is getting removed along with the bank account which is another part of the issue.

I'm a bit unsure on why there are two fields for reimbursementChoice that you mention in your solution, so I'm gonna get an engineer assigned to make sure it's okay to switch to.

🎀👀🎀 C+ reviewed

Copy link

melvin-bot bot commented Oct 1, 2024

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

@srikarparsi
Copy link
Contributor

The RCA here makes sense to me. I do think we should go with the alternate solution listed though since we already store reimbursementChoice and don't think we need a new variable for that data.

Also, I don't think we should ever show the pay button to regular employees (not admins, managers...). @rlinoz, do you know why we show the settlement button in this line if reimburser is empty (and the report is approved)?

@rlinoz
Copy link
Contributor

rlinoz commented Oct 2, 2024

I think it comes from here actually #38253, but I am not sure what we were fixing, maybe @luacmartins remembers

@luacmartins
Copy link
Contributor

luacmartins commented Oct 2, 2024

Form the PR above, that covers this case when reimbursements are enabled but there's no VBBA account, hence no achAccount data in the policy

Reimbursement enabled, indirect (no VBBA) -> show Pay elsewhere and Pay with Expensify

@teneeto
Copy link
Contributor

teneeto commented Oct 4, 2024

How do we proceed with this, are we looking at a different route?

@jjcoffee
Copy link
Contributor

jjcoffee commented Oct 8, 2024

Sounds like this maybe needs to be internal if we plan to fix policy?.reimbursementChoice as @srikarparsi suggests?

@teneeto
Copy link
Contributor

teneeto commented Oct 8, 2024

I'm still keeping up with it. Ping me if you need me to make any changes regarding this issue.

@teneeto
Copy link
Contributor

teneeto commented Oct 11, 2024

@twisterdotcom @jjcoffee @srikarparsi do we proceed with this as a BE issue and internal? what should we do with this PR. Just curious to know how we can proceed with this issue based on our previous discussions

@teneeto
Copy link
Contributor

teneeto commented Oct 17, 2024

Ping! Ping!! @twisterdotcom @jjcoffee @srikarparsi, I'm just knocking to check the next steps on this issue and the PR that has already been raised. Do you have any ideas or suggestions on what I can do next?

@twisterdotcom
Copy link
Contributor

Ping ping indeed. Really need @srikarparsi to chime in, but it does sound like we need this to be Internal.

@srikarparsi
Copy link
Contributor

Hey, yes this does look backend but it is a little intersting. Sorry for the delay in responding.

In the backend, whenever we set reimbursementChoice, we nest it under policy.reimbursement.choice.

But in the frontend, we directly access it as policy.reimbursementChoice.

This is because we send the onyx update directly under policy instead of under policy.reimbursement.choice. But, it looks like we missed doing that in one place which is why policy.reimbursement.choice.reimbursementChoice is updating but policy.reimbursementChoice is not.

So two approaches:

  1. Change the frontend: I do think it's cleaner to keep things 1:1 with the db and it might be better to access the reimbursementChoice in the frontend as policy.reimbursement.choice.reimbursementChoice since that's what we do in the backend. But I'm not sure if it's worth refactoring all this code even if we want to do it. cc @puneetlath for thoughts since you worked on SetPolicyReimbursement recently.
  2. Queue the right Onyx update in the backend: Somewhere, we're queuing an update to policy.reimbursement.choice.reimbursementChoice instead of policy.reimbursement.choice. If we change this, this should fix the bug as @teneeto pointed out.

I'm going to make this internal since I think 2 is the better approach for now.

@srikarparsi srikarparsi added Internal Requires API changes or must be handled by Expensify staff and removed Reviewing Has a PR in review External Added to denote the issue can be worked on by a contributor labels Oct 21, 2024
@puneetlath
Copy link
Contributor

I do think generally that it's better to keep the front-end and back-end aligned if we can. It just makes things simpler and less confusing. Is it a big refactor to do so?

@srikarparsi
Copy link
Contributor

Cool, yeah. It's not crazy big, there's 51 occurrences in App of reimbursementChoice. I did not count how many instances we queue onyx updates to reimbursementChoice in the backend but it doesn't look like it's too too many. I agree that it'll probably be better for the long run but just wasn't sure in terms of priorities right now. But if you think now would be a good time to refactor it, I can start working on that.

@puneetlath
Copy link
Contributor

I think it's as good a time as any. Thanks so much for handling!

@melvin-bot melvin-bot bot removed the Weekly KSv2 label Nov 11, 2024
Copy link

melvin-bot bot commented Nov 11, 2024

This issue has not been updated in over 15 days. @twisterdotcom, @teneeto, @jjcoffee, @srikarparsi 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 the Monthly KSv2 label Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is broken. Auto assigns a BugZero manager. Internal Requires API changes or must be handled by Expensify staff Monthly KSv2
Projects
No open projects
Status: Polish
Development

No branches or pull requests

9 participants