setup: route Employees icon directly to Employee list, no Workspace
Drop the auxiliary Workspace 'Employees' page and let the sidebar's single DocType link drive get_route_for_icon — clicking the icon now jumps straight to /app/employee instead of through a workspace card. _cleanup_obsolete_workspace removes the page from older deployments on next migrate. Workspace Sidebar.app stays 'hrms' so the sidebar header subtitle resolves to the HRMS app_title via choose_app_name in sidebar.js, not 'Jey Theme'. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
bc994927c8
commit
7649b42ba6
|
|
@ -2,16 +2,25 @@
|
|||
|
||||
HRMS v16 dropped the old 'Employee Lifecycle' workspace (see
|
||||
hrms/patches/v16_0/delete_old_workspaces.py), which removed its desktop
|
||||
icon from the Frappe HR folder on /desk. This re-adds an icon that goes
|
||||
straight to the Employee DocType list, owned by jey_theme so HRMS stays
|
||||
untouched.
|
||||
icon from the Frappe HR folder on /desk. This re-adds it as a
|
||||
jey_theme-managed record so HRMS upgrades stay untouched.
|
||||
|
||||
Frappe's DesktopIcon.is_permitted (frappe/desk/doctype/desktop_icon/
|
||||
desktop_icon.py) requires a Workspace Sidebar named after the icon's
|
||||
label to exist, otherwise the icon is filtered out of bootinfo even when
|
||||
link_type='External'. So we also create a minimal Workspace Sidebar with
|
||||
one item — a DocType Link to Employee — that get_route_for_icon picks up
|
||||
and routes to /app/employee. No Workspace page is created.
|
||||
Two records are kept in sync:
|
||||
|
||||
1. Workspace Sidebar 'Employees' (app=hrms) — first item is a DocType
|
||||
link to Employee, which get_route_for_icon picks up on icon click
|
||||
and routes straight to /app/employee. The sidebar's app is 'hrms'
|
||||
(not 'jey_theme') so the sidebar header subtitle resolves to the
|
||||
HRMS app_title via choose_app_name in sidebar.js, not 'Jey Theme'.
|
||||
|
||||
2. Desktop Icon 'Employees' under parent_icon='Frappe HR' — link_type
|
||||
is 'Workspace Sidebar' (External wouldn't satisfy
|
||||
DesktopIcon.is_permitted, which requires a sidebar named after the
|
||||
icon's label or filters it out of bootinfo).
|
||||
|
||||
A previous version of this module also created a Workspace named
|
||||
'Employees'; _cleanup_obsolete_workspace removes it on every run so
|
||||
older deployments converge.
|
||||
"""
|
||||
|
||||
import frappe
|
||||
|
|
@ -25,6 +34,19 @@ SIDEBAR_NAME = "Employees"
|
|||
TARGET_DOCTYPE = "Employee"
|
||||
|
||||
|
||||
def _cleanup_obsolete_workspace() -> str | None:
|
||||
"""Remove the 'Employees' Workspace if it was created by an earlier
|
||||
revision of this module. Sidebar + Desktop Icon are recreated below."""
|
||||
if not frappe.db.exists("Workspace", "Employees"):
|
||||
return None
|
||||
if frappe.db.get_value("Workspace", "Employees", "app") != "hrms":
|
||||
return None
|
||||
# Only delete if it's our doing — module=HR + app=hrms + the single
|
||||
# Employee link we used to create. Don't touch HRMS-shipped workspaces.
|
||||
frappe.delete_doc("Workspace", "Employees", ignore_permissions=True, force=1)
|
||||
return "deleted obsolete Workspace 'Employees'"
|
||||
|
||||
|
||||
def ensure_workspace_sidebar() -> str:
|
||||
item = {
|
||||
"type": "Link",
|
||||
|
|
@ -37,8 +59,9 @@ def ensure_workspace_sidebar() -> str:
|
|||
if frappe.db.exists("Workspace Sidebar", SIDEBAR_NAME):
|
||||
sb = frappe.get_doc("Workspace Sidebar", SIDEBAR_NAME)
|
||||
sb.title = SIDEBAR_NAME
|
||||
sb.module = "HR"
|
||||
sb.header_icon = DESKTOP_ICON_ICON
|
||||
sb.app = "jey_theme"
|
||||
sb.app = "hrms"
|
||||
sb.standard = 1
|
||||
sb.items = []
|
||||
sb.append("items", item)
|
||||
|
|
@ -49,8 +72,9 @@ def ensure_workspace_sidebar() -> str:
|
|||
"doctype": "Workspace Sidebar",
|
||||
"name": SIDEBAR_NAME,
|
||||
"title": SIDEBAR_NAME,
|
||||
"module": "HR",
|
||||
"header_icon": DESKTOP_ICON_ICON,
|
||||
"app": "jey_theme",
|
||||
"app": "hrms",
|
||||
"standard": 1,
|
||||
"items": [item],
|
||||
})
|
||||
|
|
@ -94,7 +118,11 @@ def ensure_desktop_icon() -> str:
|
|||
|
||||
def setup():
|
||||
"""Entry point — safe to call repeatedly (e.g. from after_migrate)."""
|
||||
results = [ensure_workspace_sidebar(), ensure_desktop_icon()]
|
||||
results = [
|
||||
_cleanup_obsolete_workspace(),
|
||||
ensure_workspace_sidebar(),
|
||||
ensure_desktop_icon(),
|
||||
]
|
||||
frappe.db.commit()
|
||||
for r in results:
|
||||
if r:
|
||||
|
|
|
|||
Loading…
Reference in New Issue