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

Fix: Delay in updating green dot and total amount #34866

Merged
merged 12 commits into from
Feb 28, 2024
35 changes: 25 additions & 10 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ function getReceiptError(receipt, filename, isScanRequest = true) {
* @param {Object} policy - May be undefined, an empty object, or an object matching the Policy type (src/types/onyx/Policy.ts)
* @param {Array} policyTags
* @param {Array} policyCategories
* @param {Boolean} hasOutstandingChildRequest
* @param {Array} needsToBeManuallySubmitted
* @returns {Array} - An array containing the optimistic data, success data, and failure data.
*/
function buildOnyxDataForMoneyRequest(
Expand All @@ -348,7 +348,7 @@ function buildOnyxDataForMoneyRequest(
policy,
policyTags,
policyCategories,
hasOutstandingChildRequest = false,
needsToBeManuallySubmitted,
) {
const isScanRequest = TransactionUtils.isScanRequest(transaction);
const optimisticData = [
Expand All @@ -361,7 +361,7 @@ function buildOnyxDataForMoneyRequest(
lastReadTime: DateUtils.getDBTime(),
lastMessageTranslationKey: '',
iouReportID: iouReport.reportID,
hasOutstandingChildRequest,
hasOutstandingChildRequest: needsToBeManuallySubmitted && iouReport.managerID === userAccountID && iouReport.total !== 0,
...(isNewChatReport ? {pendingFields: {createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD}} : {}),
},
},
Expand Down Expand Up @@ -687,7 +687,7 @@ function getMoneyRequestInformation(
let iouReport = isNewIOUReport ? null : allReports[`${ONYXKEYS.COLLECTION.REPORT}${chatReport.iouReportID}`];

// Check if the Scheduled Submit is enabled in case of expense report
let needsToBeManuallySubmitted = false;
let needsToBeManuallySubmitted = true;
let isFromPaidPolicy = false;
if (isPolicyExpenseChat) {
isFromPaidPolicy = PolicyUtils.isPaidGroupPolicy(policy);
Expand Down Expand Up @@ -806,10 +806,6 @@ function getMoneyRequestInformation(
}
: undefined;

// The policy expense chat should have the GBR only when its a paid policy and the scheduled submit is turned off
// so the employee has to submit to their manager manually.
const hasOutstandingChildRequest = isPolicyExpenseChat && needsToBeManuallySubmitted;

// STEP 5: Build Onyx Data
const [optimisticData, successData, failureData] = buildOnyxDataForMoneyRequest(
chatReport,
Expand All @@ -827,7 +823,7 @@ function getMoneyRequestInformation(
policy,
policyTags,
policyCategories,
hasOutstandingChildRequest,
needsToBeManuallySubmitted,
);

return {
Expand Down Expand Up @@ -2544,7 +2540,19 @@ function deleteMoneyRequest(transactionID, reportAction, isSingleTransactionView
let updatedIOUReport = {...iouReport};
const updatedReportPreviewAction = {...reportPreviewAction};
updatedReportPreviewAction.pendingAction = shouldDeleteIOUReport ? CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE : CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE;
if (ReportUtils.isExpenseReport(iouReport)) {

const isPolicyExpenseChat = ReportUtils.isExpenseReport(iouReport);

let needsToBeManuallySubmitted = true;
if (isPolicyExpenseChat) {
const policy = ReportUtils.getPolicy(iouReport.policyID);
const isFromPaidPolicy = PolicyUtils.isPaidGroupPolicy(policy);

// If the scheduled submit is turned off on the policy, user needs to manually submit the report which is indicated by GBR in LHN
needsToBeManuallySubmitted = isFromPaidPolicy && !(policy.isHarvestingEnabled || false);
}

if (isPolicyExpenseChat) {
updatedIOUReport = {...iouReport};

// Because of the Expense reports are stored as negative values, we add the total from the amount
Expand Down Expand Up @@ -2646,6 +2654,13 @@ function deleteMoneyRequest(transactionID, reportAction, isSingleTransactionView
},
]
: []),
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For K2 to pick up

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wdym?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry not for you. Its for me.

onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`,
value: {
hasOutstandingChildRequest: needsToBeManuallySubmitted && updatedIOUReport.managerID === userAccountID && updatedIOUReport.total !== 0,
},
},
];

const successData = [
Expand Down
Loading