Skip to content

Instantly share code, notes, and snippets.

@ManotLuijiu
Created March 24, 2025 16:39
Show Gist options
  • Save ManotLuijiu/5a3a121dc416301f4bb7a0dd9143344d to your computer and use it in GitHub Desktop.
Save ManotLuijiu/5a3a121dc416301f4bb7a0dd9143344d to your computer and use it in GitHub Desktop.
Example of creating workspace
# thai_business_suite/setup/__init__.py
from . import setup_default_workspace
def after_install():
"""Setup workspaces after app installation"""
setup_default_workspace.setup_workspaces()
# in hooks.py
after_install = "thai_business_suite.setup.after_install"
# thai_business_suite/setup/setup_default_workspace.py
import frappe
import json
import os
from frappe.desk.doctype.workspace.workspace import Workspace
def setup_workspaces():
"""Setup all default workspaces for Thai Business Suite"""
# Get the current module path
module_path = frappe.get_module_path("thai_business_suite")
# Path to workspace json files
workspace_path = os.path.join(module_path, "workspace")
# Setup each workspace
setup_thai_business_suite_workspace()
frappe.db.commit()
def setup_thai_business_suite_workspace():
"""Create the main Thai Business Suite workspace"""
workspace = {
"doctype": "Workspace",
"name": "Thai Business Suite",
"title": "Thai Business Suite",
"icon": "accounting", # You can choose appropriate icon
"is_standard": 1,
"module": "Thai Business Suite",
"public": 1,
"content": json.dumps([
{
"id": "main_section",
"type": "header",
"data": {
"text": "<span class=\"h4\">Thai Business Suite</span>",
"col": 12
}
},
{
"id": "description_section",
"type": "paragraph",
"data": {
"text": "Thai Business Suite for ERPNext",
"col": 12
}
},
{
"id": "thai_vat_section",
"type": "card",
"data": {
"card_name": "Thai VAT",
"col": 4
}
},
{
"id": "zkteco_section",
"type": "card",
"data": {
"card_name": "ZKTeco Integration",
"col": 4
}
}
]),
"links": [
{
"hidden": 0,
"is_query_report": 0,
"label": "Thai VAT",
"link_count": 2,
"onboard": 0,
"type": "Card Break"
},
{
"hidden": 0,
"is_query_report": 0,
"label": "Thai Purchase VAT",
"link_count": 0,
"link_to": "Thai Purchase VAT",
"link_type": "DocType",
"onboard": 0,
"type": "Link"
},
{
"hidden": 0,
"is_query_report": 1,
"label": "Thai Input VAT Report",
"link_count": 0,
"link_to": "Thai Input VAT Report",
"link_type": "Report",
"onboard": 0,
"type": "Link"
},
{
"hidden": 0,
"is_query_report": 0,
"label": "ZKTeco Integration",
"link_count": 2,
"onboard": 0,
"type": "Card Break"
},
{
"hidden": 0,
"is_query_report": 0,
"label": "ZKTeco Biometric Device",
"link_count": 0,
"link_to": "ZKTeco Biometric Device",
"link_type": "DocType",
"onboard": 0,
"type": "Link"
},
{
"hidden": 0,
"is_query_report": 0,
"label": "ZKTeco Settings",
"link_count": 0,
"link_to": "ZKTeco Biometric Settings",
"link_type": "DocType",
"onboard": 0,
"type": "Link"
}
]
}
# Check if workspace exists
if not frappe.db.exists("Workspace", workspace["name"]):
doc = frappe.new_doc("Workspace")
for key, value in workspace.items():
if key != "doctype":
doc.set(key, value)
doc.insert(ignore_permissions=True)
print(f"Workspace {workspace['name']} created")
else:
print(f"Workspace {workspace['name']} already exists")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment