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

feat: Receipt Audit Feature / Note type violations. #37813

Merged
merged 52 commits into from
Apr 30, 2024

Conversation

Krishna2323
Copy link
Contributor

@Krishna2323 Krishna2323 commented Mar 6, 2024

Details

Fixed Issues

$ #36288
PROPOSAL: #36288 (comment)

Tests

  1. Employee: Submit a expense to a paid policy group without receipt
  2. Employee: Open the expense report page and verify there is a error message below empty receipt holder.
  3. Admin: Open the expense report page and verify there is a error message, also the empty receipt holder should be shown but it shouldn't be editable.
  4. Employee: Submit a expense to a paid policy group with a valid receipt
  5. Employee: Wait for receipt to be scanned and then verify the is a verified audit message shown above the receipt
  6. Employee: In previous step, if the entered detail doesn't match receipt it should show notes violations (errors) below the receipt.
  • Verify that no errors appear in the JS console

Offline tests

  1. Employee: Submit a expense to a paid policy group without receipt
  2. Employee: Open the expense report page and verify there is a error message below empty receipt holder.
  3. Admin: Open the expense report page and verify there is a error message, also the empty receipt holder should be shown but it shouldn't be editable.
  4. Employee: Submit a expense to a paid policy group with a valid receipt
  5. Employee: Wait for receipt to be scanned and then verify the is a verified audit message shown above the receipt
  6. Employee: In previous step, if the entered detail doesn't match receipt it should show notes violations (errors) below the receipt.

QA Steps

  1. Employee: Submit a expense to a paid policy group without receipt
  2. Employee: Open the expense report page and verify there is a error message below empty receipt holder.
  3. Admin: Open the expense report page and verify there is a error message, also the empty receipt holder should be shown but it shouldn't be editable.
  4. Employee: Submit a expense to a paid policy group with a valid receipt
  5. Employee: Wait for receipt to be scanned and then verify the is a verified audit message shown above the receipt
  6. Employee: In previous step, if the entered detail doesn't match receipt it should show notes violations (errors) below the receipt.
  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
android_native.mp4
Android: mWeb Chrome
android_chrome.mp4
iOS: Native
ios_native.mp4
iOS: mWeb Safari
ios_safari.mp4
MacOS: Chrome / Safari
web_chrome_v.mp4
MacOS: Desktop
desktop_app.mp4

Signed-off-by: Krishna Gupta <belivethatkg@gmail.com>
@Krishna2323 Krishna2323 requested a review from a team as a code owner March 6, 2024 08:07
@melvin-bot melvin-bot bot requested review from sobitneupane and removed request for a team March 6, 2024 08:07
Copy link

melvin-bot bot commented Mar 6, 2024

@sobitneupane Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@Krishna2323 Krishna2323 marked this pull request as draft March 6, 2024 08:07
Signed-off-by: Krishna Gupta <belivethatkg@gmail.com>
Signed-off-by: Krishna Gupta <belivethatkg@gmail.com>
Signed-off-by: Krishna Gupta <belivethatkg@gmail.com>
Signed-off-by: Krishna Gupta <belivethatkg@gmail.com>
Signed-off-by: Krishna Gupta <belivethatkg@gmail.com>
Signed-off-by: Krishna Gupta <belivethatkg@gmail.com>
@Krishna2323 Krishna2323 marked this pull request as ready for review March 7, 2024 06:53
@Krishna2323 Krishna2323 marked this pull request as draft March 7, 2024 06:53
@Krishna2323
Copy link
Contributor Author

Krishna2323 commented Mar 7, 2024

@JmillsExpensify @sobitneupane, the PR is nearly ready for review. However, before that, I have a few things left to implement based on the responses to the following questions.

  1. I believe we don't want to show ReceiptAudit component when a receipt is being scanned, is that correct?

  2. Do we need to check for beta access before showing ReceiptAudit? We only display ViolationMessages component when beta is enabled for the user.

  3. This is how it currently looks. I suppose we want to change the icons here?

receipt_approved receipt_audit

@sobitneupane
Copy link
Contributor

the PR is nearly ready for review. However, before that, I have a few things left to implement based on the responses to the following questions.

  1. I believe we don't want to show ReceiptAudit component when a receipt is being scanned, is that correct?

I would think so as we do show the scanning info.
Screenshot 2024-03-07 at 14 27 15

  1. Do we need to check for beta access before showing ReceiptAudit? We only display ViolationMessages component when beta is enabled for the user.

If we display ViolationMessages only when beta is enabled, than I believe we would like to do the same for ReceiptAudit as well.

  1. This is how it currently looks. I suppose we want to change the icons here?

For this, once you add the screen recording and screenshots, we can ask the design team to verify the design and icons.

Signed-off-by: Krishna Gupta <belivethatkg@gmail.com>
Signed-off-by: Krishna Gupta <belivethatkg@gmail.com>
@Krishna2323 Krishna2323 marked this pull request as ready for review March 8, 2024 11:23
@JmillsExpensify
Copy link

Let's make sure we get a design team member on this PR before it's merged!

@sobitneupane
Copy link
Contributor

@Krishna2323 Can you please add Tests and QA steps. You also need to fill PR Author checklist.

@Krishna2323
Copy link
Contributor Author

@sobitneupane, I don't know how to generate note type violations, do you have any clue? Test steps will be based on that.

src/languages/en.ts Outdated Show resolved Hide resolved
receiptAudit: 'Auditoría de recibos',
receiptVerified: 'Recibo verificado',
receiptNoIssuesFound: 'No se encontraron problemas',
receiptIssuesFound: (count: number) => `Se encontró ${count} problema(s)`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Krishna2323 Did we verify if it is the correct translation? We can ask for the correct translations in slack channel.

@@ -148,6 +151,8 @@ function MoneyRequestView({
(field: ViolationField, data?: OnyxTypes.TransactionViolation['data']): boolean => !!canUseViolations && getViolationsForField(field, data).length > 0,
[canUseViolations, getViolationsForField],
);
const noteTypeViolations = transactionViolations?.filter((violation) => violation.type === 'note').map((v) => ViolationsUtils.getViolationTranslation(v, translate));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Krishna2323 Is the violation type 'note' for such violations? What type do we use for violation messages? Can we reuse the existing method for violation messages? If you have any confusion, please do raise it on the issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sobitneupane, I guess we need to pass array of strings to ReceiptAudit component so we need to extract like this. The type for violation messages is violation.

return Boolean(transactionViolations?.[ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS + transactionID]?.some((violation: TransactionViolation) => violation.type === 'violation'));

@JmillsExpensify can you pls confirm if the type for note type violation is note?

Copy link
Contributor

@sobitneupane sobitneupane Mar 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Krishna2323 type for such violation is "notice"

[
    {
        "type": "notice",
        "name": "modifiedAmount",
        "data": null
    },
    {
        "type": "notice",
        "name": "modifiedDate",
        "data": null
    }
]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated!

Signed-off-by: Krishna Gupta <belivethatkg@gmail.com>
Comment on lines 604 to 607
receiptAudit: 'Receipt Audit',
receiptVerified: 'Receipt Verified',
receiptNoIssuesFound: 'No issues Found',
receiptIssuesFound: (count: number) => `${count} ${count === 1 ? 'Issue' : 'Issues'} Found`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
receiptAudit: 'Receipt Audit',
receiptVerified: 'Receipt Verified',
receiptNoIssuesFound: 'No issues Found',
receiptIssuesFound: (count: number) => `${count} ${count === 1 ? 'Issue' : 'Issues'} Found`,
receiptAudit: 'Receipt Audit',
receiptVerified: 'Receipt Verified',
receiptNoIssuesFound: 'No issues found',
receiptIssuesFound: (count: number) => `${count} ${count === 1 ? 'issue' : 'issues'} found`,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good 👀, thanks for that. Updated.

@sobitneupane
Copy link
Contributor

@Krishna2323 If there are any blockers or if you have any confusion, please don't hesitate to raise those concerns. Were you able to test the issue in your end? You need to be in Violations beta to receive those violations from BE.

@shawnborton
Copy link
Contributor

Just a heads up that we're going to have a few design changes to this before it gets merged - nothing major, just updating the badge style to repurpose our existing badge component.

cc @JmillsExpensify @Expensify/design - do we have a final consensus on the updated design yet?

lakchote
lakchote previously approved these changes Apr 29, 2024
@lakchote
Copy link
Contributor

Waiting for @cead22's review before merging for reasons mentioned just above.

src/languages/en.ts Outdated Show resolved Hide resolved
src/languages/en.ts Outdated Show resolved Hide resolved
src/languages/es.ts Outdated Show resolved Hide resolved
src/libs/TransactionUtils.ts Outdated Show resolved Hide resolved
src/components/ReportActionItem/MoneyRequestView.tsx Outdated Show resolved Hide resolved
src/components/ReceiptAudit.tsx Show resolved Hide resolved
src/components/ReceiptAudit.tsx Show resolved Hide resolved
@@ -370,7 +384,9 @@ function MoneyRequestView({
}
/>
)}
{canUseViolations && <ViolationMessages violations={getViolationsForField('receipt')} />}
{!(!hasReceipt && (canEditReceipt || isAdmin || isApprover)) && !(showMapAsImage || hasReceipt) && <View style={{marginVertical: 6}} />}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is impossible to read, please intermediate variables with self-explanatory names to simplify this

src/libs/TransactionUtils.ts Outdated Show resolved Hide resolved
src/libs/TransactionUtils.ts Outdated Show resolved Hide resolved
Signed-off-by: Krishna Gupta <belivethatkg@gmail.com>
@Krishna2323 Krishna2323 requested a review from cead22 April 29, 2024 21:27
@JmillsExpensify
Copy link

@Krishna2323 When you're back online, let's try to get these comments addressed and then get this merged. We're super close, I think we're in a position to cross this PR off the list in the next 24 hours.

@JmillsExpensify
Copy link

Ah shoot! Sorry I missed the updated. Going to reach back out to @cead22 for a re-review now. Thank you for the quick work!

src/components/ReceiptAudit.tsx Outdated Show resolved Hide resolved
src/components/ReceiptAudit.tsx Show resolved Hide resolved
// TODO: remove the !isTrackExpense from this condition after this fix: https://github.com/Expensify/Expensify/issues/382786
const canEditDistance = ReportUtils.canEditFieldOfMoneyRequest(parentReportAction, CONST.EDIT_REQUEST_FIELD.DISTANCE) && !isTrackExpense;

const isAdmin = policy?.role === 'admin';
const isApprover = ReportUtils.isMoneyRequestReport(moneyRequestReport) && (session?.accountID ?? null) === moneyRequestReport?.managerID;
Copy link
Contributor

@cead22 cead22 Apr 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second condition looks wrong, or at least it doesn't seem like we need the ?? null fallback. But also, don't we need to make sure moneyRequestReport?.managerID; isn't null? I think this should be

Suggested change
const isApprover = ReportUtils.isMoneyRequestReport(moneyRequestReport) && (session?.accountID ?? null) === moneyRequestReport?.managerID;
const isApprover = ReportUtils.isMoneyRequestReport(moneyRequestReport) && moneyRequestReport?.managerID !== null && session?.accountID === moneyRequestReport?.managerID;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took that condition from MoneyRequestHeader, but the suggested changes looks more accurate to me so I updated both instances.

const isApprover = ReportUtils.isMoneyRequestReport(moneyRequestReport) && (session?.accountID ?? null) === moneyRequestReport?.managerID;

src/components/ReportActionItem/MoneyRequestView.tsx Outdated Show resolved Hide resolved
@@ -324,12 +333,20 @@ function MoneyRequestView({
</OfflineWithFeedback>
);

const shouldShowReceiptEmptyState = !hasReceipt && (canEditReceipt || isAdmin || isApprover);
/* eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing */
const shouldShowMapOrReceipt = showMapAsImage || hasReceipt;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Let's move const showMapAsImage = isDistanceRequest && hasPendingWaypoints; above this line
  • Let's move const hasPendingWaypoints = transaction?.pendingFields?.waypoints; above that ^ line and make it const hasPendingWaypoints = Boolean(transaction?.pendingFields?.waypoints;)
    • That way hasPendingWaypoints is a bool
    • And we can remove the eslint rule suppression

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you pls check again.

src/components/ReportActionItem/MoneyRequestView.tsx Outdated Show resolved Hide resolved
src/components/ReportActionItem/MoneyRequestView.tsx Outdated Show resolved Hide resolved
Signed-off-by: Krishna Gupta <belivethatkg@gmail.com>
@Krishna2323 Krishna2323 requested a review from cead22 April 29, 2024 23:31
@cead22
Copy link
Contributor

cead22 commented Apr 29, 2024

@Krishna2323 changes look good, can you give this another round of testing and we can merge?

@Krishna2323
Copy link
Contributor Author

@cead22, tested, works well on my end.

@cead22 cead22 merged commit bfa9990 into Expensify:main Apr 30, 2024
21 checks passed
@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@JmillsExpensify
Copy link

Great work on this PR @Krishna2323!

@Krishna2323
Copy link
Contributor Author

@JmillsExpensify, thanks a lot for the acknowledgment! I'm glad you liked the work on the PR. Thanks to everyone for clearing all my doubts during the PR and specially @sobitneupane & @cead22 for their great review on the code changes. Excited to contribute more to Expensify!

@OSBotify
Copy link
Contributor

OSBotify commented May 1, 2024

🚀 Deployed to staging by https://github.com/cead22 in version: 1.4.69-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

OSBotify commented May 2, 2024

🚀 Deployed to production by https://github.com/Beamanator in version: 1.4.69-2 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants