-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall_dashboard.py
More file actions
108 lines (88 loc) · 3.03 KB
/
Copy pathinstall_dashboard.py
File metadata and controls
108 lines (88 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env python3
"""
Install Employee Check-in Dashboard
This script creates the workspace and dashboard charts in the database
"""
import frappe
from frappe import _
import json
import os
def install_dashboard():
"""Install the Employee Check-in Dashboard workspace and charts"""
frappe.init(site='hrms.hamptons.om')
frappe.connect()
app_path = frappe.get_app_path('hamptons')
# Install Workspace
print("Installing Employee Check-in Dashboard Workspace...")
workspace_path = os.path.join(app_path, 'hamptons', 'workspace', 'employee_checkin_dashboard.json')
try:
with open(workspace_path, 'r') as f:
workspace_data = json.load(f)
# Check if workspace already exists
if frappe.db.exists('Workspace', 'Employee Check-in Dashboard'):
print(" Workspace already exists, updating...")
doc = frappe.get_doc('Workspace', 'Employee Check-in Dashboard')
doc.update(workspace_data)
doc.save()
else:
print(" Creating new workspace...")
doc = frappe.get_doc(workspace_data)
doc.insert()
frappe.db.commit()
print(" ✓ Workspace installed successfully")
except Exception as e:
print(f" ✗ Error installing workspace: {str(e)}")
frappe.db.rollback()
# Install Dashboard Charts
chart_files = [
'daily_check_ins_overview.json',
'department_wise_attendance.json',
'check_in_time_distribution.json'
]
chart_path = os.path.join(app_path, 'hamptons', 'dashboard_chart')
for chart_file in chart_files:
print(f"Installing chart: {chart_file}...")
try:
with open(os.path.join(chart_path, chart_file), 'r') as f:
chart_data = json.load(f)
chart_name = chart_data.get('name') or chart_data.get('chart_name')
# Check if chart already exists
if frappe.db.exists('Dashboard Chart', chart_name):
print(f" Chart '{chart_name}' already exists, updating...")
doc = frappe.get_doc('Dashboard Chart', chart_name)
doc.update(chart_data)
doc.save()
else:
print(f" Creating new chart '{chart_name}'...")
doc = frappe.get_doc(chart_data)
doc.insert()
frappe.db.commit()
print(f" ✓ Chart installed successfully")
except Exception as e:
print(f" ✗ Error installing chart: {str(e)}")
frappe.db.rollback()
# Install Number Cards
print("Installing Number Cards...")
if 'number_cards' in workspace_data:
for card in workspace_data['number_cards']:
try:
card_name = card.get('name')
if frappe.db.exists('Number Card', card_name):
print(f" Number Card '{card_name}' already exists, skipping...")
else:
print(f" Creating Number Card '{card_name}'...")
card_doc = frappe.get_doc({
'doctype': 'Number Card',
**card
})
card_doc.insert()
frappe.db.commit()
print(f" ✓ Number Card installed")
except Exception as e:
print(f" ✗ Error installing number card: {str(e)}")
frappe.db.rollback()
print("\n✅ Dashboard installation complete!")
print("Access it at: http://hrms.hamptons.om/app/employee-check-in-dashboard")
frappe.destroy()
if __name__ == '__main__':
install_dashboard()