Skip to content

Commit

Permalink
Merge pull request #35062 from software-mansion-labs/money-report-cur…
Browse files Browse the repository at this point in the history
…rency-fix

FIX: Implement pattern C for money reports with various currencies
  • Loading branch information
johnmlee101 authored Feb 5, 2024
2 parents a1b33ef + 7121f1f commit 43d1576
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
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

0 comments on commit 43d1576

Please sign in to comment.