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

Disable pay button when the expense report currency is different than workspace currency #39684

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
4 changes: 2 additions & 2 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function MoneyReportHeader({session, policy, chatReport, nextStep, report: money
const [isHoldMenuVisible, setIsHoldMenuVisible] = useState(false);
const [paymentType, setPaymentType] = useState<PaymentMethodType>();
const [requestType, setRequestType] = useState<'pay' | 'approve'>();
const canAllowSettlement = ReportUtils.hasUpdatedTotal(moneyRequestReport);
const canAllowSettlement = ReportUtils.hasUpdatedTotal(moneyRequestReport, policy);
const policyType = policy?.type;
const isPayer = ReportUtils.isPayer(session, moneyRequestReport);
const isDraft = ReportUtils.isOpenExpenseReport(moneyRequestReport);
Expand Down Expand Up @@ -106,7 +106,7 @@ function MoneyReportHeader({session, policy, chatReport, nextStep, report: money
const shouldShowAnyButton = shouldShowSettlementButton || shouldShowApproveButton || shouldShowSubmitButton || shouldShowNextStep;
const bankAccountRoute = ReportUtils.getBankAccountRoute(chatReport);
const formattedAmount = CurrencyUtils.convertToDisplayString(reimbursableSpend, moneyRequestReport.currency);
const [nonHeldAmount, fullAmount] = ReportUtils.getNonHeldAndFullAmount(moneyRequestReport);
const [nonHeldAmount, fullAmount] = ReportUtils.getNonHeldAndFullAmount(moneyRequestReport, policy);
const displayedAmount = ReportUtils.hasHeldExpenses(moneyRequestReport.reportID) && canAllowSettlement ? nonHeldAmount : formattedAmount;
const isMoreContentShown = shouldShowNextStep || (shouldShowAnyButton && isSmallScreenWidth);

Expand Down
2 changes: 1 addition & 1 deletion src/components/ReportActionItem/MoneyReportView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function MoneyReportView({report, policy, shouldShowHorizontalRule}: MoneyReport
const {translate} = useLocalize();
const {isSmallScreenWidth} = useWindowDimensions();
const isSettled = ReportUtils.isSettled(report.reportID);
const isTotalUpdated = ReportUtils.hasUpdatedTotal(report);
const isTotalUpdated = ReportUtils.hasUpdatedTotal(report, policy);

const {totalDisplaySpend, nonReimbursableSpend, reimbursableSpend} = ReportUtils.getMoneyRequestSpendBreakdown(report);

Expand Down
2 changes: 1 addition & 1 deletion src/components/ReportActionItem/ReportPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function ReportPreview({
const isOpenExpenseReport = isPolicyExpenseChat && ReportUtils.isOpenExpenseReport(iouReport);

const isApproved = ReportUtils.isReportApproved(iouReport);
const canAllowSettlement = ReportUtils.hasUpdatedTotal(iouReport);
const canAllowSettlement = ReportUtils.hasUpdatedTotal(iouReport, policy);
const allTransactions = TransactionUtils.getAllReportTransactions(iouReportID);
const transactionsWithReceipts = ReportUtils.getTransactionsWithReceipts(iouReportID);
const numberOfScanningReceipts = transactionsWithReceipts.filter((transaction) => TransactionUtils.isReceiptBeingScanned(transaction)).length;
Expand Down
9 changes: 5 additions & 4 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5477,26 +5477,27 @@ function shouldDisplayThreadReplies(reportAction: OnyxEntry<ReportAction>, repor
/**
* Check if money report has any transactions updated optimistically
*/
function hasUpdatedTotal(report: OnyxEntry<Report>): boolean {
function hasUpdatedTotal(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>): boolean {
if (!report) {
return true;
}

const transactions = TransactionUtils.getAllReportTransactions(report.reportID);
const hasPendingTransaction = transactions.some((transaction) => !!transaction.pendingAction);
const hasTransactionWithDifferentCurrency = transactions.some((transaction) => transaction.currency !== report.currency);
const hasDifferentWorkspaceCurrency = report.pendingFields?.createChat && isExpenseReport(report) && report.currency !== policy?.outputCurrency;

return !(hasPendingTransaction && hasTransactionWithDifferentCurrency) && !(hasHeldExpenses(report.reportID) && report?.unheldTotal === undefined);
return !(hasPendingTransaction && (hasTransactionWithDifferentCurrency || hasDifferentWorkspaceCurrency)) && !(hasHeldExpenses(report.reportID) && report?.unheldTotal === undefined);
}

/**
* Return held and full amount formatted with used currency
*/
function getNonHeldAndFullAmount(iouReport: OnyxEntry<Report>): string[] {
function getNonHeldAndFullAmount(iouReport: OnyxEntry<Report>, policy: OnyxEntry<Policy>): string[] {
const transactions = TransactionUtils.getAllReportTransactions(iouReport?.reportID ?? '');
const hasPendingTransaction = transactions.some((transaction) => !!transaction.pendingAction);

if (hasUpdatedTotal(iouReport) && hasPendingTransaction) {
if (hasUpdatedTotal(iouReport, policy) && hasPendingTransaction) {
const unheldTotal = transactions.reduce((currentVal, transaction) => currentVal - (!TransactionUtils.isOnHold(transaction) ? transaction.amount : 0), 0);

return [CurrencyUtils.convertToDisplayString(unheldTotal, iouReport?.currency ?? ''), CurrencyUtils.convertToDisplayString((iouReport?.total ?? 0) * -1, iouReport?.currency ?? '')];
Expand Down
Loading