Skip to content
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
12 changes: 9 additions & 3 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2716,14 +2716,19 @@ function canAddOrDeleteTransactions(moneyRequestReport: OnyxEntry<Report>, isRep
* Returns false if:
* - if current user is not the submitter of an expense report
*/
function canAddTransaction(moneyRequestReport: OnyxEntry<Report>, isReportArchived = false): boolean {
function canAddTransaction(moneyRequestReport: OnyxEntry<Report>, isReportArchived = false, isMovingTransaction = false): boolean {
if (!isMoneyRequestReport(moneyRequestReport) || (isExpenseReport(moneyRequestReport) && !isCurrentUserSubmitter(moneyRequestReport))) {
return false;
}
// This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
// eslint-disable-next-line @typescript-eslint/no-deprecated
const policy = getPolicy(moneyRequestReport?.policyID);
if (isInstantSubmitEnabled(policy) && isSubmitAndClose(policy) && hasOnlyNonReimbursableTransactions(moneyRequestReport?.reportID)) {
if (
isInstantSubmitEnabled(policy) &&
isSubmitAndClose(policy) &&
(hasOnlyNonReimbursableTransactions(moneyRequestReport?.reportID) ||
(!isMovingTransaction && !isOpenExpenseReport(moneyRequestReport) && policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_NO))
) {
return false;
}

Expand Down Expand Up @@ -6974,6 +6979,7 @@ function getMovedTransactionMessage(action: ReportAction) {
const fromReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${fromReportID}`];

const report = fromReport ?? toReport;
// eslint-disable-next-line @typescript-eslint/no-deprecated
const reportName = getReportName(report) ?? report?.reportName ?? '';
let reportUrl = getReportURLForCurrentContext(report?.reportID);
if (typeof fromReportID === 'undefined') {
Expand Down Expand Up @@ -7002,7 +7008,7 @@ function getUnreportedTransactionMessage(action: ReportAction) {
const {fromReportID} = movedTransactionOriginalMessage as OriginalMessageMovedTransaction;

const fromReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${fromReportID}`];

// eslint-disable-next-line @typescript-eslint/no-deprecated
const reportName = getReportName(fromReport) ?? fromReport?.reportName ?? '';

let reportUrl = `${environmentURL}/r/${fromReport?.reportID}`;
Expand Down
3 changes: 2 additions & 1 deletion src/pages/iou/request/step/IOURequestEditReportCommon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ function IOURequestEditReportCommon({
return true;
})
.filter((report) => {
if (canAddTransaction(report)) {
if (canAddTransaction(report, undefined, true)) {
return true;
}

Expand All @@ -188,6 +188,7 @@ function IOURequestEditReportCommon({
// We set it to null here to prevent showing RBR for reports https://github.com/Expensify/App/issues/65960.
brickRoadIndicator: null,
alternateText: getPolicyName({report}) ?? matchingOption?.alternateText,
// eslint-disable-next-line @typescript-eslint/no-deprecated
text: getReportName(report),
value: report.reportID,
keyForList: report.reportID,
Expand Down
8 changes: 7 additions & 1 deletion src/types/onyx/OriginalMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,12 @@ type OriginalMessageSubmitted = {
cc?: string;
};

/** Model of `created` report action */
type OriginalMessageCreated = {
/** The account id of the user the report is submitted to */
submittedTo?: number;
};

/** Model of `closed` report action */
type OriginalMessageClosed = {
/** Name of the policy */
Expand Down Expand Up @@ -1056,7 +1062,7 @@ type OriginalMessageMap = {
[CONST.REPORT.ACTIONS.TYPE.CHANGE_TYPE]: never;
[CONST.REPORT.ACTIONS.TYPE.CHRONOS_OOO_LIST]: OriginalMessageChronosOOOList;
[CONST.REPORT.ACTIONS.TYPE.CLOSED]: OriginalMessageClosed;
[CONST.REPORT.ACTIONS.TYPE.CREATED]: never;
[CONST.REPORT.ACTIONS.TYPE.CREATED]: OriginalMessageCreated;
[CONST.REPORT.ACTIONS.TYPE.DISMISSED_VIOLATION]: OriginalMessageDismissedViolation;
[CONST.REPORT.ACTIONS.TYPE.EXPENSIFY_CARD_SYSTEM_MESSAGE]: never;
[CONST.REPORT.ACTIONS.TYPE.EXPORTED_TO_CSV]: never;
Expand Down
51 changes: 51 additions & 0 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5949,6 +5949,57 @@ describe('ReportUtils', () => {
expect(result).toBe(false);
});

it('should return false for a submitted report when the policy is submit and close with payment disabled', async () => {
// Given the policy is submit and close with payment disabled
const workflowDisabledPolicy: Policy = {
...createRandomPolicy(2962),
autoReporting: true,
autoReportingFrequency: CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT,
approvalMode: CONST.POLICY.APPROVAL_MODE.OPTIONAL,
reimbursementChoice: CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_NO,
employeeList: {
[currentUserEmail]: {email: currentUserEmail, submitsTo: currentUserEmail},
},
approver: currentUserEmail,
};
const report: Report = {
...createRandomReport(10002, undefined),
type: CONST.REPORT.TYPE.EXPENSE,
statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED,
stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
policyID: workflowDisabledPolicy.id,
ownerAccountID: currentUserAccountID,
managerID: currentUserAccountID,
};
const createdAction: ReportAction = {...createRandomReportAction(123), actionName: CONST.REPORT.ACTIONS.TYPE.CREATED, originalMessage: {submittedTo: currentUserAccountID}};
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report);
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, {[createdAction.reportActionID]: createdAction});
await Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${workflowDisabledPolicy.id}`, workflowDisabledPolicy);
await Onyx.set(`${ONYXKEYS.PERSONAL_DETAILS_LIST}`, {
[currentUserAccountID]: {
accountID: currentUserAccountID,
displayName: 'Lagertha Lothbrok',
firstName: 'Lagertha',
login: currentUserEmail,
pronouns: 'She/her',
},
});

const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.reportID));

// If the canAddTransaction is used for the case of adding expense into the report
const result = canAddTransaction(report, isReportArchived.current);

// Then the result should be false
expect(result).toBe(false);

// If the canAddTransaction is used for the case of moving transaction into the report
const result2 = canAddTransaction(report, isReportArchived.current, true);

// Then the result should be true
expect(result2).toBe(true);
});

it('should return false for an archived report', async () => {
// Given an archived expense report
const report: Report = {
Expand Down
Loading