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

Allow invoices with multiple expenses #52556

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
10 changes: 6 additions & 4 deletions src/components/ReportActionItem/MoneyReportView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ function MoneyReportView({report, policy, isCombinedReport = false, shouldShowTo

const enabledReportFields = sortedPolicyReportFields.filter((reportField) => !ReportUtils.isReportFieldDisabled(report, reportField, policy));
const isOnlyTitleFieldEnabled = enabledReportFields.length === 1 && ReportUtils.isReportFieldOfTypeTitle(enabledReportFields.at(0));
const shouldShowReportField =
!ReportUtils.isClosedExpenseReportWithNoExpenses(report) && ReportUtils.isPaidGroupPolicyExpenseReport(report) && (!isCombinedReport || !isOnlyTitleFieldEnabled);
const isClosedExpenseReportWithNoExpenses = ReportUtils.isClosedExpenseReportWithNoExpenses(report);
const isPaidGroupPolicyExpenseReport = ReportUtils.isPaidGroupPolicyExpenseReport(report);
const isInvoiceReport = ReportUtils.isInvoiceReport(report);
const shouldShowReportField = !isClosedExpenseReportWithNoExpenses && (isPaidGroupPolicyExpenseReport || isInvoiceReport) && (!isCombinedReport || !isOnlyTitleFieldEnabled);

const renderThreadDivider = useMemo(
() =>
Expand All @@ -102,9 +104,9 @@ function MoneyReportView({report, policy, isCombinedReport = false, shouldShowTo
<>
<View style={[styles.pRelative]}>
<AnimatedEmptyStateBackground />
{!ReportUtils.isClosedExpenseReportWithNoExpenses(report) && (
{!isClosedExpenseReportWithNoExpenses && (
<>
{ReportUtils.isPaidGroupPolicyExpenseReport(report) &&
{(isPaidGroupPolicyExpenseReport || isInvoiceReport) &&
policy?.areReportFieldsEnabled &&
(!isCombinedReport || !isOnlyTitleFieldEnabled) &&
sortedPolicyReportFields.map((reportField) => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/SelectionList/Search/ReportListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function TotalCell({showTooltip, isLargeScreenWidth, reportItem}: ReportCellProp

// Only invert non-zero values otherwise we'll end up with -0.00
if (total) {
total *= reportItem?.type === CONST.REPORT.TYPE.EXPENSE ? -1 : 1;
total *= reportItem?.type === CONST.REPORT.TYPE.EXPENSE || reportItem?.type === CONST.REPORT.TYPE.INVOICE ? -1 : 1;
}

return (
Expand Down
4 changes: 4 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4049,6 +4049,10 @@ function getReportName(
}

if (isInvoiceReport(report)) {
if (!isInvoiceRoom(getReport(report?.chatReportID ?? ''))) {
return report?.reportName ?? getMoneyRequestReportName(report, policy, invoiceReceiverPolicy);
}

formattedName = getMoneyRequestReportName(report, policy, invoiceReceiverPolicy);
}

Expand Down
2 changes: 1 addition & 1 deletion src/pages/EditReportFieldPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function EditReportFieldPage({route}: EditReportFieldPageProps) {
const [isDeleteModalVisible, setIsDeleteModalVisible] = useState(false);
const {translate} = useLocalize();
const isReportFieldTitle = ReportUtils.isReportFieldOfTypeTitle(reportField);
const reportFieldsEnabled = (ReportUtils.isPaidGroupPolicyExpenseReport(report) && !!policy?.areReportFieldsEnabled) || isReportFieldTitle;
const reportFieldsEnabled = ((ReportUtils.isPaidGroupPolicyExpenseReport(report) || ReportUtils.isInvoiceReport(report)) && !!policy?.areReportFieldsEnabled) || isReportFieldTitle;

if (!reportFieldsEnabled || !reportField || !policyField || !report || isDisabled) {
return (
Expand Down
11 changes: 11 additions & 0 deletions src/pages/home/report/ReportActionItemSingle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,17 @@ function ReportActionItemSingle({
const reportIcons = ReportUtils.getIcons(report, {});

secondaryAvatar = reportIcons.at(avatarIconIndex) ?? {name: '', source: '', type: CONST.ICON_TYPE_AVATAR};
} else if (ReportUtils.isInvoiceReport(iouReport)) {
const secondaryAccountId = iouReport?.managerID ?? -1;
const secondaryUserAvatar = personalDetails?.[secondaryAccountId ?? -1]?.avatar ?? FallbackAvatar;
const secondaryDisplayName = ReportUtils.getDisplayNameForParticipant(secondaryAccountId);

secondaryAvatar = {
source: secondaryUserAvatar,
type: CONST.ICON_TYPE_AVATAR,
name: secondaryDisplayName,
id: secondaryAccountId,
};
} else {
secondaryAvatar = {name: '', source: '', type: 'avatar'};
}
Expand Down
Loading