fix: add error handling and safe attribute access in boot_session_handler
Problem: - boot_session_handler was failing silently for some DocTypes - Direct access to field.js_parent_subtab caused AttributeError - DocTypes with errors prevented entire hierarchy from being built Solution: - Added try-except around DocType processing loop - Changed field.js_parent_subtab to getattr(field, 'js_parent_subtab', None) - Errors are logged but don't break the entire boot process Result: - All DocTypes with subtabs now properly included in tab_hierarchy - "Declaration of value added tax" and similar DocTypes now work correctly Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
ff3924f0fd
commit
751de46b7b
|
|
@ -6,32 +6,37 @@ def boot_session_handler(bootinfo):
|
||||||
tab_hierarchy_data = {}
|
tab_hierarchy_data = {}
|
||||||
|
|
||||||
for doctype in all_doctypes:
|
for doctype in all_doctypes:
|
||||||
meta = frappe.get_meta(doctype["name"])
|
try:
|
||||||
|
meta = frappe.get_meta(doctype["name"])
|
||||||
|
|
||||||
# Проверяем, есть ли вкладки (Tab Break) в Doctype
|
# Проверяем, есть ли вкладки (Tab Break) в Doctype
|
||||||
if not any(field.fieldtype == "Tab Break" for field in meta.fields):
|
if not any(field.fieldtype == "Tab Break" for field in meta.fields):
|
||||||
|
continue
|
||||||
|
|
||||||
|
tabs = []
|
||||||
|
subtabs = {}
|
||||||
|
|
||||||
|
for field in meta.fields:
|
||||||
|
if field.fieldtype == "Tab Break":
|
||||||
|
tab_name = field.label
|
||||||
|
js_parent = getattr(field, 'js_parent_subtab', None) or None
|
||||||
|
|
||||||
|
if js_parent:
|
||||||
|
if js_parent not in subtabs:
|
||||||
|
subtabs[js_parent] = []
|
||||||
|
subtabs[js_parent].append(tab_name)
|
||||||
|
else:
|
||||||
|
tabs.append(tab_name)
|
||||||
|
|
||||||
|
# Добавляем данные для Doctype
|
||||||
|
tab_hierarchy_data[doctype["name"]] = {
|
||||||
|
"tabs": tabs,
|
||||||
|
"subtabs": subtabs
|
||||||
|
}
|
||||||
|
except Exception as e:
|
||||||
|
# Пропускаем DocTypes с ошибками, но не ломаем весь boot
|
||||||
|
frappe.log_error(f"Error processing subtabs for {doctype['name']}: {str(e)}", "Custom Subtabs Boot Error")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
tabs = []
|
|
||||||
subtabs = {}
|
|
||||||
|
|
||||||
for field in meta.fields:
|
|
||||||
if field.fieldtype == "Tab Break":
|
|
||||||
tab_name = field.label
|
|
||||||
js_parent = field.js_parent_subtab or None
|
|
||||||
|
|
||||||
if js_parent:
|
|
||||||
if js_parent not in subtabs:
|
|
||||||
subtabs[js_parent] = []
|
|
||||||
subtabs[js_parent].append(tab_name)
|
|
||||||
else:
|
|
||||||
tabs.append(tab_name)
|
|
||||||
|
|
||||||
# Добавляем данные для Doctype
|
|
||||||
tab_hierarchy_data[doctype["name"]] = {
|
|
||||||
"tabs": tabs,
|
|
||||||
"subtabs": subtabs
|
|
||||||
}
|
|
||||||
|
|
||||||
# Передаём данные на клиентскую сторону через bootinfo
|
# Передаём данные на клиентскую сторону через bootinfo
|
||||||
bootinfo.tab_hierarchy = tab_hierarchy_data
|
bootinfo.tab_hierarchy = tab_hierarchy_data
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue