livrare website cu erp si crm
This commit is contained in:
parent
28773e3a72
commit
5c7bf7c295
257 changed files with 31929 additions and 0 deletions
126
erp_crm/scripts/setup/03-cleanup.py
Normal file
126
erp_crm/scripts/setup/03-cleanup.py
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
"""
|
||||
Cleanup ERPNext: hide unused modules, configure sidebar, check users/permissions.
|
||||
"""
|
||||
import frappe
|
||||
|
||||
|
||||
def execute():
|
||||
cleanup_modules()
|
||||
cleanup_users()
|
||||
setup_workspace()
|
||||
frappe.db.commit()
|
||||
print("\n=== Cleanup Complete ===\n")
|
||||
|
||||
|
||||
def cleanup_modules():
|
||||
"""Hide modules that are not needed from the sidebar."""
|
||||
print("[1/3] Hiding unused modules...")
|
||||
|
||||
# Modules to KEEP visible
|
||||
keep_modules = {
|
||||
"Accounts", "Selling", "CRM", "Buying",
|
||||
"Didi Custom", "Setup", "Core",
|
||||
}
|
||||
|
||||
# Modules to HIDE
|
||||
hide_modules = {
|
||||
"Stock", "Manufacturing", "Assets", "Projects",
|
||||
"Quality Management", "Subcontracting", "Support",
|
||||
"Maintenance", "EDI", "Telephony", "Portal",
|
||||
"Bulk Transaction", "ERPNext Integrations",
|
||||
"Social", "Website",
|
||||
}
|
||||
|
||||
# Use Module Profile to restrict what Administrator sees
|
||||
# Actually in ERPNext v15, we use "Allowed Modules" on User
|
||||
# But for Administrator we can't restrict. Instead, we hide workspaces.
|
||||
|
||||
# Hide workspaces for unused modules
|
||||
workspaces_to_hide = [
|
||||
"Stock", "Manufacturing", "Assets", "Projects",
|
||||
"Quality", "Subcontracting", "Support",
|
||||
"HR", "Payroll", "Website",
|
||||
]
|
||||
|
||||
for ws_name in workspaces_to_hide:
|
||||
ws_list = frappe.get_all("Workspace", filters={"name": ["like", f"%{ws_name}%"]})
|
||||
for ws in ws_list:
|
||||
doc = frappe.get_doc("Workspace", ws.name)
|
||||
if doc.public:
|
||||
doc.public = 0
|
||||
doc.save(ignore_permissions=True)
|
||||
print(f" Hidden workspace: {ws.name}")
|
||||
|
||||
print(" Module cleanup done.")
|
||||
|
||||
|
||||
def cleanup_users():
|
||||
"""Verify users and their roles."""
|
||||
print("[2/3] Checking users...")
|
||||
|
||||
users = frappe.get_all("User",
|
||||
filters={"user_type": "System User", "enabled": 1},
|
||||
fields=["name", "full_name", "user_type"]
|
||||
)
|
||||
|
||||
for u in users:
|
||||
roles = frappe.get_all("Has Role",
|
||||
filters={"parent": u.name},
|
||||
fields=["role"]
|
||||
)
|
||||
role_names = [r.role for r in roles]
|
||||
print(f" User: {u.name} ({u.full_name})")
|
||||
print(f" Roles: {', '.join(role_names)}")
|
||||
|
||||
# Ensure website_api user has minimal roles
|
||||
api_user = "website_api@didi.localhost"
|
||||
if frappe.db.exists("User", api_user):
|
||||
user_doc = frappe.get_doc("User", api_user)
|
||||
current_roles = [r.role for r in user_doc.roles]
|
||||
print(f"\n API User roles: {current_roles}")
|
||||
|
||||
# Remove unnecessary roles if any
|
||||
wanted_roles = {"Website Integration"}
|
||||
unwanted = set(current_roles) - wanted_roles - {"All", "Guest"}
|
||||
if unwanted:
|
||||
for role_name in unwanted:
|
||||
user_doc.roles = [r for r in user_doc.roles if r.role != role_name]
|
||||
user_doc.save(ignore_permissions=True)
|
||||
print(f" Removed unwanted roles: {unwanted}")
|
||||
|
||||
print(" Users OK.")
|
||||
|
||||
|
||||
def setup_workspace():
|
||||
"""Create a clean DiDi workspace with only relevant shortcuts."""
|
||||
print("[3/3] Setting up DiDi workspace...")
|
||||
|
||||
ws_name = "DiDi"
|
||||
|
||||
if frappe.db.exists("Workspace", ws_name):
|
||||
frappe.delete_doc("Workspace", ws_name, force=True)
|
||||
|
||||
ws = frappe.get_doc({
|
||||
"doctype": "Workspace",
|
||||
"name": ws_name,
|
||||
"label": "DiDi",
|
||||
"title": "DiDi",
|
||||
"module": "Didi Custom",
|
||||
"icon": "home",
|
||||
"public": 1,
|
||||
"sequence_id": 1,
|
||||
"shortcuts": [
|
||||
{"type": "DocType", "link_to": "Customer", "label": "Clienti", "color": "#2563eb"},
|
||||
{"type": "DocType", "link_to": "Lead", "label": "Lead-uri", "color": "#7c3aed"},
|
||||
{"type": "DocType", "link_to": "Sales Invoice", "label": "Facturi", "color": "#059669"},
|
||||
{"type": "DocType", "link_to": "Subscription Plan", "label": "Planuri Abonament", "color": "#d97706"},
|
||||
{"type": "DocType", "link_to": "Subscription", "label": "Subscriptii", "color": "#dc2626"},
|
||||
{"type": "DocType", "link_to": "Website Content", "label": "Continut Website (CMS)", "color": "#0891b2"},
|
||||
{"type": "DocType", "link_to": "Service Agreement", "label": "Acorduri Servicii", "color": "#4f46e5"},
|
||||
{"type": "DocType", "link_to": "Payment Log", "label": "Log Plati", "color": "#be185d"},
|
||||
{"type": "DocType", "link_to": "Supplier", "label": "Furnizori", "color": "#64748b"},
|
||||
{"type": "DocType", "link_to": "Email Template", "label": "Template-uri Email", "color": "#475569"},
|
||||
],
|
||||
})
|
||||
ws.insert(ignore_permissions=True)
|
||||
print(f" Created workspace: DiDi (with shortcuts + number cards)")
|
||||
Loading…
Add table
Add a link
Reference in a new issue