feat: enhance account category with root type (#53190)

(cherry picked from commit f6639db0e9)
This commit is contained in:
Abdeali Chharchhodawala
2026-04-23 17:34:37 +05:30
committed by Mergify
parent 4f8184ec70
commit 96bab08ae0
6 changed files with 101 additions and 5 deletions

View File

@@ -0,0 +1,32 @@
import json
from pathlib import Path
import frappe
def execute():
base_path = Path(frappe.get_app_path("erpnext", "accounts")).resolve()
categories_file = (base_path / "financial_report_template" / "account_categories.json").resolve()
if not categories_file.exists():
return
categories = json.loads(frappe.read_file(str(categories_file)))
valid_root_types = set(frappe.get_meta("Account Category").get_field("root_type").options.split("\n"))
root_type_categories = {}
for category in categories:
if (root_type := category.get("root_type")) and root_type in valid_root_types:
root_type_categories.setdefault(root_type, []).append(category["account_category_name"])
if not root_type_categories:
return
for root_type, category_names in root_type_categories.items():
frappe.db.set_value(
"Account Category",
{"name": ["in", category_names], "root_type": ["is", "not set"]},
"root_type",
root_type,
)