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 @@ -55,6 +55,7 @@ function MoneyReportHeader({session, personalDetails, policy, chatReport, nextSt
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 @@ -141,6 +142,7 @@ function MoneyReportHeader({session, personalDetails, policy, chatReport, nextSt
shouldShowApproveButton={shouldShowApproveButton}
style={[styles.pv2]}
formattedAmount={formattedAmount}
isDisabled={!canAllowSettlement}
/>
</View>
)}
Expand Down Expand Up @@ -172,6 +174,7 @@ function MoneyReportHeader({session, personalDetails, policy, chatReport, nextSt
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 @@ -50,6 +50,7 @@ function MoneyReportView({report, policyReportFields, shouldShowHorizontalRule,
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 @@ -121,7 +122,7 @@ function MoneyReportView({report, policyReportFields, shouldShowHorizontalRule,
)}
<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 @@ -304,6 +306,7 @@ function ReportPreview({
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.RIGHT,
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM,
}}
isDisabled={!canAllowSettlement}
/>
)}
{shouldShowSubmitButton && (
Expand Down
17 changes: 17 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4572,6 +4572,22 @@ 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);

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

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

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 @@ -4798,6 +4814,7 @@ export {
isReportParticipant,
isValidReport,
isReportFieldOfTypeTitle,
hasUpdatedTotal,
};

export type {
Expand Down
Loading