Skip to content
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
19 changes: 10 additions & 9 deletions src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import {
getTagForDisplay,
getTaxName,
hasMissingSmartscanFields,
hasReceipt,
hasReservationList,
hasRoute as hasRouteTransactionUtils,
isCardTransaction as isCardTransactionTransactionUtils,
Expand Down Expand Up @@ -194,9 +195,15 @@ function MoneyRequestView({
// Use the updated transaction amount in merge flow to have correct positive/negative sign
const actualAmount = isFromMergeTransaction && updatedTransaction ? updatedTransaction.amount : transactionAmount;
Comment thread
Gonals marked this conversation as resolved.
const actualCurrency = updatedTransaction ? getCurrency(updatedTransaction) : transactionCurrency;
const shouldDisplayTransactionAmount = ((isDistanceRequest && hasRoute) || !!actualAmount) && actualAmount !== undefined;
const shouldDisplayTransactionAmount = useMemo(() => {
return (
((isDistanceRequest && hasRoute) || (!!actualAmount && hasReceipt(updatedTransaction ?? transaction)) || !hasReceipt(updatedTransaction ?? transaction)) &&
actualAmount !== undefined
);
}, [isDistanceRequest, hasRoute, actualAmount, updatedTransaction, transaction]);
const formattedTransactionAmount = shouldDisplayTransactionAmount ? convertToDisplayString(actualAmount, actualCurrency) : '';
const formattedPerAttendeeAmount = shouldDisplayTransactionAmount ? convertToDisplayString(actualAmount / (transactionAttendees?.length ?? 1), actualCurrency) : '';
const formattedPerAttendeeAmount =
shouldDisplayTransactionAmount && actualAmount !== undefined ? convertToDisplayString(actualAmount / (transactionAttendees?.length ?? 1), actualCurrency) : '';

const formattedOriginalAmount = transactionOriginalAmount && transactionOriginalCurrency && convertToDisplayString(transactionOriginalAmount, transactionOriginalCurrency);
const isCardTransaction = isCardTransactionTransactionUtils(transaction);
Expand Down Expand Up @@ -298,7 +305,7 @@ function MoneyRequestView({
const rateToDisplay = isCustomUnitOutOfPolicy ? translate('common.rateOutOfPolicy') : DistanceRequestUtils.getRateForDisplay(unit, rate, currency, translate, toLocaleDigit, isOffline);
const distanceToDisplay = DistanceRequestUtils.getDistanceForDisplay(hasRoute, distance, unit, rate, translate);
let merchantTitle = isEmptyMerchant ? '' : transactionMerchant;
let amountTitle = formattedTransactionAmount ? formattedTransactionAmount.toString() : '';
let amountTitle = formattedTransactionAmount?.toString() || '';
if (isTransactionScanning) {
merchantTitle = translate('iou.receiptStatusTitle');
amountTitle = translate('iou.receiptStatusTitle');
Expand Down Expand Up @@ -371,10 +378,6 @@ function MoneyRequestView({
// Checks applied when creating a new expense
// NOTE: receipt field can return multiple violations, so we need to handle it separately
const fieldChecks: Partial<Record<ViolationField, {isError: boolean; translationPath: TranslationPaths}>> = {
amount: {
isError: transactionAmount === 0,
translationPath: canEditAmount ? 'common.error.enterAmount' : 'common.error.missingAmount',
},
merchant: {
isError: !isSettled && !isCancelled && isPolicyExpenseChat && isEmptyMerchant,
translationPath: canEditMerchant ? 'common.error.enterMerchant' : 'common.error.missingMerchantName',
Expand Down Expand Up @@ -413,7 +416,6 @@ function MoneyRequestView({
return '';
},
[
transactionAmount,
isSettled,
isCancelled,
isPolicyExpenseChat,
Expand All @@ -424,7 +426,6 @@ function MoneyRequestView({
hasViolations,
translate,
getViolationsForField,
canEditAmount,
canEditDate,
canEditMerchant,
canEdit,
Expand Down
3 changes: 2 additions & 1 deletion src/libs/TransactionPreviewUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
hasMissingSmartscanFields,
hasNoticeTypeViolation,
hasPendingRTERViolation,
hasReceipt,
hasViolation,
hasWarningTypeViolation,
isAmountMissing,
Expand Down Expand Up @@ -237,7 +238,7 @@ function getTransactionPreviewTextAndTranslationPaths({

if (hasFieldErrors && RBRMessage === undefined) {
const merchantMissing = isMerchantMissing(transaction);
const amountMissing = isAmountMissing(transaction);
const amountMissing = isAmountMissing(transaction) && hasReceipt(transaction);
Comment thread
Gonals marked this conversation as resolved.
if (amountMissing && merchantMissing) {
RBRMessage = {translationPath: 'violations.reviewRequired'};
} else if (amountMissing) {
Expand Down
3 changes: 2 additions & 1 deletion src/libs/TransactionUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@

let allTransactions: OnyxCollection<Transaction> = {};

Onyx.connect({

Check warning on line 118 in src/libs/TransactionUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -127,7 +127,7 @@
});

let allReports: OnyxCollection<Report> = {};
Onyx.connect({

Check warning on line 130 in src/libs/TransactionUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -136,7 +136,7 @@
});

let allTransactionViolations: OnyxCollection<TransactionViolations> = {};
Onyx.connect({

Check warning on line 139 in src/libs/TransactionUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS,
waitForCollectionCallback: true,
callback: (value) => (allTransactionViolations = value),
Expand All @@ -144,7 +144,7 @@

let currentUserEmail = '';
let currentUserAccountID = -1;
Onyx.connect({

Check warning on line 147 in src/libs/TransactionUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (val) => {
currentUserEmail = val?.email ?? '';
Expand Down Expand Up @@ -445,7 +445,8 @@
const isFromExpenseReport = parentReport?.type === CONST.REPORT.TYPE.EXPENSE;
const isSplitPolicyExpenseChat = !!transaction?.comment?.splits?.some((participant) => allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${participant.chatReportID}`]?.isOwnPolicyExpenseChat);
const isMerchantRequired = isFromExpenseReport || isSplitPolicyExpenseChat;
return (isMerchantRequired && isMerchantMissing(transaction)) || isAmountMissing(transaction) || isCreatedMissing(transaction);
const isAmountRequired = hasReceipt(transaction);
Comment thread
Gonals marked this conversation as resolved.
return (isMerchantRequired && isMerchantMissing(transaction)) || (isAmountMissing(transaction) && isAmountRequired) || isCreatedMissing(transaction);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/pages/iou/MoneyRequestAmountForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type MoneyRequestAmountFormProps = Omit<MoneyRequestAmountInputProps, 'shouldSho
chatReportID?: string;
};

const isAmountInvalid = (amount: string) => !amount.length || parseFloat(amount) < 0.01;
const isAmountInvalid = (amount: string) => !amount.length || parseFloat(amount) < 0;
Comment thread
stitesExpensify marked this conversation as resolved.
const isTaxAmountInvalid = (currentAmount: string, taxAmount: number, isTaxAmountForm: boolean, currency: string) =>
isTaxAmountForm && Number.parseFloat(currentAmount) > convertToFrontendAmountAsInteger(Math.abs(taxAmount), currency);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ function IOURequestStepDistanceManual({

const submitAndNavigateToNextPage = useCallback(() => {
const value = numberFormRef.current?.getNumber() ?? '';
if (!value.length || parseFloat(value) < 0.01) {
if (!value.length || parseFloat(value) < 0) {
setFormError(translate('iou.error.invalidDistance'));
return;
}
Expand Down
25 changes: 15 additions & 10 deletions tests/unit/DebugUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1250,8 +1250,9 @@ describe('DebugUtils', () => {
};
await Onyx.multiSet({
[`${ONYXKEYS.COLLECTION.TRANSACTION}1` as const]: {
amount: 0,
modifiedAmount: 0,
amount: 100,
created: '',
modifiedCreated: '',
},
[`${ONYXKEYS.COLLECTION.REPORT}1` as const]: MOCK_IOU_REPORT,
[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1` as const]: MOCK_REPORT_ACTIONS,
Expand Down Expand Up @@ -1310,8 +1311,9 @@ describe('DebugUtils', () => {
};
await Onyx.multiSet({
[`${ONYXKEYS.COLLECTION.TRANSACTION}1` as const]: {
amount: 0,
modifiedAmount: 0,
amount: 100,
created: '',
modifiedCreated: '',
},
[`${ONYXKEYS.COLLECTION.REPORT}1` as const]: MOCK_IOU_REPORT,
[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1` as const]: MOCK_REPORT_ACTIONS,
Expand Down Expand Up @@ -1369,8 +1371,9 @@ describe('DebugUtils', () => {
};
await Onyx.multiSet({
[`${ONYXKEYS.COLLECTION.TRANSACTION}1` as const]: {
amount: 0,
modifiedAmount: 0,
amount: 100,
created: '',
modifiedCreated: '',
},
[`${ONYXKEYS.COLLECTION.REPORT}1` as const]: MOCK_CHAT_REPORT,
[`${ONYXKEYS.COLLECTION.REPORT}2` as const]: MOCK_IOU_REPORT,
Expand Down Expand Up @@ -1434,8 +1437,9 @@ describe('DebugUtils', () => {
};
await Onyx.multiSet({
[`${ONYXKEYS.COLLECTION.TRANSACTION}1` as const]: {
amount: 0,
modifiedAmount: 0,
amount: 100,
created: '',
modifiedCreated: '',
},
[`${ONYXKEYS.COLLECTION.REPORT}1` as const]: MOCK_CHAT_REPORT,
[`${ONYXKEYS.COLLECTION.REPORT}2` as const]: MOCK_IOU_REPORT,
Expand Down Expand Up @@ -1493,8 +1497,9 @@ describe('DebugUtils', () => {
};
await Onyx.multiSet({
[`${ONYXKEYS.COLLECTION.TRANSACTION}1` as const]: {
amount: 0,
modifiedAmount: 0,
amount: 100,
created: '',
modifiedCreated: '',
},
[`${ONYXKEYS.COLLECTION.REPORT}1` as const]: MOCK_IOU_REPORT,
[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1` as const]: MOCK_REPORT_ACTIONS,
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7133,7 +7133,8 @@ describe('ReportUtils', () => {
const transaction: Transaction = {
...createRandomTransaction(12345),
reportID: parentReport.reportID,
amount: 0,
created: '',
modifiedCreated: '',
};
await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`, transaction);
await waitForBatchedUpdates();
Expand All @@ -7158,7 +7159,8 @@ describe('ReportUtils', () => {
const transaction: Transaction = {
...createRandomTransaction(12345),
reportID: parentReport.reportID,
amount: 0,
created: '',
modifiedCreated: '',
};
await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`, transaction);
await waitForBatchedUpdates();
Expand Down
12 changes: 10 additions & 2 deletions tests/unit/TransactionPreviewUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,20 @@ describe('TransactionPreviewUtils', () => {
expect(result.displayAmountText.text).toEqual('$0.00');
});

it('returns merchant missing and amount missing message when appropriate', () => {
it('returns violations.reviewRequired when transaction has receipt with missing merchant and amount', async () => {
// Set up a proper expense report in Onyx
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}1`, {
reportID: '1',
type: 'expense',
});
await waitForBatchedUpdates();

const functionArgs = {
...basicProps,
transaction: {...basicProps.transaction, merchant: '', amount: 0},
transaction: {...basicProps.transaction, merchant: '', amount: 0, receipt: {source: 'test-receipt.jpg', state: CONST.IOU.RECEIPT_STATE.SCAN_COMPLETE}},
originalTransaction: undefined,
shouldShowRBR: true,
isReportAPolicyExpenseChat: true,
};
const result = getTransactionPreviewTextAndTranslationPaths(functionArgs);
expect(result.RBRMessage.translationPath).toEqual('violations.reviewRequired');
Expand Down
Loading