Skip to content

[Due for payment 2025-09-19] [$250] Expense - Unable to sort expenses after split #69302

Closed

Description

@lanitochka17

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.99-0
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught during regression testing, add the test name, ID and link from TestRail: https://test-management.browserstack.com/projects/2219752/test-runs/TR-439/folder/13176791/41237172/861418493
Email or phone of affected tester (no customers): sdhshssdjiosdndjs@gmail.com
Issue reported by: Applause - Internal Team

Action Performed:

  1. Go to staging.new.expensify.com
  2. Go to workspace chat
  3. Submit an expense in the workspace chat
  4. Open the expense report
  5. Click More > Split
  6. On split page, edit the amount of one of the splits to be lower than the original amount
  7. Click Save
  8. Click Total on the table header to sort the expenses

Expected Result:

The expenses can be sorted after split

Actual Result:

The expenses cannot be sorted after split

Workaround:

Unknown

Platforms:

Select the officially supported platforms where the issue was reproduced:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari
  • MacOS: Desktop
Platforms Tested: On which of our officially supported platforms was this issue tested:
  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Add any screenshot/video evidence
Bug6927502_1756232494799.Screen_Recording_2025-08-27_at_02.17.48.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021960478703209653842
  • Upwork Job ID: 1960478703209653842
  • Last Price Increase: 2025-08-26
Issue OwnerCurrent Issue Owner: @Christinadobrzyn

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Aug 26, 2025
  2. melvin-bot commented on Aug 26, 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. FitseTLT commented on Aug 26, 2025

    @FitseTLT
    Contributor

    Proposal

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

    Expense - Unable to sort expenses after split

    What is the root cause of that problem?

    For split transactions the modifiedAmount is the real split amount value but we are sorting it with amount key here

    const getTransactionKey = (transaction: OnyxTypes.Transaction, key: SortableColumnName) => {
    const dateKey = transaction.modifiedCreated ? 'modifiedCreated' : 'created';
    return key === CONST.SEARCH.TABLE_COLUMNS.DATE ? dateKey : key;
    };

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

    We should use the key modifiedAmount if it exists here

    const getTransactionKey = (transaction: OnyxTypes.Transaction, key: SortableColumnName) => {
    const dateKey = transaction.modifiedCreated ? 'modifiedCreated' : 'created';
    return key === CONST.SEARCH.TABLE_COLUMNS.DATE ? dateKey : key;
    };

    if (key === CONST.SEARCH.TABLE_COLUMNS.TOTAL_AMOUNT) {
            return typeof transaction.modifiedAmount === 'number' ? 'modifiedAmount' : 'amount';
        }
    

    We can use a better switch to consider other modified fields too like modifiedCurrency and others too.

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

    N / A

    What alternative solutions did you explore? (Optional)

  4. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Aug 26, 2025
  5. changed the title [-]Expense - Unable to sort expenses after split[/-] [+][$250] Expense - Unable to sort expenses after split[/+] on Aug 26, 2025
  6. melvin-bot commented on Aug 26, 2025

    @melvin-bot
  7. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Aug 26, 2025
  8. melvin-bot commented on Aug 26, 2025

    @melvin-bot

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

  9. Christinadobrzyn commented on Aug 26, 2025

    @Christinadobrzyn
    Contributor

    I can reproduce this so sending to External

  10. lorretheboy commented on Aug 27, 2025

    @lorretheboy
    Contributor

    🚨 Edited by proposal-police: This proposal was edited at 2025-08-27 01:50:50 UTC.

    Proposal

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

    Expense - Unable to sort expenses after split

    What is the root cause of that problem?

    Root cause is because for split transactions, the modifiedAmount is the real split amount value, but the sorting is using the amount key instead of considering modifiedAmount

    const getTransactionKey = (transaction: OnyxTypes.Transaction, key: SortableColumnName) => {
    const dateKey = transaction.modifiedCreated ? 'modifiedCreated' : 'created';
    return key === CONST.SEARCH.TABLE_COLUMNS.DATE ? dateKey : key;
    };

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

    Replace original function by getTransactionSortValue function to use the existing getAmount utility which properly handles modifiedAmount vs amount logic

    const getTransactionSortValue = (transaction: OnyxTypes.Transaction, key: SortableColumnName, report: OnyxTypes.Report) => {
        switch (key) {
            case CONST.SEARCH.TABLE_COLUMNS.DATE:
                return transaction.modifiedCreated ?? transaction.created;
            case CONST.SEARCH.TABLE_COLUMNS.TOTAL_AMOUNT:
                // Use getAmount utility which properly handles modifiedAmount vs amount logic
                // This ensures split transactions are sorted by their actual split amount
                return getAmount(transaction, isExpenseReport(report));
            // Optional: We can consider this or just handle Date and Total Amount like the original one
            case CONST.SEARCH.TABLE_COLUMNS.MERCHANT:
                return transaction.modifiedMerchant ?? transaction.merchant;
            default:
                return transaction[key as keyof OnyxTypes.Transaction];
        }
    };

    Then update this place to call new function

    .sort((a, b) => compareValues(a[getTransactionKey(a, sortBy)], b[getTransactionKey(b, sortBy)], sortOrder, sortBy, localeCompare))

    We should also add useAbsoluteValues = false this props to compareValues to disable the compare absolute value if for the negative sorting case

    function compareValues(a: unknown, b: unknown, sortOrder: SortOrder, sortBy: string, localeCompare: LocaleContextProps['localeCompare'], useAbsoluteValues = false): number {
    
    ...
    
        if (typeof a === 'number' && typeof b === 'number') {
            const aValue = useAbsoluteValues ? Math.abs(a) : a;
            const bValue = useAbsoluteValues ? Math.abs(b) : b;
            return isAsc ? aValue - bValue : bValue - aValue;
        }

    function compareValues(a: unknown, b: unknown, sortOrder: SortOrder, sortBy: string, localeCompare: LocaleContextProps['localeCompare']): number {

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

    Add test to test the MoneyRequestReportTransactionList - Transaction Sorting

    What alternative solutions did you explore? (Optional)

    We should update the getTransactionKey function to handle the amount field properly by returning the appropriate amount value (considering modifiedAmount vs amount) rather than just the field name

        if (key === CONST.SEARCH.TABLE_COLUMNS.DATE) {
            return dateKey;
        }
        if (key === CONST.SEARCH.TABLE_COLUMNS.TOTAL_AMOUNT) {
            // For amount sorting, use modifiedAmount if available, otherwise use amount
            // This ensures split transactions are sorted by their actual split amount
            return transaction.modifiedAmount !== undefined ? 'modifiedAmount' : 'amount';
        }
        return key;

    return key === CONST.SEARCH.TABLE_COLUMNS.DATE ? dateKey : key;

    Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

  11. nkdengineer commented on Aug 27, 2025

    @nkdengineer
    Contributor

    🚨 Edited by proposal-police: This proposal was edited at 2025-08-27 02:12:42 UTC.

    Proposal

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

    The expenses cannot be sorted after split

    What is the root cause of that problem?

    All split transactions have the amount as the amount from the original transaction. The real amount is in modifiedAmount field

    .sort((a, b) => compareValues(a[getTransactionKey(a, sortBy)], b[getTransactionKey(b, sortBy)], sortOrder, sortBy, localeCompare))

    Because we get the value to compare from the amount field, nothing happen

    const getTransactionKey = (transaction: OnyxTypes.Transaction, key: SortableColumnName) => {
    const dateKey = transaction.modifiedCreated ? 'modifiedCreated' : 'created';
    return key === CONST.SEARCH.TABLE_COLUMNS.DATE ? dateKey : key;

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

    Instead of returning the key, we can create a function to get the comparison value and use the existing util to get the correct value from the transaction.

    We have an important note for the amount field. The amount from the expense report is negative, so we should use getAmount function to return the positive amount. We also have a problem if the transaction has a different currency from the workspace currency. To resolve this issue, the backend should return the correct originalAmount in the transaction data, allowing us to compare it with others (currently, the backend returns the originalAmount as 0).

    const getSortValue = (transaction: OnyxTypes.Transaction, key: SortableColumnName, report: OnyxTypes.Report) => {
        switch(key) {
            case CONST.SEARCH.TABLE_COLUMNS.DATE:
                return getCreated(transaction);
            case CONST.SEARCH.TABLE_COLUMNS.MERCHANT:
                return getMerchant(transaction);
            case CONST.SEARCH.TABLE_COLUMNS.CATEGORY:
                return getCategory(transaction);
            case CONST.SEARCH.TABLE_COLUMNS.TAG:
                return getTag(transaction);
            case CONST.SEARCH.TABLE_COLUMNS.TOTAL_AMOUNT:
                return getAmount(transaction, isExpenseReport(report), transaction.reportID === CONST.REPORT.UNREPORTED_REPORT_ID);
            default:
                return '';
        }
    }
    
    .sort((a, b) => compareValues(getSortValue(a, sortBy, report), getSortValue(b, sortBy, report), sortOrder, sortBy, localeCompare))
    

    .sort((a, b) => compareValues(a[getTransactionKey(a, sortBy)], b[getTransactionKey(b, sortBy)], sortOrder, sortBy, localeCompare))

    The compareValues function always compares the positive amount; we should update and remove the convert to abs logic here or we should define a new param to control compare original amount or compare the positive value and pass this parameter accordingly when we want to compare the original value.

    App/src/libs/SearchUIUtils.ts

    Lines 1585 to 1600 in ae5f666

    function compareValues(a: unknown, b: unknown, sortOrder: SortOrder, sortBy: string, localeCompare: LocaleContextProps['localeCompare']): number {
    const isAsc = sortOrder === CONST.SEARCH.SORT_ORDER.ASC;
    if (a === undefined || b === undefined) {
    return 0;
    }
    if (typeof a === 'string' && typeof b === 'string') {
    return isAsc ? localeCompare(a, b) : localeCompare(b, a);
    }
    if (typeof a === 'number' && typeof b === 'number') {
    const aValue = sortBy === CONST.SEARCH.TABLE_COLUMNS.TOTAL_AMOUNT ? Math.abs(a) : a;
    const bValue = sortBy === CONST.SEARCH.TABLE_COLUMNS.TOTAL_AMOUNT ? Math.abs(b) : b;
    return isAsc ? aValue - bValue : bValue - aValue;
    }

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

    None

    What alternative solutions did you explore? (Optional)

    Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

  12. 33 remaining items

  13. changed the title [-][$250] Expense - Unable to sort expenses after split[/-] [+][Due for payment 2025-09-19] [$250] Expense - Unable to sort expenses after split[/+] on Sep 12, 2025
  14. melvin-bot commented on Sep 12, 2025

    @melvin-bot

    Reviewing label has been removed, please complete the "BugZero Checklist".

  15. melvin-bot commented on Sep 12, 2025

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.2.12-4 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

    If no regressions arise, payment will be issued on 2025-09-19. 🎊

    For reference, here are some details about the assignees on this issue:

  16. melvin-bot commented on Sep 12, 2025

    @melvin-bot

    @suneox @Christinadobrzyn The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]

  17. Christinadobrzyn commented on Sep 16, 2025

    @Christinadobrzyn
    Contributor

    payment is coming up @suneox please let us know about a regression test.

  18. suneox commented on Sep 18, 2025

    @suneox
    Contributor

    BugZero Checklist:

    • [Contributor] Classify the bug:
    Bug classification

    Source of bug:

    • 1a. Result of the original design (eg. a case wasn't considered)
    • 1b. Mistake during implementation
    • 1c. Backend bug
    • 1z. Other:

    Where bug was reported:

    • 2a. Reported on production (eg. bug slipped through the normal regression and PR testing process on staging)
    • 2b. Reported on staging (eg. found during regression or PR testing)
    • 2d. Reported on a PR
    • 2z. Other:

    Who reported the bug:

    • 3a. Expensify user
    • 3b. Expensify employee
    • 3c. Contributor
    • 3d. QA
    • 3z. Other:
    • [Contributor] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.

      Link to comment: https://github.com/Expensify/App/pull/58713/files#r2360060460

    • [Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner.

      Link to discussion: N/A

    • [Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.

    https://github.com/Expensify/Expensify/issues/549317

    Regression Test Proposal

    Precondition:

    Test:

    1. Go to any workspace chat
    2. Submit an expense in the workspace chat
    3. Open the expense report
    4. Click More > Split
    5. On split page, edit the amount of one of the splits to be lower than the original amount
    6. Click Save
    7. Click Total on the table header to sort the expenses

    Verify the expenses are sorted correctly in ascending order

    Do we agree 👍 or 👎

  19. Christinadobrzyn commented on Sep 19, 2025

    @Christinadobrzyn
    Contributor

    Payment day -

    Regression test - #69302 (comment)
    Payment summary - #69302 (comment)

    @suneox can you please make sure to request payment through ND? Closing as complete

  20. quinthar commented on Oct 12, 2025

    @quinthar
    Contributor

    Approved $250 to @suneox

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