fix(accounting): transaction status improve#7737
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideUpdates transaction status categorization and visibility rules: backend now classifies more statuses as ACTIVE and introduces a CONVERSATION group, while frontend status group labels and dropdown rendering are aligned with the new grouping and visibility behavior based on user association with a transaction. Flow diagram for updated transaction visibility filter logicflowchart TD
A[generateFilter called
with user and params] --> B[Check if user exists]
B -->|yes| C[Initialize andFilter]
C --> D[Add $or filter]
D --> E[Condition 1:
status in TR_STATUSES.ACTIVE]
D --> F[Condition 2:
status in TR_STATUSES.CONVERSATION
AND user is associated]
F --> G[Subcondition:
createdBy equals user._id]
F --> H[Subcondition:
mentionOwnerId equals user._id]
F --> I[Subcondition:
mentionUserIds contains user._id]
E --> J[Return filter]
G --> J
H --> J
I --> J
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
📝 WalkthroughWalkthroughTransaction status handling is reorganized across backend and frontend. Backend constants introduce a new CONVERSATION grouping for conversation-level statuses while extending ACTIVE to include cancelled. Filtering logic updates to conditionally apply conversation statuses based on user relationships. Frontend labels switch from Mongolian to English display names, and UI rendering displays group headings in the status dropdown. ChangesTransaction Status Grouping and Display
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
generateFilter,status: TR_STATUSES.CONVERSATIONis now an array but is used like a scalar; this should likely bestatus: { $in: TR_STATUSES.CONVERSATION }to match howACTIVEis handled. - The new
TR_STATUSES.CONVERSATIONarray includes a status keyrejeced, which looks like a typo compared to the existingrejectedstatus naming and may cause mismatches when querying or filtering.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `generateFilter`, `status: TR_STATUSES.CONVERSATION` is now an array but is used like a scalar; this should likely be `status: { $in: TR_STATUSES.CONVERSATION }` to match how `ACTIVE` is handled.
- The new `TR_STATUSES.CONVERSATION` array includes a status key `rejeced`, which looks like a typo compared to the existing `rejected` status naming and may cause mismatches when querying or filtering.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
🌗 Pull Request OverviewThis PR improves the transaction status handling in the accounting module by adding 'cancelled' to the ACTIVE status filter and introducing a new CONVERSATION status category. It also refactors the transaction filtering logic and updates frontend UI labels from Mongolian to English. Reviewed Changes Show a summary per file
📋 Review Findings📄
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@backend/plugins/accounting_api/src/modules/accounting/graphql/resolvers/queries/transactionsCommon.ts`:
- Around line 349-355: The query is comparing status to an array constant
(TR_STATUSES.CONVERSATION) directly which never matches; update the filter to
use MongoDB membership operator by replacing the plain comparison with a $in
check (i.e., change the condition for status in the query object to use { $in:
TR_STATUSES.CONVERSATION }) so the status field is matched against any value in
the TR_STATUSES.CONVERSATION array; locate this in the transactions query block
in transactionsCommon.ts where status is currently set to
TR_STATUSES.CONVERSATION.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: ab2578d9-c139-429b-9917-57155f457ce0
📒 Files selected for processing (4)
backend/plugins/accounting_api/src/modules/accounting/@types/constants.tsbackend/plugins/accounting_api/src/modules/accounting/graphql/resolvers/queries/transactionsCommon.tsfrontend/plugins/accounting_ui/src/modules/transactions/transaction-form/components/TransactionsGroupForm.tsxfrontend/plugins/accounting_ui/src/modules/transactions/types/constants.tsx
| { | ||
| status: TR_STATUSES.CONVERSATION, $or: [ | ||
| { createdBy: user._id }, | ||
| { mentionOwnerId: user._id }, | ||
| { mentionUserIds: { $in: [user._id] } }, | ||
| ] | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# First, find and examine the file in question
cat -n backend/plugins/accounting_api/src/modules/accounting/graphql/resolvers/queries/transactionsCommon.ts | sed -n '340,365p'Repository: erxes/erxes
Length of output: 806
🏁 Script executed:
# Search for TR_STATUSES definition
rg "TR_STATUSES" backend/plugins/accounting_api/src --type ts -A 2 -B 2 | head -100Repository: erxes/erxes
Length of output: 9658
🏁 Script executed:
# Check for any constant files that might define TR_STATUSES
fd -e ts -e js backend/plugins/accounting_api/src | xargs rg "CONVERSATION" | grep -E "(const|export)" | head -20Repository: erxes/erxes
Length of output: 3532
🏁 Script executed:
# Find the constants file
find backend/plugins/accounting_api/src -name "constants*" -type fRepository: erxes/erxes
Length of output: 204
🏁 Script executed:
# Search for TR_STATUSES definition
rg "export.*TR_STATUSES" backend/plugins/accounting_api/src --type ts -A 30Repository: erxes/erxes
Length of output: 6094
Use $in for conversation status matching.
Line 350 compares status to an array of values directly, which won't match any documents. Since TR_STATUSES.CONVERSATION is an array (['draft', 'mentioned', 'approved', 'rejeced', 'returned', 'plan']), it requires the $in operator for membership filtering, as already used correctly on line 348 with TR_STATUSES.ACTIVE.
Proposed fix
{
- status: TR_STATUSES.CONVERSATION, $or: [
+ status: { $in: TR_STATUSES.CONVERSATION }, $or: [
{ createdBy: user._id },
{ mentionOwnerId: user._id },
{ mentionUserIds: { $in: [user._id] } },
]
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| { | |
| status: TR_STATUSES.CONVERSATION, $or: [ | |
| { createdBy: user._id }, | |
| { mentionOwnerId: user._id }, | |
| { mentionUserIds: { $in: [user._id] } }, | |
| ] | |
| } | |
| { | |
| status: { $in: TR_STATUSES.CONVERSATION }, $or: [ | |
| { createdBy: user._id }, | |
| { mentionOwnerId: user._id }, | |
| { mentionUserIds: { $in: [user._id] } }, | |
| ] | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@backend/plugins/accounting_api/src/modules/accounting/graphql/resolvers/queries/transactionsCommon.ts`
around lines 349 - 355, The query is comparing status to an array constant
(TR_STATUSES.CONVERSATION) directly which never matches; update the filter to
use MongoDB membership operator by replacing the plain comparison with a $in
check (i.e., change the condition for status in the query object to use { $in:
TR_STATUSES.CONVERSATION }) so the status field is matched against any value in
the TR_STATUSES.CONVERSATION array; locate this in the transactions query block
in transactionsCommon.ts where status is currently set to
TR_STATUSES.CONVERSATION.
|



Summary by Sourcery
Adjust transaction status classification and visibility rules across backend and frontend.
Bug Fixes:
Enhancements:
Summary by CodeRabbit
Release Notes