Skip to content

Set testing receipt as scan complete and hardcode known data #59573

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

Merged
merged 3 commits into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3543,7 +3543,9 @@ const CONST = {
TEST_RECEIPT: {
AMOUNT: 1800,
CURRENCY: 'USD',
MERCHANT: "Taco Todd's",
FILENAME: 'test_receipt',
FILE_TYPE: 'image/png',
},

AVATAR_CROP_MODAL: {
Expand Down
2 changes: 2 additions & 0 deletions src/libs/DebugUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,7 @@ function validateReportActionDraftProperty(key: keyof ReportAction, value: strin
source: 'string',
filename: 'string',
reservationList: 'string',
isTestReceipt: 'boolean',
});
case 'childRecentReceiptTransactionIDs':
return validateObject<ObjectElement<ReportAction, 'childRecentReceiptTransactionIDs'>>(value, {}, 'string');
Expand Down Expand Up @@ -1060,6 +1061,7 @@ function validateTransactionDraftProperty(key: keyof Transaction, value: string)
state: CONST.IOU.RECEIPT_STATE,
receiptID: 'number',
reservationList: 'array',
isTestReceipt: 'boolean',
});
case 'taxRate':
return validateObject<ObjectElement<Transaction, 'taxRate'>>(value, {
Expand Down
12 changes: 7 additions & 5 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -934,9 +934,10 @@ function setSplitPayer(transactionID: string, payerAccountID: number) {
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {splitPayerAccountIDs: [payerAccountID]});
}

function setMoneyRequestReceipt(transactionID: string, source: string, filename: string, isDraft: boolean, type?: string) {
function setMoneyRequestReceipt(transactionID: string, source: string, filename: string, isDraft: boolean, type?: string, isTestReceipt = false) {
Onyx.merge(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {
receipt: {source, type: type ?? ''},
// isTestReceipt = false is being converted to null because we don't really need to store it in Onyx in that case
receipt: {source, type: type ?? '', isTestReceipt: isTestReceipt ? true : null},
filename,
});
}
Expand Down Expand Up @@ -1333,14 +1334,15 @@ function buildOnyxDataForMoneyRequest(moneyRequestParams: BuildOnyxDataForMoneyR

if (isMoneyRequestToManagerMcTest) {
const date = new Date();
const isTestReceipt = transaction.receipt?.isTestReceipt ?? false;
const managerMcTestParticipant = getManagerMcTestParticipant() ?? {};
const optimisticIOUReportAction = buildOptimisticIOUReportAction({
type: isScanRequest ? CONST.IOU.REPORT_ACTION_TYPE.CREATE : CONST.IOU.REPORT_ACTION_TYPE.PAY,
type: isScanRequest && !isTestReceipt ? CONST.IOU.REPORT_ACTION_TYPE.CREATE : CONST.IOU.REPORT_ACTION_TYPE.PAY,
amount: iou.report?.total ?? 0,
currency: iou.report?.currency ?? '',
comment: '',
participants: [managerMcTestParticipant],
paymentType: isScanRequest ? undefined : CONST.IOU.PAYMENT_TYPE.ELSEWHERE,
paymentType: isScanRequest && !isTestReceipt ? undefined : CONST.IOU.PAYMENT_TYPE.ELSEWHERE,
iouReportID: iou.report.reportID,
transactionID: transaction.transactionID,
});
Expand All @@ -1356,7 +1358,7 @@ function buildOnyxDataForMoneyRequest(moneyRequestParams: BuildOnyxDataForMoneyR
key: `${ONYXKEYS.COLLECTION.REPORT}${iou.report.reportID}`,
value: {
...iou.report,
...(!isScanRequest ? {lastActionType: CONST.REPORT.ACTIONS.TYPE.MARKED_REIMBURSED, statusNum: CONST.REPORT.STATUS_NUM.REIMBURSED} : undefined),
...(!isScanRequest || isTestReceipt ? {lastActionType: CONST.REPORT.ACTIONS.TYPE.MARKED_REIMBURSED, statusNum: CONST.REPORT.STATUS_NUM.REIMBURSED} : undefined),
hasOutstandingChildRequest: false,
lastActorAccountID: currentUserPersonalDetails?.accountID,
},
Expand Down
14 changes: 10 additions & 4 deletions src/pages/iou/request/step/IOURequestStepConfirmation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,12 @@ function IOURequestStepConfirmation({

const onSuccess = (file: File) => {
const receipt: Receipt = file;
receipt.state = file && requestType === CONST.IOU.REQUEST_TYPE.MANUAL ? CONST.IOU.RECEIPT_STATE.OPEN : CONST.IOU.RECEIPT_STATE.SCANREADY;
if (transaction?.receipt?.isTestReceipt) {
receipt.isTestReceipt = true;
receipt.state = CONST.IOU.RECEIPT_STATE.SCANCOMPLETE;
} else {
receipt.state = file && requestType === CONST.IOU.REQUEST_TYPE.MANUAL ? CONST.IOU.RECEIPT_STATE.OPEN : CONST.IOU.RECEIPT_STATE.SCANREADY;
}

setReceiptFile(receipt);
};
Expand All @@ -368,6 +373,7 @@ function IOURequestStepConfirmation({
if (!participant) {
return;
}
const isTestReceipt = receiptObj?.isTestReceipt ?? false;
requestMoneyIOUActions({
report,
participantParams: {
Expand All @@ -383,11 +389,11 @@ function IOURequestStepConfirmation({
gpsPoints,
action,
transactionParams: {
amount: transaction.amount,
amount: isTestReceipt ? CONST.TEST_RECEIPT.AMOUNT : transaction.amount,
attendees: transaction.comment?.attendees,
currency: transaction.currency,
currency: isTestReceipt ? CONST.TEST_RECEIPT.CURRENCY : transaction.currency,
created: transaction.created,
merchant: transaction.merchant,
merchant: isTestReceipt ? CONST.TEST_RECEIPT.MERCHANT : transaction.merchant,
comment: trimmedComment,
receipt: receiptObj,
category: transaction.category,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,15 +507,15 @@ function IOURequestStepScan({
const file: FileObject = {
uri: `file://${path}`,
name: filename,
type: 'image/png',
type: CONST.TEST_RECEIPT.FILE_TYPE,
size: 0,
};

if (!file.uri) {
return;
}

setMoneyRequestReceipt(transactionID, file.uri, filename, !isEditing, file.type);
setMoneyRequestReceipt(transactionID, file.uri, filename, !isEditing, file.type, true);
navigateToConfirmationStep(file, file.uri, false, true);
})
.catch((error) => {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/iou/request/step/IOURequestStepScan/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -571,13 +571,13 @@ function IOURequestStepScan({
filename,
(file) => {
const source = URL.createObjectURL(file);
setMoneyRequestReceipt(transactionID, source, filename, !isEditing, undefined);
setMoneyRequestReceipt(transactionID, source, filename, !isEditing, CONST.TEST_RECEIPT.FILE_TYPE, true);
navigateToConfirmationStep(file, source, false, true);
},
(error) => {
console.error('Error reading test receipt:', error);
},
'image/png',
CONST.TEST_RECEIPT.FILE_TYPE,
);
} catch (error) {
console.error('Error in setTestReceiptAndNavigate:', error);
Expand Down
3 changes: 3 additions & 0 deletions src/types/onyx/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ type Receipt = {

/** Collection of reservations */
reservationList?: Reservation[];

/** Receipt is [email protected] testing receipt */
isTestReceipt?: true;
};

/** Model of route */
Expand Down