-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Fix wrong total amount of hold expenses when approve/pay partially #49971
Merged
Gonals
merged 28 commits into
Expensify:main
from
bernhardoj:fix/48760-wrong-expense-total-if-currency-different
Dec 2, 2024
Merged
Changes from 26 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
09a1942
fix the wrong calculation
bernhardoj d0037f6
Merge branch 'main' into fix/48760-wrong-expense-total-if-currency-di…
bernhardoj 2b5a152
use the current iou when creating the new report
bernhardoj 6196f9c
remove unused import
bernhardoj 8c86bc1
Merge branch 'main' into fix/48760-wrong-expense-total-if-currency-di…
bernhardoj b831dd1
fix total calculation
bernhardoj fbdb8ad
Merge branch 'main' into fix/48760-wrong-expense-total-if-currency-di…
bernhardoj 7c223b9
get the reimbursable amount when the type is pay
bernhardoj 62b6727
Merge branch 'main' into fix/48760-wrong-expense-total-if-currency-di…
bernhardoj 903d17d
rename
bernhardoj 997de55
update unheldTotal and unheldReimburableTotal optimistically
bernhardoj 3817ddd
Merge branch 'main' into fix/48760-wrong-expense-total-if-currency-di…
bernhardoj 6e1f6e4
update comment
bernhardoj 077a7d5
calc the amount once
bernhardoj d7fddd1
store the correct non reimbursable amount
bernhardoj 6932d60
fix lint
bernhardoj 8cbe949
Merge branch 'main' into fix/48760-wrong-expense-total-if-currency-di…
bernhardoj 8ce39ae
fix wrong non reimbursable amount
bernhardoj c278a1a
optimistically update unheld total for IOU
bernhardoj 54023a3
Merge branch 'main' into fix/48760-wrong-expense-total-if-currency-di…
bernhardoj d0277e2
Merge branch 'main' into fix/48760-wrong-expense-total-if-currency-di…
bernhardoj 164a73a
fix syntax error
bernhardoj a3c25a5
Merge branch 'main' into fix/48760-wrong-expense-total-if-currency-di…
bernhardoj 2c4480d
fix lint
bernhardoj 9ade52c
fix another lint
bernhardoj fa58c4f
fix type error
bernhardoj 07c33d0
Merge branch 'main' into fix/48760-wrong-expense-total-if-currency-di…
bernhardoj ad5a3c5
Merge branch 'main' into fix/48760-wrong-expense-total-if-currency-di…
bernhardoj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,6 +76,7 @@ function updateIOUOwnerAndTotal<TReport extends OnyxInputOrEntry<Report>>( | |
currency: string, | ||
isDeleting = false, | ||
isUpdating = false, | ||
isOnhold = false, | ||
): TReport { | ||
// For the update case, we have calculated the diff amount in the calculateDiffAmount function so there is no need to compare currencies here | ||
if ((currency !== iouReport?.currency && !isUpdating) || !iouReport) { | ||
|
@@ -87,18 +88,26 @@ function updateIOUOwnerAndTotal<TReport extends OnyxInputOrEntry<Report>>( | |
|
||
// Let us ensure a valid value before updating the total amount. | ||
iouReportUpdate.total = iouReportUpdate.total ?? 0; | ||
iouReportUpdate.unheldTotal = iouReportUpdate.unheldTotal ?? 0; | ||
|
||
if (actorAccountID === iouReport.ownerAccountID) { | ||
iouReportUpdate.total += isDeleting ? -amount : amount; | ||
if (!isOnhold) { | ||
iouReportUpdate.unheldTotal += isDeleting ? -amount : amount; | ||
} | ||
} else { | ||
iouReportUpdate.total += isDeleting ? amount : -amount; | ||
if (!isOnhold) { | ||
iouReportUpdate.unheldTotal += isDeleting ? amount : -amount; | ||
} | ||
} | ||
|
||
if (iouReportUpdate.total < 0) { | ||
// The total sign has changed and hence we need to flip the manager and owner of the report. | ||
iouReportUpdate.ownerAccountID = iouReport.managerID; | ||
iouReportUpdate.managerID = iouReport.ownerAccountID; | ||
iouReportUpdate.total = -iouReportUpdate.total; | ||
iouReportUpdate.unheldTotal = -iouReportUpdate.unheldTotal; | ||
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. Even though the BE stores it as negative, I still switch the sign here optimistically just to make it consistent with |
||
} | ||
|
||
return iouReportUpdate; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the optimistic unheldTotal for IOU too. However, there is a problem.
When user B submits, it will go into the
else
block, subtractingtotal
from the amount (10). So, the new total will be -6. If it's < 0, we switch the owner with this logic and switch the sign too, so the new optimistic total is 6.App/src/libs/IOUUtils.ts
Lines 96 to 100 in 866ce4b
The problem I see is, that BE still keeps the sign, so the
total
from BE is -6. Also, theunheldTotal
is -8, which looks like it comes fromunheldTotal
(2) - amount (10). So, I apply this calculation for the optimistic one too as you can see above. I'm not sure if theunheldTotal
should be -8, but at least I match it with the BE. I think it will be another big problem to solve and decide the expected behavior.Notice the image below shows Pay -8 (unheldTotal).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm this looks tricky, i think we need to agree on the expected behaviour on what the total and the unheldTotal should be in this case and also in the case where we unhold the $2 request. (can we still unhold that request? and how can do it?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can still unhold it and the
unheldTotal
will be the same astotal
(-6). If I hold it again, it will be -8 again.I think if we have this case, the new total should be 6 (number is correct already in prod, but it's in negative) and unheldTotal should be:
current held = total (4) - unheldTotal (2) = 2
new unheldTotal = new total (6) - current held (2) = 4
I suspect the BE already did this calculation, but because the total is negative (-6), subtracting with 2 will be -8.
cc: @robertjchen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unheldTotal
on the backend is simply thereimbursable total (excluding held transactions)
+non reimbursable total (excluding held transactions)
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the problem around IOUs and expense reports having different signage? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK, we haven't changed that, but it has been a loooong while since I touched that area
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@robertjchen Would you be able to check again so we can move forward here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@robertjchen Just merged with the main and fixed some conflicts. I think we just need a confirmation whether it's necessarry need to do this or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay- I think switching the sign optimistically as you've proposed may be necessary, as there won't be any further changes to the amounts being returned from the BE 😥
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing to change then, I just fixed a conflict, I think it's ready for merge.