Skip to content

Fix account coa#25

Closed
ljain112 wants to merge 3 commits into
developfrom
fix-account-coa
Closed

Fix account coa#25
ljain112 wants to merge 3 commits into
developfrom
fix-account-coa

Conversation

@ljain112

@ljain112 ljain112 commented Aug 11, 2025

Copy link
Copy Markdown
Owner

The fix was incorrect. Root account creation is allowed from the charts of accounts.

The problem was an incorrect validation message.
Root Account should always be a group account.
But due to an incorrect validation error, a missing root type was thrown.

Issue: 0 being passed as a string.

Before:
image

After:
image

Summary by CodeRabbit

  • New Features

    • Create root accounts directly from the Accounts Tree.
    • “Add Child” is available on root nodes when applicable, simplifying top-level hierarchy building.
  • Bug Fixes

    • Root account validation now correctly enforces that a root must be a group, preventing invalid account configurations.

@coderabbitai

coderabbitai Bot commented Aug 11, 2025

Copy link
Copy Markdown

Walkthrough

Server-side account validation now coercively checks is_group using cint before decisions about root/group. Client-side COA tree UI guards were relaxed to allow creating root accounts and adding children to root nodes when nodes are expandable and not hidden.

Changes

Cohort / File(s) Summary
Server-side validation
erpnext/accounts/doctype/account/account.py
Replaced truthiness checks on is_group with cint(self.is_group) in set_root_and_report_type, validate_root_details, and validate_group_or_ledger to coerce non-boolean values before branching.
COA tree UI behavior
erpnext/accounts/doctype/account/account_tree.js
Removed guard that prevented creating a root-level account when the selected node is root; removed not is_root check from Add Child toolbar condition so root nodes can accept children when expandable and not hidden.

Sequence Diagram(s)

sequenceDiagram
  participant U as User
  participant UI as COA Tree UI
  participant S as Account DocType (Server)
  participant DB as Database

  U->>UI: Click "New" or "Add Child"
  UI->>S: Submit account creation request
  S->>S: validate_root_details() / validate_group_or_ledger()<br/>- use cint(is_group) for root/group checks
  S->>DB: Insert / Update account
  DB-->>S: Success / Error
  S-->>UI: Result (success or validation error)
  UI-->>U: Display outcome
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I nibble roots beneath the tree,
A tweak, a hop, now roots run free.
Coerce the groups, the branches sing,
New children grow where buttons bring.
A rabbit cheers—accounts take wing! 🐰🌿


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 63cc54d and d381e98.

📒 Files selected for processing (1)
  • erpnext/accounts/doctype/account/account.py (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • erpnext/accounts/doctype/account/account.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Patch Test
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-account-coa

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (2)
erpnext/accounts/doctype/account/account.py (1)

170-183: Standardize is_group checks to use cint

The truthiness checks on self.is_group can misbehave if the field is passed as "0"/"1". Normalize both occurrences to avoid subtle bugs:

• erpnext/accounts/doctype/account/account.py:170
• erpnext/accounts/doctype/account/account.py:262

@@ erpnext/accounts/doctype/account/account.py
-        if self.is_group:
+        if cint(self.is_group):
             db_value = self.get_doc_before_save()
             if db_value:
@@
-        elif self.is_group:
+        elif cint(self.is_group):
             if self.account_type and not self.flags.exclude_account_type_check:
                 throw(_("Cannot covert to Group because Account Type is selected."))
erpnext/accounts/doctype/account/account_tree.js (1)

230-244: Ensure “New” action respects ignore_root_company_validation

The primary “New” button currently always blocks when a root company is selected. To match the “Add Child” toolbar behavior (which allows creation when frappe.flags.ignore_root_company_validation is true), swap the condition order so that “New” also skips validation if that flag is set.

Locations to update:

  • erpnext/accounts/doctype/account/account_tree.js, inside the post_render → set_primary_action block

Revised diff:

@@ post_render: function (treeview) {
-    if (root_company) {
-        frappe.throw(__("Please add the account to root level Company - {0}"), [
-            root_company,
-        ]);
-    } else {
-        treeview.new_node();
-    }
+    // Allow account creation against child companies when flagged
+    if (!root_company || frappe.flags.ignore_root_company_validation) {
+        treeview.new_node();
+    } else {
+        frappe.throw(__("Please add the account to root level Company - {0}"), [
+            root_company,
+        ]);
+    }
🧹 Nitpick comments (1)
erpnext/accounts/doctype/account/account.py (1)

207-215: Add a regression test for is_group provided as a string

To prevent future regressions, add a test that creates a root account with is_group="0"/"1" as strings and asserts correct validation behavior (root requires group; child inherits root_type).

I can draft a pytest for Account.validate_root_details and set_root_and_report_type if you want.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3302795 and 63cc54d.

📒 Files selected for processing (2)
  • erpnext/accounts/doctype/account/account.py (1 hunks)
  • erpnext/accounts/doctype/account/account_tree.js (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Patch Test
🔇 Additional comments (2)
erpnext/accounts/doctype/account/account.py (1)

213-214: Robust root validation with cint(self.is_group) — good fix

Casting is_group avoids the "0" string pitfall and enforces that root must be a group. This aligns with the PR objective and prevents the incorrect Root Type validation from surfacing.

erpnext/accounts/doctype/account/account_tree.js (1)

257-258: Allowing Add Child on root nodes is consistent with permitting root-level maintenance

Removing the extra guard and relying on node.expandable and node.hide_add is appropriate. This matches the backend constraint that roots must be groups.

Please verify the UX flow when the selected root node is a ledger (non-expandable). The button should be disabled as intended due to node.expandable=false.

@ljain112 ljain112 closed this Aug 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant