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

FIX: Implement pattern C for money reports with various currencies #35062

Merged
3 changes: 3 additions & 0 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function MoneyReportHeader({session, policy, chatReport, nextStep, report: money
const {reimbursableSpend} = ReportUtils.getMoneyRequestSpendBreakdown(moneyRequestReport);
const isApproved = ReportUtils.isReportApproved(moneyRequestReport);
const isSettled = ReportUtils.isSettled(moneyRequestReport.reportID);
const canAllowSettlement = ReportUtils.hasUpdatedTotal(moneyRequestReport);
const policyType = policy?.type;
const isPolicyAdmin = policyType !== CONST.POLICY.TYPE.PERSONAL && policy?.role === CONST.POLICY.ROLE.ADMIN;
const isAutoReimbursable = ReportUtils.canBeAutoReimbursed(moneyRequestReport, policy);
Expand Down Expand Up @@ -140,6 +141,7 @@ function MoneyReportHeader({session, policy, chatReport, nextStep, report: money
shouldShowApproveButton={shouldShowApproveButton}
style={[styles.pv2]}
formattedAmount={formattedAmount}
isDisabled={!canAllowSettlement}
/>
</View>
)}
Expand Down Expand Up @@ -171,6 +173,7 @@ function MoneyReportHeader({session, policy, chatReport, nextStep, report: money
shouldHidePaymentOptions={!shouldShowPayButton}
shouldShowApproveButton={shouldShowApproveButton}
formattedAmount={formattedAmount}
isDisabled={!canAllowSettlement}
/>
</View>
)}
Expand Down
3 changes: 2 additions & 1 deletion src/components/ReportActionItem/MoneyReportView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function MoneyReportView({report, policy, policyReportFields, shouldShowHorizont
const {isSmallScreenWidth} = useWindowDimensions();
const {canUseReportFields} = usePermissions();
const isSettled = ReportUtils.isSettled(report.reportID);
const isTotalUpdated = ReportUtils.hasUpdatedTotal(report);

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

Expand Down Expand Up @@ -119,7 +120,7 @@ function MoneyReportView({report, policy, policyReportFields, shouldShowHorizont
)}
<Text
numberOfLines={1}
style={[styles.taskTitleMenuItem, styles.alignSelfCenter]}
style={[styles.taskTitleMenuItem, styles.alignSelfCenter, !isTotalUpdated && styles.offlineFeedback.pending]}
>
{formattedTotalAmount}
</Text>
Expand Down
3 changes: 3 additions & 0 deletions src/components/ReportActionItem/ReportPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,11 @@ function ReportPreview({
const isDraftExpenseReport = isPolicyExpenseChat && ReportUtils.isDraftExpenseReport(iouReport);

const isApproved = ReportUtils.isReportApproved(iouReport);
const canAllowSettlement = ReportUtils.hasUpdatedTotal(iouReport);
const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(iouReport);
const transactionsWithReceipts = ReportUtils.getTransactionsWithReceipts(iouReportID);
const numberOfScanningReceipts = transactionsWithReceipts.filter((transaction) => TransactionUtils.isReceiptBeingScanned(transaction)).length;

const hasReceipts = transactionsWithReceipts.length > 0;
const isScanning = hasReceipts && areAllRequestsBeingSmartScanned;
const hasErrors = (hasReceipts && hasMissingSmartscanFields) || (canUseViolations && ReportUtils.hasViolations(iouReportID, transactionViolations));
Expand Down Expand Up @@ -307,6 +309,7 @@ function ReportPreview({
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.RIGHT,
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM,
}}
isDisabled={!canAllowSettlement}
/>
)}
{shouldShowSubmitButton && (
Expand Down
16 changes: 16 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4648,6 +4648,21 @@ function shouldDisplayThreadReplies(reportAction: OnyxEntry<ReportAction>, repor
return hasReplies && !!reportAction?.childCommenterCount && !isThreadFirstChat(reportAction, reportID);
}

/**
* Check if money report has any transactions updated optimistically
*/
function hasUpdatedTotal(report: OnyxEntry<Report>): 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);

return !(hasPendingTransaction && hasTransactionWithDifferentCurrency);
}

/**
* Disable reply in thread action if:
*
Expand Down Expand Up @@ -4946,6 +4961,7 @@ export {
isReportParticipant,
isValidReport,
isReportFieldOfTypeTitle,
hasUpdatedTotal,
isReportFieldDisabled,
getAvailableReportFields,
getAllAncestorReportActionIDs,
Expand Down
Loading