Skip to content

Commit 9451328

Browse files
Pass report and policy props to TotalCell to fix negative sign in IOU report
TotalCell was reading report/policy from transactionItem, which is undefined in the IOU report view (MoneyRequestReportTransactionItem passes a raw Transaction). This caused shouldEnableNegative to hit a fallback path that incorrectly allowed negative amounts. Thread the report and policy props that TransactionItemRow already receives down to TotalCell, falling back to transactionItem fields for the Search context where they are enriched. Co-authored-by: ahmedGaber93 <ahmedGaber93@users.noreply.github.com>
1 parent 47fee90 commit 9451328

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

src/components/TransactionItemRow/DataCells/TotalCell.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,17 @@ import {parseFloatAnyLocale, roundToTwoDecimalPlaces} from '@libs/NumberUtils';
1414
import {getTransactionDetails, isInvoiceReport, shouldEnableNegative} from '@libs/ReportUtils';
1515
import {getCurrency as getTransactionCurrency, isDeletedTransaction, isExpenseUnreported, isScanning} from '@libs/TransactionUtils';
1616
import CONST from '@src/CONST';
17+
import type {Policy, Report} from '@src/types/onyx';
1718
import type TransactionDataCellProps from './TransactionDataCellProps';
1819

19-
type TotalCellProps = TransactionDataCellProps & EditableProps<number>;
20+
type TotalCellProps = TransactionDataCellProps &
21+
EditableProps<number> & {
22+
/** Report passed explicitly (used in IOU report view where transactionItem.report may be undefined) */
23+
report?: Report;
24+
25+
/** Policy passed explicitly (used in IOU report view where transactionItem.policy may be undefined) */
26+
policy?: Policy;
27+
};
2028
type TransactionItem = TransactionDataCellProps['transactionItem'];
2129

2230
function getTransactionItemIouType(transactionItem: TransactionItem) {
@@ -28,7 +36,7 @@ function getTransactionItemIouType(transactionItem: TransactionItem) {
2836
return isSplitTransaction ? CONST.IOU.TYPE.SPLIT : CONST.IOU.TYPE.SUBMIT;
2937
}
3038

31-
function TotalCell({shouldShowTooltip, transactionItem, canEdit, onSave}: TotalCellProps) {
39+
function TotalCell({shouldShowTooltip, transactionItem, canEdit, onSave, report, policy}: TotalCellProps) {
3240
const styles = useThemeStyles();
3341
const {translate, preferredLocale} = useLocalize();
3442
const {convertToDisplayString} = useCurrencyListActions();
@@ -41,10 +49,12 @@ function TotalCell({shouldShowTooltip, transactionItem, canEdit, onSave}: TotalC
4149
amountToDisplay = translate('iou.receiptStatusTitle');
4250
}
4351

44-
const iouType = getTransactionItemIouType(transactionItem);
52+
const effectiveReport = report ?? transactionItem.report;
53+
const effectivePolicy = policy ?? transactionItem.policy;
54+
const iouType = getTransactionItemIouType({...transactionItem, report: effectiveReport});
4555
const isSplitBill = iouType === CONST.IOU.TYPE.SPLIT;
4656
const isUnreportedExpense = isExpenseUnreported(transactionItem);
47-
const allowNegative = isUnreportedExpense || shouldEnableNegative(transactionItem.report, transactionItem.policy, iouType, transactionItem.participants);
57+
const allowNegative = isUnreportedExpense || shouldEnableNegative(effectiveReport, effectivePolicy, iouType, transactionItem.participants);
4858

4959
const absoluteAmount = Math.abs(amount ?? 0);
5060
const isOriginalAmountNegative = (amount ?? 0) < 0;

src/components/TransactionItemRow/TransactionItemRowNarrow.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ function TransactionItemRowNarrow({
120120
transactionItem={transactionItem}
121121
shouldShowTooltip={shouldShowTooltip}
122122
shouldUseNarrowLayout
123+
report={report}
123124
/>
124125
</View>
125126
</View>

src/components/TransactionItemRow/TransactionItemRowWide.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,8 @@ function TransactionItemRowWide({
415415
shouldUseNarrowLayout={false}
416416
canEdit={canEditAmount}
417417
onSave={onEditAmount}
418+
report={report}
419+
policy={policy}
418420
/>
419421
</View>
420422
);

0 commit comments

Comments
 (0)