Skip to content

[Due for payment 2025-10-09] [$250] Android - Report - Amount is not updated smoothly after deleting expenses from report. #67641

Closed

Description

@jponikarchuk

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: 9.1.88-0
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught during regression testing, add the test name, ID and link from TestRail: https://test-management.browserstack.com/projects/2148171/test-runs/TR-328/folder/12015306/39317678/816207325
Email or phone of affected tester (no customers): ibellicotest+1485@gmail.com
Issue reported by: Applause Internal Team
Device used: Motorola MotoG60 / Android 12 (Hybrid app)
App Component: Money Requests

Action Performed:

Prerequisite: Account has at least one workspace.

  1. Open the expensify app.
  2. Open any workspace chat.
  3. Submit several manual expenses to it . (At least 5)
  4. Open the report of the just created expenses.
  5. Select between two and three expenses.
  6. Delete the selected expenses.
  7. Note that total amount changes to an incorrect amount for some seconds, before changing to the new correct amount.

Expected Result:

When deleting several expenses from a report, total amount should automatically change the the new correct total amount.

Actual Result:

When deleting several expenses from a report, the total amount changes to an incorrect new amount for some seconds, before changing again to the correct new amount.

Workaround:

Unknown

Platforms:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

1.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021951306802216159736
  • Upwork Job ID: 1951306802216159736
  • Last Price Increase: 2025-08-08
  • Automatic offers:
    • FitseTLT | Contributor | 108397079
Issue OwnerCurrent Issue Owner: @Christinadobrzyn

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Aug 1, 2025
  2. melvin-bot commented on Aug 1, 2025

    @melvin-bot

    Triggered auto assignment to @Christinadobrzyn (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

  3. bernhardoj commented on Aug 1, 2025

    @bernhardoj
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    Amount is not updated smoothly when deleting multiple expenses.

    What is the root cause of that problem?

    When we delete multiple expenses, we iterate over it and call deleteMoneyRequest for each expense.

    transactionsWithActions.forEach(({transactionID, action}) => {
    if (!action) {
    return;
    }
    deleteMoneyRequest(transactionID, action, duplicateTransactions, duplicateTransactionViolations, false, deletedTransactionIDs);
    deletedTransactionIDs.push(transactionID);
    });

    In deleteMoneyRequest, specifically in prepareToCleanUpMoneyRequest, we update the IOU report total with the transaction/expense amount.

    App/src/libs/actions/IOU.ts

    Lines 7668 to 7674 in 1dfb9cb

    if (iouReport && isExpenseReport(iouReport)) {
    updatedIOUReport = {...iouReport};
    if (typeof updatedIOUReport.total === 'number' && currency === iouReport?.currency) {
    // Because of the Expense reports are stored as negative values, we add the total from the amount
    const amountDiff = getAmount(transaction, true);
    updatedIOUReport.total += amountDiff;

    However, since IOU report total isn't immediately updated, each calls to prepareToCleanUpMoneyRequest gives different total. For example, the current report total is 15, then I delete 2 expenses with amounts of 1 and 5. For the first transaction, the report total will be 13. For the second transaction, the report total will be 14. We expect it to be 9.

    What changes do you think we should make in order to solve the problem?

    The simplest solution is,

    first, we have a list of pending transaction IDs

    function prepareToCleanUpMoneyRequest(transactionID: string, reportAction: OnyxTypes.ReportAction, shouldRemoveIOUTransactionID = true, transactionIDsPendingDeletion?: string[]) {

    for example, when I delete 3 expenses, the 2nd call of prepareToCleanUpMoneyRequest, transactionIDsPendingDeletion will contain the first expense ID, while the 3rd call of prepareToCleanUpMoneyRequest, transactionIDsPendingDeletion will contain the first and second expense ID.

    We get the transaction list from the IDs.

    const transactionPendingDelete = transactionIDsPendingDeletion?.map((id) => allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${id}`]);

    Then, we calculate all the pending transaction amount and add it to the amountDiff.

    App/src/libs/actions/IOU.ts

    Lines 7668 to 7673 in 1dfb9cb

    if (iouReport && isExpenseReport(iouReport)) {
    updatedIOUReport = {...iouReport};
    if (typeof updatedIOUReport.total === 'number' && currency === iouReport?.currency) {
    // Because of the Expense reports are stored as negative values, we add the total from the amount
    const amountDiff = getAmount(transaction, true);

    const amountDiff = getAmount(transaction, true) + (transactionPendingDelete?.reduce((prev, curr) => prev + getAmount(curr, true), 0) ?? 0);

    (we can do the same for IOU report)

    App/src/libs/actions/IOU.ts

    Lines 7691 to 7694 in 1dfb9cb

    updatedIOUReport = updateIOUOwnerAndTotal(
    iouReport,
    reportAction.actorAccountID ?? CONST.DEFAULT_NUMBER_ID,
    getAmount(transaction, false),

    This will have more smooth result, but we will still see the amount is reducing step by step quickly. It's because we use MERGE and we can use SET to make it faster.

    {
        onyxMethod: Onyx.METHOD.SET,
        key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport?.reportID}`,
        value: {...iouReport, ...updatedIOUReport},
    },

    What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

    We can test calling deleteMoneyRequest multiple times and verify that the report total is updated correctly.

    What alternative solutions did you explore? (Optional)

    For a more complex solution, we can have a separate function to delete multiple transactions and prepareToCleanUpMoneyRequest but we will still need to iterate over all transactions and call the API and update the others optimistic data.

  4. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Aug 1, 2025
  5. melvin-bot commented on Aug 1, 2025

    @melvin-bot
  6. changed the title [-]Android - Report - Amount is not updated smoothly after deleting expenses from report.[/-] [+][$250] Android - Report - Amount is not updated smoothly after deleting expenses from report.[/+] on Aug 1, 2025
  7. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Aug 1, 2025
  8. melvin-bot commented on Aug 1, 2025

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @dukenv0307 (External)

  9. FitseTLT commented on Aug 1, 2025

    @FitseTLT
    Contributor

    🚨 Edited by proposal-police: This proposal was edited at 2025-08-01 22:36:37 UTC.

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    Android - Report - Amount is not updated smoothly after deleting expenses from report.

    What is the root cause of that problem?

    We do bulk delete by iterating on the selected trasactions and calling deleteMoneyRequest

    transactionsWithActions.forEach(({transactionID, action}) => {
    if (!action) {
    return;
    }
    deleteMoneyRequest(transactionID, action, duplicateTransactions, duplicateTransactionViolations, false, deletedTransactionIDs);
    deletedTransactionIDs.push(transactionID);
    });

    and as deleteMoneyRequest is design for a single deleltion it updates the iouReport total by deducting the deleted transaction amount on the iouReport total

    App/src/libs/actions/IOU.ts

    Lines 7668 to 7674 in 1dfb9cb

    if (iouReport && isExpenseReport(iouReport)) {
    updatedIOUReport = {...iouReport};
    if (typeof updatedIOUReport.total === 'number' && currency === iouReport?.currency) {
    // Because of the Expense reports are stored as negative values, we add the total from the amount
    const amountDiff = getAmount(transaction, true);
    updatedIOUReport.total += amountDiff;

    but the subsequent deleteMoneyRequest calls don't receive the updated iouReport value as the iteratee calls occur too quick before the previous onyx update on the iou report takes effect.

    What changes do you think we should make in order to solve the problem?

    We can pass all selecteTransactionIDs to deleteMoneyRequest here

    deleteMoneyRequest(transactionID, action, duplicateTransactions, duplicateTransactionViolations, false, deletedTransactionIDs);

    and when calculating iouReport total we will determine the diff by suming all selectedTransactionIDs (the whole list of transactions to be deleted.
    const amountDiff = getAmount(transaction, true);

        const selectedTransactions = selectedTransactionID?.map((id) => allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${id}`]);
    ...
    
                const amountDiff = !selectedTransactions ? getAmount(transaction, true) : (selectedTransactions?.reduce((prev, transaction) => prev + getAmount(transaction, true), 0) ?? 0);
    
    

    But alternatively we can progressively update the iou report diff by deducting only the transactionPendingDelete transactions amount and the current deleted transaction

    const transactionPendingDelete = transactionIDsPendingDeletion?.map((id) => allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${id}`]);
    
    ...
    
    const amountDiff = getAmount(transaction, true) + (transactionPendingDelete?.reduce((prev, curr) => prev + getAmount(curr, true), 0) ?? 0);
    

    And to avoid a visible effect of the total reducing continously we can update the iou Report via SET here spreading iouREport and updatedIOUReport

    App/src/libs/actions/IOU.ts

    Lines 8066 to 8069 in d5ce4e8

    onyxMethod: Onyx.METHOD.MERGE,
    key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport?.reportID}`,
    value: updatedIOUReport,
    },

    Note: another thing we should consider is that here
    if (typeof updatedIOUReport.total === 'number' && currency === iouReport?.currency) {

    we update the iouReport total if the transaction to be deleted has the same currency as the iouReport but in our case of bulk deletion we should only update the iouReport total if all the deleted transactions have the same currency as the iouReport as we don't have exchange rate data in FE. We should update to

    const selectedTransactions = selectedTransactionID?.map((id) => allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${id}`]);
    
            if (typeof updatedIOUReport.total === 'number' && currency === iouReport?.currency && !selectedTransactions?.some((trans) => getCurrency(trans) !== iouReport?.currency)) {
             
    

    We will do the same for iou reports here

    getAmount(transaction, false),

    This will avoid continous reducing total value on slower platform as Android by following the method proposed in the above proposal.

    What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

    We can test delelteMoneyRequest handles bulk deletion by passing multiple transactions as selectedTransactionIDs and asserting that the iouReport will be calculated according to all selecteTransactionIDs

    What alternative solutions did you explore? (Optional)

    As discussed here the current bulk deletion method of calling delete iterating on selectedTransactions has many side effects and the ideal solution if BE change can be made is to add a new bulk deletion API like DELETE_MONEY_REQUEST_ON_SEARCH which handle buld deletion and create a new function in the FE which updates the optimisticData needed for buld deletion, we can re-implement deleteMoneyRequest function by adapting it for bulk deletion.

  10. dukenv0307 commented on Aug 2, 2025

    @dukenv0307
    Contributor

    Thanks for all your proposals. I like @bernhardoj's proposal. I think the amount should be reflected in the processed transactions. It doesn't make sense if the total value is updated while the transactions are not processed, so it can cause confusion

    🎀👀🎀 C+ reviewed

  11. 54 remaining items

  12. dukenv0307 commented on Oct 9, 2025

    @dukenv0307
    Contributor

    Yeah @FitseTLT, @Christinadobrzyn I think another $250 for me and @FitseTLT for fixing another bug

  13. Christinadobrzyn commented on Oct 9, 2025

    @Christinadobrzyn
    Contributor

    Thanks everyone! @mollfpr let me know what you think of a bonus of $250 for this #68484 (comment) for @dukenv0307 and @FitseTLT

  14. Christinadobrzyn commented on Oct 10, 2025

    @Christinadobrzyn
    Contributor

    Nudged @mollfpr for a review of the bonus

  15. mollfpr commented on Oct 11, 2025

    @mollfpr
    Contributor

    Apologies for the delay 🙏

    I’m fine with the bonus, weighing the bug fixed is essential for the pending transaction.

  16. melvin-bot commented on Oct 13, 2025

    @melvin-bot

    @Christinadobrzyn Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

  17. melvin-bot commented on Oct 13, 2025

    @melvin-bot

    @Christinadobrzyn Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

  18. Christinadobrzyn commented on Oct 14, 2025

    @Christinadobrzyn
    Contributor

    Thanks for confirming @mollfpr!

    Payment summary here - #67641 (comment)

    Please reach out with any questions otherwise @bernhardoj and @dukenv0307 please request payment via ND.

  19. bernhardoj commented on Oct 15, 2025

    @bernhardoj
    Contributor

    Requested in ND.

  20. garrettmknight commented on Oct 17, 2025

    @garrettmknight
    Contributor

    $100 approved for @bernhardoj

  21. trjExpensify commented on Oct 21, 2025

    @trjExpensify
    Contributor

    Approved $500 for @dukenv0307

  22. garrettmknight commented on Oct 24, 2025

    @garrettmknight
    Contributor

    $500 approved for @dukenv0307

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions