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

[HOLD for payment 2024-10-14] [$250] [P2P Distance] App crashes after selecting rate that has no Tax rate & Tax reclaimable on #49556

Closed
2 of 6 tasks
IuliiaHerets opened this issue Sep 20, 2024 · 21 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

@IuliiaHerets
Copy link

IuliiaHerets commented Sep 20, 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.39-0
Reproducible in staging?: Y
Reproducible in production?: Y
Email or phone of affected tester (no customers): [email protected]
Issue reported by: Applause Internal Team

Action Performed:

  1. Launch New Expensify app.
  2. Create a new workspace.
  3. Enable Distance rates and Taxes.
  4. Go to Distance rates > Settings > Enable Track tax.
  5. Add a distance rate and leave Tax rate and Tax reclaimable on fields empty.
  6. Submit a distance expense in the workspace chat.
  7. Go to transaction thread.
  8. Click Rate.
  9. Select the other distance rate that does not have Tax rate and Tax reclaimable on.

Expected Result:

App will not crash.

Actual Result:

App crashes after selecting distance rate that has no Tax rate and Tax reclaimable on.

Crash happens when the rate has

  • no tax rate and no tax reclaimable
  • No tax rate and has tax reclaimable

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

2009_1.txt

Bug6610205_1726857577201.ScreenRecording_09-21-2024_02-34-46_1.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021838672839174830384
  • Upwork Job ID: 1838672839174830384
  • Last Price Increase: 2024-10-01
  • Automatic offers:
    • nkdengineer | Contributor | 104224449
Issue OwnerCurrent Issue Owner: @aimane-chnaif
@IuliiaHerets IuliiaHerets added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Sep 20, 2024
Copy link

melvin-bot bot commented Sep 20, 2024

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

@IuliiaHerets
Copy link
Author

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

@IuliiaHerets
Copy link
Author

@OfstadC 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

@etCoderDysto
Copy link
Contributor

Proposal

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

Distance - App crashes after selecting rate that has no Tax rate & Tax reclaimable on

What is the root cause of that problem?

We are not adding optional chaining before value below

originalMessage.taxRate = transactionChanges?.taxCode && policy?.taxRates?.taxes[transactionChanges?.taxCode].value;

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

Add optional chaining before value

originalMessage.taxRate = transactionChanges?.taxCode && policy?.taxRates?.taxes[transactionChanges?.taxCode]?.value;

What alternative solutions did you explore? (Optional)

@nkdengineer
Copy link
Contributor

Proposal

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

App crashes after selecting distance rate that has no Tax rate and Tax reclaimable on.

What is the root cause of that problem?

When track tax is enabled and we select the rate that has no tax rate, taxRateExternalID here is -1

taxRateExternalID = policyCustomUnitRate?.attributes?.taxRateExternalID ?? '-1';
const taxableAmount = DistanceRequestUtils.getTaxableAmount(policy, customUnitRateID, TransactionUtils.getDistanceInMeters(transaction, unit));
const taxPercentage = TransactionUtils.getTaxValue(policy, transaction, taxRateExternalID) ?? '';
taxAmount = CurrencyUtils.convertToBackendAmount(TransactionUtils.calculateTaxAmount(taxPercentage, taxableAmount, rates[customUnitRateID].currency ?? CONST.CURRENCY.USD));
IOU.setMoneyRequestTaxAmount(transactionID, taxAmount);
IOU.setMoneyRequestTaxRate(transactionID, taxRateExternalID);
}
if (currentRateID !== customUnitRateID) {
IOU.setMoneyRequestDistanceRate(transactionID, customUnitRateID, policy?.id ?? '-1', !isEditing);
if (isEditing) {
IOU.updateMoneyRequestDistanceRate(transaction?.transactionID ?? '-1', reportID, customUnitRateID, policy, policyTags, policyCategories, taxAmount, taxRateExternalID);

Then here we passed it to transactionChanges because updatedTaxCode is not empty

App/src/libs/actions/IOU.ts

Lines 3176 to 3180 in 513e6b3

const transactionChanges: TransactionChanges = {
customUnitRateID: rateID,
...(typeof updatedTaxAmount === 'number' ? {taxAmount: updatedTaxAmount} : {}),
...(updatedTaxCode ? {taxCode: updatedTaxCode} : {}),
};

Then the app crashes here because policy?.taxRates?.taxes[transactionChanges?.taxCode] is undefined with transactionChanges?.taxCode as -1

App/src/libs/ReportUtils.ts

Lines 3475 to 3477 in 8383570

if (didTaxCodeChange && !didAmountOrCurrencyChange) {
originalMessage.oldTaxRate = policy?.taxRates?.taxes[TransactionUtils.getTaxCode(oldTransaction)]?.value;
originalMessage.taxRate = transactionChanges?.taxCode && policy?.taxRates?.taxes[transactionChanges?.taxCode].value;

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

Safely get the value field here

policy?.taxRates?.taxes[transactionChanges?.taxCode]?.value

App/src/libs/ReportUtils.ts

Lines 3475 to 3477 in 8383570

if (didTaxCodeChange && !didAmountOrCurrencyChange) {
originalMessage.oldTaxRate = policy?.taxRates?.taxes[TransactionUtils.getTaxCode(oldTransaction)]?.value;
originalMessage.taxRate = transactionChanges?.taxCode && policy?.taxRates?.taxes[transactionChanges?.taxCode].value;

And we can fallback taxRateExternalID as empty string

taxRateExternalID = policyCustomUnitRate?.attributes?.taxRateExternalID ?? '-1';
const taxableAmount = DistanceRequestUtils.getTaxableAmount(policy, customUnitRateID, TransactionUtils.getDistanceInMeters(transaction, unit));
const taxPercentage = TransactionUtils.getTaxValue(policy, transaction, taxRateExternalID) ?? '';
taxAmount = CurrencyUtils.convertToBackendAmount(TransactionUtils.calculateTaxAmount(taxPercentage, taxableAmount, rates[customUnitRateID].currency ?? CONST.CURRENCY.USD));
IOU.setMoneyRequestTaxAmount(transactionID, taxAmount);
IOU.setMoneyRequestTaxRate(transactionID, taxRateExternalID);
}
if (currentRateID !== customUnitRateID) {
IOU.setMoneyRequestDistanceRate(transactionID, customUnitRateID, policy?.id ?? '-1', !isEditing);
if (isEditing) {
IOU.updateMoneyRequestDistanceRate(transaction?.transactionID ?? '-1', reportID, customUnitRateID, policy, policyTags, policyCategories, taxAmount, taxRateExternalID);

or add a check here to not add taxCode to transactionChanges if it's -1

)updatedTaxCode && updatedTaxCode !== '-1') ? {taxCode: updatedTaxCode} : {}

App/src/libs/actions/IOU.ts

Lines 3176 to 3180 in 513e6b3

const transactionChanges: TransactionChanges = {
customUnitRateID: rateID,
...(typeof updatedTaxAmount === 'number' ? {taxAmount: updatedTaxAmount} : {}),
...(updatedTaxCode ? {taxCode: updatedTaxCode} : {}),
};

What alternative solutions did you explore? (Optional)

NA

@OfstadC
Copy link
Contributor

OfstadC commented Sep 23, 2024

Added to Wave Collect - will confirm before adding External

@melvin-bot melvin-bot bot removed the Overdue label Sep 23, 2024
@trjExpensify trjExpensify changed the title Distance - App crashes after selecting rate that has no Tax rate & Tax reclaimable on [P2P Distance] App crashes after selecting rate that has no Tax rate & Tax reclaimable on Sep 23, 2024
@OfstadC OfstadC added the External Added to denote the issue can be worked on by a contributor label Sep 24, 2024
@melvin-bot melvin-bot bot changed the title [P2P Distance] App crashes after selecting rate that has no Tax rate & Tax reclaimable on [$250] [P2P Distance] App crashes after selecting rate that has no Tax rate & Tax reclaimable on Sep 24, 2024
Copy link

melvin-bot bot commented Sep 24, 2024

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

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

melvin-bot bot commented Sep 24, 2024

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

@OfstadC
Copy link
Contributor

OfstadC commented Oct 1, 2024

@aimane-chnaif could you please review the proposal? Thank you 😃

Copy link

melvin-bot bot commented Oct 1, 2024

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

@aimane-chnaif
Copy link
Contributor

@nkdengineer's proposal looks good to me.

  1. policy?.taxRates?.taxes[transactionChanges?.taxCode]?.value
  2. fallback taxRateExternalID as empty string
  3. updatedTaxCode && updatedTaxCode !== '-1'

All proposed solutions work but I prefer 1.

🎀👀🎀 C+ reviewed

(I didn't select first proposal because the root cause is not clear enough)

Copy link

melvin-bot bot commented Oct 1, 2024

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

@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Oct 2, 2024
Copy link

melvin-bot bot commented Oct 2, 2024

📣 @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 added Reviewing Has a PR in review and removed Daily KSv2 labels Oct 3, 2024
@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels Oct 3, 2024
@melvin-bot melvin-bot bot changed the title [$250] [P2P Distance] App crashes after selecting rate that has no Tax rate & Tax reclaimable on [HOLD for payment 2024-10-14] [$250] [P2P Distance] App crashes after selecting rate that has no Tax rate & Tax reclaimable on Oct 7, 2024
Copy link

melvin-bot bot commented Oct 7, 2024

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

@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Oct 7, 2024
Copy link

melvin-bot bot commented Oct 7, 2024

The solution for this issue has been 🚀 deployed to production 🚀 in version 9.0.45-4 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 2024-10-14. 🎊

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

Copy link

melvin-bot bot commented Oct 7, 2024

BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

  • [@aimane-chnaif] The PR that introduced the bug has been identified. Link to the PR:
  • [@aimane-chnaif] 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:
  • [@aimane-chnaif] A discussion in #expensify-bugs 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:
  • [@aimane-chnaif] Determine if we should create a regression test for this bug.
  • [@aimane-chnaif] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.
  • [@OfstadC] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

@OfstadC
Copy link
Contributor

OfstadC commented Oct 10, 2024

@aimane-chnaif Please complete the BZ checklist so I can issue payment on the 14th. Thank you! 😃

@aimane-chnaif
Copy link
Contributor

  • The PR that introduced the bug has been identified. Link to the PR: feat: add edit fields for tax tracking #33927
  • 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: feat: add edit fields for tax tracking #33927 (comment)
  • A discussion in #expensify-bugs 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

Regression Test Proposal

  1. Create a new workspace.
  2. Enable Distance rates and Taxes.
  3. Go to Distance rates > Settings > Enable Track tax.
  4. Add a distance rate and leave Tax rate and Tax reclaimable on fields empty.
  5. Submit a distance expense in the workspace chat.
  6. Go to transaction thread.
  7. Click Rate.
  8. Select the other distance rate that does not have Tax rate and Tax reclaimable on.
  9. Verify that app does not crash

@OfstadC
Copy link
Contributor

OfstadC commented Oct 14, 2024

Thanks @aimane-chnaif ! Could you please accept this offer so I can issue payment? 😃

@OfstadC
Copy link
Contributor

OfstadC commented Oct 14, 2024

Payment Summary

@melvin-bot melvin-bot bot added Daily KSv2 and removed Weekly KSv2 labels Oct 14, 2024
@OfstadC
Copy link
Contributor

OfstadC commented Oct 17, 2024

Will close once @aimane-chnaif accepts Upwork offer 😃

@melvin-bot melvin-bot bot added the Overdue label Oct 17, 2024
@OfstadC OfstadC closed this as completed Oct 17, 2024
@melvin-bot melvin-bot bot removed the Overdue label Oct 17, 2024
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
No open projects
Status: Polish
Development

No branches or pull requests

6 participants