Repository navigation
Keep the negative tax amount sign for unreported expenses #103673
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
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
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.
When a positive unreported expense's amount, tax rate, or tax amount is edited,
getUpdatedTransaction()still stores the positivetransactionChanges.taxAmountunchanged becauseisFromExpenseReportis false for tracked expenses. This new tracked-expense normalization then negates that optimistic value, so the UI shows a negative tax and the update payload produced fromgetTransactionDetails()sends the negative amount to the API. The edit path must store tracked tax changes using the same opposite-sign convention before applying this normalization.Useful? React with 👍 / 👎.
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.
@MelvinBot can you explain the above in detail? The flow and the repro steps.
Uh oh!
There was an error while loading. Please reload this page.
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.
Codex is right. I reproduced it on this branch on web. If you type a tax amount on a positive unreported expense, the app shows it as negative. For example, entering 3.00 displays -$3.00.
Why: The PR now reads unreported tax with the opposite sign, like
amount. But the edit path still saves an edited tax as typed. It doesn't apply the opposite sign:amountforisFromExpenseReport || isUnReportedExpense.taxAmountonly forisFromExpenseReport.Before this PR,
Math.abs()hid the mismatch. Now the new read path in ReportUtils.ts:5651 flips the unflipped value.Fix: At line 384, use
isFromExpenseReport || isUnReportedExpense, matching line 180.Repro steps (workspace with Taxes on and a 5% rate):
Flow and more detail
Flow for a $100 unreported expense, tax set to 3.00:
300and callsupdateMoneyRequestTaxAmount.isFromExpenseReporttofalsebecause the parent is the self DM.getUpdatedTransactionstorestaxAmount: 300in the optimistic transaction. An unreported expense should store-300.getTransactionDetails(updatedTransaction). With this PR,getTaxAmount(..., false, true)returns-300. The UI shows -$3.00, and the request sendstaxAmount: -300(it sent300before this PR).getUpdateTrackExpenseParams(UpdateMoneyRequest.ts:2600-2616) follows the same pattern withisFromExpenseReport: false.What I tested:
Before the edit, the unreported expense showed tax $4.76. After changing the rate, it still showed $4.76:
view run · view recording
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.
@MelvinBot apply the fix
Uh oh!
There was an error while loading. Please reload this page.
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.
Done in 0ae433f. An edited tax amount on an unreported expense is now stored with the opposite sign, the same way
amountis. Entering 3.00 now reads back as $3.00, not -$3.00.taxAmountforisFromExpenseReport || isUnReportedExpense, matching line 180.TransactionUtilsTest,UpdateMoneyRequestTestandReportUtilsTestpass (1,997 tests). ESLint, typecheck and cspell are clean. I couldn't run the repro steps on web because the test browser loaded a blank page.Category-driven tax is not changed
I left the category path at getUpdatedTransaction.ts:413 as is.
getCategoryTaxDetailscalculates tax fromMath.absof the amount and stores it without a sign flip. Expense report expenses already work this way. I haven't checked whether the server response corrects that optimistic value.view run · no recording available