2016-05-11 09:43:44 +00:00
|
|
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
|
|
|
# See license.txt
|
|
|
|
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
import frappe
|
|
|
|
|
2016-07-21 10:31:59 +00:00
|
|
|
def get_domain(domain):
|
2016-06-28 16:07:28 +00:00
|
|
|
'''Written as a function to prevent data mutation effects'''
|
2016-07-21 10:31:59 +00:00
|
|
|
data = {
|
2016-06-28 16:07:28 +00:00
|
|
|
'Manufacturing': {
|
|
|
|
'desktop_icons': ['Item', 'BOM', 'Customer', 'Supplier', 'Sales Order',
|
|
|
|
'Production Order', 'Stock Entry', 'Purchase Order', 'Task', 'Buying', 'Selling',
|
|
|
|
'Accounts', 'HR', 'ToDo'],
|
2016-07-21 10:31:59 +00:00
|
|
|
'remove_roles': ['Academics User'],
|
2016-06-28 16:07:28 +00:00
|
|
|
'properties': [
|
|
|
|
{'doctype': 'Item', 'fieldname': 'manufacturing', 'property': 'collapsible_depends_on', 'value': 'is_stock_item'},
|
|
|
|
],
|
|
|
|
'set_value': [
|
|
|
|
['Stock Settings', None, 'show_barcode_field', 1]
|
2016-07-21 10:31:59 +00:00
|
|
|
],
|
2016-09-23 16:21:51 +00:00
|
|
|
'default_portal_role': 'Customer'
|
2016-06-28 16:07:28 +00:00
|
|
|
},
|
2016-05-20 07:24:44 +00:00
|
|
|
|
2016-06-28 16:07:28 +00:00
|
|
|
'Retail': {
|
|
|
|
'desktop_icons': ['POS', 'Item', 'Customer', 'Sales Invoice', 'Purchase Order', 'Warranty Claim',
|
|
|
|
'Accounts', 'Buying', 'ToDo'],
|
2016-07-21 10:31:59 +00:00
|
|
|
'remove_roles': ['Manufacturing User', 'Manufacturing Manager', 'Academics User'],
|
2016-06-28 16:07:28 +00:00
|
|
|
'properties': [
|
|
|
|
{'doctype': 'Item', 'fieldname': 'manufacturing', 'property': 'hidden', 'value': 1},
|
|
|
|
{'doctype': 'Customer', 'fieldname': 'credit_limit_section', 'property': 'hidden', 'value': 1},
|
|
|
|
],
|
|
|
|
'set_value': [
|
|
|
|
['Stock Settings', None, 'show_barcode_field', 1]
|
2016-07-21 10:31:59 +00:00
|
|
|
],
|
2016-09-23 16:21:51 +00:00
|
|
|
'default_portal_role': 'Customer'
|
2016-06-28 16:07:28 +00:00
|
|
|
},
|
2016-05-20 07:24:44 +00:00
|
|
|
|
2016-06-28 16:07:28 +00:00
|
|
|
'Distribution': {
|
|
|
|
'desktop_icons': ['Item', 'Customer', 'Supplier', 'Lead', 'Sales Order',
|
|
|
|
'Sales Invoice', 'CRM', 'Selling', 'Buying', 'Stock', 'Accounts', 'HR', 'ToDo'],
|
2016-07-21 10:31:59 +00:00
|
|
|
'remove_roles': ['Manufacturing User', 'Manufacturing Manager', 'Academics User'],
|
2016-06-28 16:07:28 +00:00
|
|
|
'set_value': [
|
|
|
|
['Stock Settings', None, 'show_barcode_field', 1]
|
2016-07-21 10:31:59 +00:00
|
|
|
],
|
2016-09-23 16:21:51 +00:00
|
|
|
'default_portal_role': 'Customer'
|
2016-06-28 16:07:28 +00:00
|
|
|
},
|
2016-05-20 07:24:44 +00:00
|
|
|
|
2016-06-28 16:07:28 +00:00
|
|
|
'Services': {
|
2016-07-06 14:42:58 +00:00
|
|
|
'desktop_icons': ['Project', 'Timesheet', 'Customer', 'Sales Order', 'Sales Invoice', 'Lead', 'Opportunity',
|
2016-06-28 16:07:28 +00:00
|
|
|
'Expense Claim', 'Employee', 'HR', 'ToDo'],
|
2016-07-21 10:31:59 +00:00
|
|
|
'remove_roles': ['Manufacturing User', 'Manufacturing Manager', 'Academics User'],
|
2016-06-28 16:07:28 +00:00
|
|
|
'properties': [
|
|
|
|
{'doctype': 'Item', 'fieldname': 'is_stock_item', 'property': 'default', 'value': 0},
|
|
|
|
],
|
|
|
|
'set_value': [
|
|
|
|
['Stock Settings', None, 'show_barcode_field', 0]
|
2016-07-21 10:31:59 +00:00
|
|
|
],
|
2016-09-23 16:21:51 +00:00
|
|
|
'default_portal_role': 'Customer'
|
2016-07-21 10:31:59 +00:00
|
|
|
},
|
|
|
|
'Education': {
|
|
|
|
'desktop_icons': ['Student', 'Program', 'Course', 'Student Group', 'Instructor',
|
|
|
|
'Fees', 'ToDo', 'Schools'],
|
2016-09-20 11:52:54 +00:00
|
|
|
'allow_roles': ['Academics User', 'Accounts User', 'Accounts Manager', 'Item Manager',
|
2016-09-23 16:21:51 +00:00
|
|
|
'Website Manager', 'HR User', 'HR Manager', 'Purchase User', 'Purchase Manager',
|
|
|
|
'Student'],
|
|
|
|
'default_portal_role': 'Student'
|
2016-07-21 10:31:59 +00:00
|
|
|
},
|
2016-05-11 09:43:44 +00:00
|
|
|
}
|
2016-07-21 10:31:59 +00:00
|
|
|
if not domain in data:
|
|
|
|
raise 'Invalid Domain {0}'.format(domain)
|
|
|
|
return frappe._dict(data[domain])
|
2016-05-11 09:43:44 +00:00
|
|
|
|
|
|
|
def setup_domain(domain):
|
2016-07-21 10:31:59 +00:00
|
|
|
'''Setup roles, desktop icons, properties, values, portal sidebar menu based on domain'''
|
|
|
|
data = get_domain(domain)
|
|
|
|
setup_roles(data)
|
|
|
|
setup_desktop_icons(data)
|
|
|
|
setup_properties(data)
|
|
|
|
set_values(data)
|
|
|
|
setup_sidebar_items(data)
|
2016-09-23 16:21:51 +00:00
|
|
|
if data.get('default_portal_role'):
|
|
|
|
frappe.db.set_value('Portal Settings', None, 'default_role', data.get('default_portal_role'))
|
2016-07-21 10:31:59 +00:00
|
|
|
frappe.clear_cache()
|
2016-05-11 09:43:44 +00:00
|
|
|
|
2016-07-21 10:31:59 +00:00
|
|
|
def setup_desktop_icons(data):
|
|
|
|
'''set desktop icons form `data.desktop_icons`'''
|
2016-05-11 09:43:44 +00:00
|
|
|
from frappe.desk.doctype.desktop_icon.desktop_icon import set_desktop_icons
|
|
|
|
if data.desktop_icons:
|
|
|
|
set_desktop_icons(data.desktop_icons)
|
|
|
|
|
2016-07-21 10:31:59 +00:00
|
|
|
def setup_properties(data):
|
2016-05-11 09:43:44 +00:00
|
|
|
if data.properties:
|
|
|
|
for args in data.properties:
|
|
|
|
frappe.make_property_setter(args)
|
|
|
|
|
2016-07-21 10:31:59 +00:00
|
|
|
def setup_roles(data):
|
|
|
|
'''Add, remove roles from `data.allow_roles` or `data.remove_roles`'''
|
|
|
|
def remove_role(role):
|
|
|
|
frappe.db.sql('delete from tabUserRole where role=%s', role)
|
2016-10-25 09:31:30 +00:00
|
|
|
frappe.set_value('Role', role, 'disabled', 1)
|
2016-07-21 10:31:59 +00:00
|
|
|
|
|
|
|
if data.remove_roles:
|
|
|
|
for role in data.remove_roles:
|
|
|
|
remove_role(role)
|
|
|
|
|
|
|
|
if data.allow_roles:
|
|
|
|
# remove all roles other than allowed roles
|
2016-11-05 04:39:53 +00:00
|
|
|
data.allow_roles += ['Administrator', 'Guest', 'System Manager', 'All']
|
2016-07-21 10:31:59 +00:00
|
|
|
for role in frappe.get_all('Role'):
|
|
|
|
if not (role.name in data.allow_roles):
|
|
|
|
remove_role(role.name)
|
|
|
|
|
|
|
|
def set_values(data):
|
|
|
|
'''set values based on `data.set_value`'''
|
2016-05-12 10:56:01 +00:00
|
|
|
if data.set_value:
|
|
|
|
for args in data.set_value:
|
|
|
|
doc = frappe.get_doc(args[0], args[1] or args[0])
|
|
|
|
doc.set(args[2], args[3])
|
|
|
|
doc.save()
|
|
|
|
|
2016-07-21 10:31:59 +00:00
|
|
|
def setup_sidebar_items(data):
|
|
|
|
'''Enable / disable sidebar items'''
|
|
|
|
if data.allow_sidebar_items:
|
|
|
|
# disable all
|
|
|
|
frappe.db.sql('update `tabPortal Menu Item` set enabled=0')
|
|
|
|
|
|
|
|
# enable
|
|
|
|
frappe.db.sql('''update `tabPortal Menu Item` set enabled=1
|
|
|
|
where route in ({0})'''.format(', '.join(['"{0}"'.format(d) for d in data.allow_sidebar_items])))
|
|
|
|
|
|
|
|
if data.remove_sidebar_items:
|
|
|
|
# disable all
|
|
|
|
frappe.db.sql('update `tabPortal Menu Item` set enabled=1')
|
|
|
|
|
|
|
|
# enable
|
|
|
|
frappe.db.sql('''update `tabPortal Menu Item` set enabled=0
|
|
|
|
where route in ({0})'''.format(', '.join(['"{0}"'.format(d) for d in data.remove_sidebar_items])))
|
|
|
|
|
2016-05-11 09:43:44 +00:00
|
|
|
|
|
|
|
def reset():
|
|
|
|
from frappe.desk.page.setup_wizard.setup_wizard import add_all_roles_to
|
|
|
|
add_all_roles_to('Administrator')
|
|
|
|
|
2016-06-28 16:07:28 +00:00
|
|
|
frappe.db.sql('delete from `tabProperty Setter`')
|