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 user to delete expense as long as report is not approved yet #46057

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
2 changes: 1 addition & 1 deletion src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
// Only the requestor can delete the request, admins can only edit it.
const isActionOwner =
typeof requestParentReportAction?.actorAccountID === 'number' && typeof session?.accountID === 'number' && requestParentReportAction.actorAccountID === session?.accountID;
const canDeleteRequest = isActionOwner && ReportUtils.canAddOrDeleteTransactions(moneyRequestReport) && !isDeletedParentAction;
const canDeleteRequest = isActionOwner && ReportUtils.canDeleteTransaction(moneyRequestReport) && !isDeletedParentAction;
const [isHoldMenuVisible, setIsHoldMenuVisible] = useState(false);
const [paymentType, setPaymentType] = useState<PaymentMethodType>();
const [requestType, setRequestType] = useState<ActionHandledType>();
Expand Down
43 changes: 31 additions & 12 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1579,13 +1579,6 @@ function getChildReportNotificationPreference(reportAction: OnyxInputOrEntry<Rep
return isActionCreator(reportAction) ? CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS : CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN;
}

/**
* Checks whether the supplied report supports adding more transactions to it.
* Return true if:
* - report is a non-settled IOU
* - report is a draft
* - report is a processing expense report and its policy has Instant reporting frequency
*/
function canAddOrDeleteTransactions(moneyRequestReport: OnyxEntry<Report>): boolean {
if (!isMoneyRequestReport(moneyRequestReport)) {
return false;
Expand All @@ -1600,11 +1593,36 @@ function canAddOrDeleteTransactions(moneyRequestReport: OnyxEntry<Report>): bool
return false;
}

return true;
}

/**
* Checks whether the supplied report supports adding more transactions to it.
* Return true if:
* - report is a non-settled IOU
* - report is a draft
* - report is a processing expense report and its policy has Instant reporting frequency
*/
function canAddTransaction(moneyRequestReport: OnyxEntry<Report>): boolean {
if (!isMoneyRequestReport(moneyRequestReport)) {
return false;
}

if (isReportInGroupPolicy(moneyRequestReport) && isProcessingReport(moneyRequestReport) && !PolicyUtils.isInstantSubmitEnabled(getPolicy(moneyRequestReport?.policyID))) {
return false;
}

return true;
return canAddOrDeleteTransactions(moneyRequestReport);
}

/**
* Checks whether the supplied report supports deleting more transactions from it.
* Return true if:
* - report is a non-settled IOU
* - report is a non-approved IOU
*/
function canDeleteTransaction(moneyRequestReport: OnyxEntry<Report>): boolean {
return canAddOrDeleteTransactions(moneyRequestReport);
}

/**
Expand All @@ -1628,7 +1646,7 @@ function canDeleteReportAction(reportAction: OnyxInputOrEntry<ReportAction>, rep
const linkedReport = isThreadFirstChat(reportAction, reportID) ? getReportOrDraftReport(report?.parentReportID) : report;
if (isActionOwner) {
if (!isEmptyObject(linkedReport) && isMoneyRequestReport(linkedReport)) {
return canAddOrDeleteTransactions(linkedReport);
return canDeleteTransaction(linkedReport);
}
return true;
}
Expand Down Expand Up @@ -5857,7 +5875,7 @@ function canRequestMoney(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>, o
// User can submit expenses in any IOU report, unless paid, but the user can only submit expenses in an expense report
// which is tied to their workspace chat.
if (isMoneyRequestReport(report)) {
const canAddTransactions = canAddOrDeleteTransactions(report);
const canAddTransactions = canAddTransaction(report);
return isReportInGroupPolicy(report) ? isOwnPolicyExpenseChat && canAddTransactions : canAddTransactions;
}

Expand Down Expand Up @@ -6901,7 +6919,7 @@ function hasMissingPaymentMethod(userWallet: OnyxEntry<UserWallet>, iouReportID:
* - we have one, but we can't add more transactions to it due to: report is approved or settled, or report is processing and policy isn't on Instant submit reporting frequency
*/
function shouldCreateNewMoneyRequestReport(existingIOUReport: OnyxInputOrEntry<Report> | undefined, chatReport: OnyxInputOrEntry<Report>): boolean {
return !existingIOUReport || hasIOUWaitingOnCurrentUserBankAccount(chatReport) || !canAddOrDeleteTransactions(existingIOUReport);
return !existingIOUReport || hasIOUWaitingOnCurrentUserBankAccount(chatReport) || !canAddTransaction(existingIOUReport);
}

function getTripTransactions(tripRoomReportID: string | undefined, reportFieldToCompare: 'parentReportID' | 'reportID' = 'parentReportID'): Transaction[] {
Expand Down Expand Up @@ -7204,7 +7222,8 @@ export {
buildParticipantsFromAccountIDs,
buildTransactionThread,
canAccessReport,
canAddOrDeleteTransactions,
canAddTransaction,
canDeleteTransaction,
canBeAutoReimbursed,
canCreateRequest,
canCreateTaskInReport,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/ReportDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD
report.stateNum !== CONST.REPORT.STATE_NUM.APPROVED &&
!ReportUtils.isClosedReport(report) &&
canModifyTask;
const canDeleteRequest = isActionOwner && (ReportUtils.canAddOrDeleteTransactions(moneyRequestReport) || isSelfDMTrackExpenseReport) && !isDeletedParentAction;
const canDeleteRequest = isActionOwner && (ReportUtils.canDeleteTransaction(moneyRequestReport) || isSelfDMTrackExpenseReport) && !isDeletedParentAction;
const shouldShowDeleteButton = shouldShowTaskDeleteButton || canDeleteRequest;

const canUnapproveRequest =
Expand Down
Loading