Skip to content

[Rules Engine Release 2] [App] Support expense defaults for more than just merchants - #104155

Merged
JS00001 merged 69 commits into
Expensify:mainfrom
Krishna2323:krishna2323/issue-102277-expense-defaults
Nov 3, 2026
Merged

JS00001 merged 69 commits into
Expensify:mainfrom
Krishna2323:krishna2323/issue-102277-expense-defaults

Conversation

@Krishna2323

@Krishna2323 Krishna2323 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

An expense default rule could only match on a single merchant, and a category's tax default was stored separately on policy.rules.expenseRules. The filter tree is now built by ANDing every condition the form sets, so one rule can match on a merchant, a list of categories and a list of tags at once, and every expense default — including a category's tax rate — saves through setRule into the rules_ collection.

  • buildExpenseDefaultFilters builds a left-nested and tree, so three conditions become and(and(merchant, category), tag). Each multi-select stays one comparison with an array on the right, which the backend matches as an OR.
  • getEditableConditions and getConditionFromLeaf replace getEditableMerchantMatch. A rule stays read-only when the form cannot represent its tree: an or combination, the same field matched twice, a field the form has no input for, or an operator it has no control for.
  • isExpenseDefaultRule required a merchant condition, which would have hidden every rule matching on a category or a tag alone. It now requires at least one condition.
  • Duplicate detection compares the whole condition set instead of the merchant and match type, ignoring the order of a multi-select and only comparing the match type when both rules match on a merchant.
  • A rule is created to fire on both CreateTransaction and UpdateTransaction, so a default applies when an expense is edited into matching it and not only when it is created. An edit hands back the triggers the rule already carries, so it never silently narrows when the rule applies.
  • On the Rules page a rule that matches on a category alone is listed under Categories, and one that also matches on a merchant or a tag stays with them, so each rule appears in one place there. Category settings lists every rule matching the category, whatever else it matches on, one row each. The row carries the ID of the rule it opens, so a category holding more than one rule no longer hides all but the first.
  • Category settings describes a rule by what it sets, reusing the summary the Expense defaults table builds, rather than by its tax rate. A rule that set no tax used to produce no row at all, and one that set several fields showed only its tax.
  • A rule deleted offline stays listed in category settings, struck through and not openable, until the request goes through, the same as in the Expense defaults table.
  • Category settings prefetches the rules collection. It reads the same collection the Rules page does, but nothing on the way in fetched it, so the section could read empty on a fresh session and invite a duplicate.
  • Creating a rule from category settings creates one, the way the Rules page does, rather than opening the rule the category already has. Saving one that matches the same things prompts first.
  • The legacy policy.rules.expenseRules path is gone, along with the client-side prediction of a category's tax. The rate now comes from the API response rather than being guessed optimistically.
  • The rules table spells out the match type, so a "contains" rule and an "exactly matches" rule on the same merchant no longer read as duplicates.

Fixed Issues

$ #102277
PROPOSAL:

Tests

  1. Open a workspace with Rules and Categories enabled, go to Workspace settings > Rules > Expense defaults.
  2. New rule > Apply expense defaults. Set a merchant to match, a category to match and a tag to match, then set a category, tag, tax and amount as the defaults. Save.
  3. Verify the row lists all three conditions and all four defaults.
  4. Reopen the rule and verify every field is populated with what you saved. Save again and verify nothing changes.
  5. Create a rule matching on a category alone. Verify it is listed under Categories, not Merchants, and that it opens.
  6. Create a second rule with the same merchant and match type. Verify the "Similar rule already exists" prompt appears.
  7. Dismiss it, change the match type from Contains to Exact match, save, and verify the prompt does not appear. Verify the two rows now read "Merchant contains …" and "Merchant exactly matches …" rather than both reading "Merchant is …".
  8. From Workspace settings > Categories, open a category, Create new rule > Apply expense defaults, set a tax and save. Verify it returns to category settings, the rule is listed under Category rules describing what it sets, and it appears under Categories in the Expense defaults table. Repeat from Settings > Categories.
  9. From the same category, press Create new rule again. Verify a blank form opens scoped to that category rather than the rule you just made. Set an amount only, with no tax, and save. Verify both rules are now listed under Category rules, that the amount-only one is listed at all, and that each row opens the rule it describes.
  10. Create a rule matching that same category together with a merchant. Verify it is listed under Merchants in the Expense defaults table, not under Categories, and that it is also listed in the category's Category rules.
  11. From the category, use Describe a rule to describe a tax rule for that category. Verify it opens the editor rather than rejecting the category.
  12. Open every row of the editor from the category settings flow and verify none shows Not found. Press back from each and verify it returns to category settings rather than the Rules page.
  13. Refresh the browser on a category's settings page, or open it from Settings > Categories in a fresh session. Verify Category rules still lists the rules rather than coming up empty.
  14. Create a rule matching two categories. Verify it is listed under Category rules on both of them.
  15. Edit a saved rule's category and save. Verify it updates the existing rule rather than creating a second one.
  16. Create an expense matching a rule and verify the defaults are applied.
  17. Delete the rules and verify they disappear from both the table and category settings.

Offline tests

  1. Go offline.
  2. Create a rule with a merchant, a category and a tag. Verify it appears in the table greyed out as pending.
  3. Edit it while still offline. Verify the row shows the edited values, still pending.
  4. Delete a category's rule while offline. Verify it stays listed in category settings struck through and cannot be opened, and that recreating the same rule is not rejected as a duplicate.
  5. Go back online. Verify the rules save, lose the pending style, and show the same values they showed offline.

QA Steps

  1. Open a workspace with Rules and Categories enabled, go to Workspace settings > Rules > Expense defaults.
  2. New rule > Apply expense defaults. Set a merchant to match, a category to match and a tag to match, then set a category, tag, tax and amount as the defaults. Save.
  3. Verify the row lists all three conditions and all four defaults.
  4. Reopen the rule and verify every field is populated with what you saved.
  5. Create a rule matching on a category alone. Verify it is listed under Categories, not Merchants, and that it opens.
  6. Create a second rule with the same merchant and match type. Verify the "Similar rule already exists" prompt appears.
  7. Dismiss it, switch the match type from Contains to Exact match, save, and verify the prompt does not appear.
  8. From Workspace settings > Categories, open a category, Create new rule > Apply expense defaults, set a tax and save. Verify the rule is listed under Category rules and appears under Categories in the Expense defaults table. Repeat from Settings > Categories.
  9. From the same category, press Create new rule again. Verify a blank form opens rather than the rule you just made, save an amount-only rule, and verify both are listed and each opens the rule it describes.
  10. Create a rule matching that category together with a merchant. Verify it is listed under Merchants in the table and is also listed in the category's Category rules.
  11. Edit a saved rule's category and save. Verify it updates the existing rule rather than creating a second one.
  12. Create an expense matching a rule and verify the defaults are applied to it.
  13. Delete the rules you created and verify they disappear from the table.

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I verified there are no new alerts related to the canBeMissing param for useOnyx
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
android_hybrid.mp4
Android: mWeb Chrome
android_mWeb.mp4
iOS: Native
ios_hybrid.mp4
iOS: mWeb Safari
ios_mWeb.mp4
MacOS: Chrome / Safari
web_chrome.mp4

Signed-off-by: krishna2323 <belivethatkg@gmail.com>
@codecov

codecov Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
src/CONST/index.ts 95.96% <ø> (ø)
src/SCREENS.ts 100.00% <ø> (ø)
...MoneyRequestConfirmationList/FieldAutoSelector.tsx 72.00% <100.00%> (-1.08%) ⬇️
...nts/MoneyRequestConfirmationList/TaxController.tsx 97.56% <100.00%> (+0.78%) ⬆️
...MoneyRequestConfirmationList/hooks/useTaxAmount.ts 100.00% <100.00%> (ø)
...oneyRequestConfirmationList/sections/DateField.tsx 72.83% <100.00%> (+0.68%) ⬆️
...DefaultsTable/WorkspaceExpenseDefaultsTableRow.tsx 3.50% <ø> (ø)
...nts/Tables/WorkspaceExpenseDefaultsTable/index.tsx 2.04% <100.00%> (ø)
src/hooks/useUpdateTransactionCategory.ts 100.00% <100.00%> (ø)
src/libs/CategoryTaxRulesUtils.ts 93.75% <100.00%> (+2.98%) ⬆️
... and 46 more
... and 62 files with indirect coverage changes

…dition rules

Signed-off-by: krishna2323 <belivethatkg@gmail.com>
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
…ount pages

Signed-off-by: krishna2323 <belivethatkg@gmail.com>
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
@melvin-bot

melvin-bot Bot commented Oct 15, 2026

Copy link
Copy Markdown

Hey, I noticed you changed src/languages/en.ts in a PR from a fork. For security reasons, translations are not generated automatically for PRs from forks.

If you want to automatically generate translations for other locales, an Expensify employee will have to:

  1. Look at the code and make sure there are no malicious changes.
  2. Run the Generate static translations GitHub workflow. If you have write access and the K2 extension, you can simply click: [this button]

Alternatively, if you are an external contributor, you can run the translation script locally with your own OpenAI API key. To learn more, try running:

npx bun ./scripts/generateTranslations.ts --help

Typically, you'd want to translate only what you changed by running npx bun ./scripts/generateTranslations.ts --compare-ref main

Signed-off-by: krishna2323 <belivethatkg@gmail.com>
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
@JS00001

JS00001 commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Ran an initial test of this locally, this works great!! Nice work on this

@Krishna2323 Krishna2323 changed the title Krishna2323/issue 102277 expense defaults [Rules Engine Release 2] [App] Support expense defaults for more than just merchants Oct 19, 2026
…02277-expense-defaults

# Conflicts:
#	src/libs/Navigation/types.ts
@Krishna2323

Copy link
Copy Markdown
Contributor Author

@JS00001 please run translations script when you get a chance.

@OSBotify

This comment has been minimized.

@JmillsExpensify
JmillsExpensify self-requested a review October 19, 2026 17:37
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
@Krishna2323
Krishna2323 marked this pull request as ready for review October 19, 2026 18:24
@Krishna2323
Krishna2323 requested review from a team as code owners October 19, 2026 18:24
@OSBotify

OSBotify commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/JS00001 in version: 9.5.31-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@MelvinBot

MelvinBot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Help site update needed: the Duplicate Workspace article lists “Merchant rules,” but the option is now Expense defaults. Verified the label in the live web UI.

Created Rename workspace copy option to Expense defaults as a draft, labeled HelpDot and assigned to Krishna2323. It changes only that list item.

@Krishna2323, please review the linked help site PR and confirm it reflects the current behavior. Then mark the linked help site PR Ready for review

@albertodege

Copy link
Copy Markdown

Deploy Blocker #105855 was identified to be related to this PR.

@jponikarchuk

Copy link
Copy Markdown

Deploy Blocker #105859 was identified to be related to this PR.

@jponikarchuk

Copy link
Copy Markdown

Deploy Blocker #105862 was identified to be related to this PR.

Krishna2323 added a commit to Krishna2323/App that referenced this pull request Nov 4, 2026
…323/issue-102277-expense-defaults"

This reverts commit 5fe4be0, which added
amount and tag conditions to expense default rules.

Deploy blockers 105805, 105811, 105812, 105819 and 105862 all come from the
amount condition. Reverting clears them while the rules engine work continues.

The conflict in DynamicIOURequestStepCategoryCreate.tsx keeps main's version,
because useCreateAndApplyCategory landed after this PR and is not being
reverted.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
JS00001 added a commit that referenced this pull request Nov 4, 2026
…-expense-defaults

[cp staging] Revert "Merge pull request #104155 from Krishna2323/krishna2323/issue-102277-expense-defaults"
OSBotify pushed a commit that referenced this pull request Nov 4, 2026
…-expense-defaults

[cp staging] Revert "Merge pull request #104155 from Krishna2323/krishna2323/issue-102277-expense-defaults"

(cherry picked from commit fb50a47)

(cherry-picked to staging by blimpich)
@OSBotify

OSBotify commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/blimpich in version: 9.5.31-4 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Bundle Size Analysis (Sentry):

@OSBotify

OSBotify commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/JS00001 in version: 9.5.32-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@MelvinBot

Copy link
Copy Markdown
Contributor

FullStory changes recommended: add stable identifiers to the category-condition and tag-condition Save buttons. New screens already receive Page_viewed automatically.

Created Update FullStory for E/A#104155 Multi-condition expense defaults and category rule management, labeled Weekly and assigned to JmillsExpensify and Krishna2323. All three recommendations have high confidence.

@OSBotify

OSBotify commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/lakchote in version: 9.5.32-7 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

JS00001 pushed a commit that referenced this pull request Nov 13, 2026
…e-102277-expense-defaults"

This reverts commit 9f34259, restoring the amount and tag conditions on
expense default rules exactly as they were.

The resulting tree is byte for byte identical to main at 90b4be4, so this
commit carries no behavior change of its own. The beta gate that keeps the
feature off follows in the next commit.

Signed-off-by: krishna2323 <belivethatkg@gmail.com>
@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/JS00001 in version: 9.5.40-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/marcaaron in version: 9.5.40-1 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Bundle Size Analysis (Sentry):

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.