From 20038ad2c940ae128e013d708d5284d58a1ba41e Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 21 Jul 2016 16:01:59 +0530 Subject: [PATCH] [fixes] setup wizard and domainify for schools; --- erpnext/config/desktop.py | 106 ++++++++++ erpnext/config/schools.py | 110 +++++++++++ erpnext/patches.txt | 1 + .../v7_0/migrate_schools_to_erpnext.py | 12 +- erpnext/public/js/setup_wizard.js | 183 +++++++++++++++--- .../doctype/announcement/announcement.json | 25 +-- erpnext/schools/doctype/fees/fees.json | 44 +---- erpnext/setup/setup_wizard/domainify.py | 92 +++++++-- erpnext/setup/setup_wizard/setup_wizard.py | 53 +++++ 9 files changed, 510 insertions(+), 116 deletions(-) create mode 100644 erpnext/config/schools.py diff --git a/erpnext/config/desktop.py b/erpnext/config/desktop.py index fc2be827b6a..df2a0ee1f91 100644 --- a/erpnext/config/desktop.py +++ b/erpnext/config/desktop.py @@ -164,5 +164,111 @@ def get_data(): "icon": "octicon octicon-tools", "type": "module", "label": _("Maintenance") + }, + { + "module_name": "Student", + "color": "#c0392b", + "icon": "octicon octicon-person", + "label": _("Student"), + "link": "List/Student", + "doctype": "Student", + "type": "list" + }, + { + "module_name": "Student Group", + "color": "#d59919", + "icon": "octicon octicon-organization", + "label": _("Student Group"), + "link": "List/Student Group", + "doctype": "Student Group", + "type": "list" + }, + { + "module_name": "Course Schedule", + "color": "#fd784f", + "icon": "octicon octicon-calendar", + "label": _("Course Schedule"), + "link": "Calendar/Course Schedule", + "doctype": "Course Schedule", + "type": "list" + }, + { + "module_name": "Student Attendance", + "color": "#3aacba", + "icon": "octicon octicon-checklist", + "label": _("Student Attendance"), + "link": "List/Student Attendance", + "doctype": "Student Attendance", + "type": "list" + }, + { + "module_name": "Course", + "color": "#8e44ad", + "icon": "octicon octicon-book", + "label": _("Course"), + "link": "List/Course", + "doctype": "Course", + "type": "list" + }, + { + "module_name": "Program", + "color": "#9b59b6", + "icon": "octicon octicon-repo", + "label": _("Program"), + "link": "List/Program", + "doctype": "Program", + "type": "list" + }, + { + "module_name": "Student Applicant", + "color": "#4d927f", + "icon": "octicon octicon-clippy", + "label": _("Student Applicant"), + "link": "List/Student Applicant", + "doctype": "Student Applicant", + "type": "list" + }, + { + "module_name": "Examination", + "color": "#8a70be", + "icon": "icon-file-text-alt", + "label": _("Examination"), + "link": "List/Examination", + "doctype": "Examination", + "type": "list" + }, + { + "module_name": "Fees", + "color": "#83C21E", + "icon": "icon-money", + "label": _("Fees"), + "link": "List/Fees", + "doctype": "Fees", + "type": "list" + }, + { + "module_name": "Instructor", + "color": "#a99e4c", + "icon": "octicon octicon-broadcast", + "label": _("Instructor"), + "link": "List/Instructor", + "doctype": "Instructor", + "type": "list" + }, + { + "module_name": "Room", + "color": "#f22683", + "icon": "icon-map-marker", + "label": _("Room"), + "link": "List/Room", + "doctype": "Examination", + "type": "list" + }, + { + "module_name": "Schools", + "color": "#DE2B37", + "icon": "octicon octicon-mortar-board", + "type": "module", + "label": _("Schools") } ] diff --git a/erpnext/config/schools.py b/erpnext/config/schools.py new file mode 100644 index 00000000000..ee1a8cbf1ae --- /dev/null +++ b/erpnext/config/schools.py @@ -0,0 +1,110 @@ +from __future__ import unicode_literals +from frappe import _ + +def get_data(): + return [ + { + "label": _("Student"), + "items": [ + + { + "type": "doctype", + "name": "Student" + }, + { + "type": "doctype", + "name": "Student Group" + }, + { + "type": "doctype", + "name": "Student Applicant" + }, + { + "type": "doctype", + "name": "Program Enrollment" + }, + { + "type": "doctype", + "name": "Program Enrollment Tool" + }, + { + "type": "doctype", + "name": "Student Group Creation Tool" + } + ] + }, + { + "label": _("Schedule"), + "items": [ + { + "type": "doctype", + "name": "Course Schedule", + "route": "Calendar/Course Schedule" + }, + { + "type": "doctype", + "name": "Student Attendance" + }, + { + "type": "doctype", + "name": "Scheduling Tool" + }, + { + "type": "doctype", + "name": "Examination" + } + ] + }, + { + "label": _("Fees"), + "items": [ + { + "type": "doctype", + "name": "Fees" + }, + { + "type": "doctype", + "name": "Fee Structure" + }, + { + "type": "doctype", + "name": "Fee Category" + }, + { + "type": "report", + "name": "Student Fee Collection", + "doctype": "Fees", + "is_query_report": True + } + ] + }, + { + "label": _("Setup"), + "items": [ + { + "type": "doctype", + "name": "Course" + }, + { + "type": "doctype", + "name": "Program" + }, + { + "type": "doctype", + "name": "Instructor" + }, + { + "type": "doctype", + "name": "Room" + }, + { + "type": "doctype", + "name": "Academic Term" + }, + { + "type": "doctype", + "name": "Academic Year" + } + ] + }, + ] diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 699a745f240..d211ca9d772 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -299,3 +299,4 @@ execute:frappe.delete_doc_if_exists("Report", "Employee Holiday Attendance") execute:frappe.delete_doc_if_exists("DocType", "Payment Tool") execute:frappe.delete_doc_if_exists("DocType", "Payment Tool Detail") erpnext.patches.v7_0.setup_account_table_for_expense_claim_type_if_exists +erpnext.patches.v7_0.migrate_schools_to_erpnext diff --git a/erpnext/patches/v7_0/migrate_schools_to_erpnext.py b/erpnext/patches/v7_0/migrate_schools_to_erpnext.py index 95ab16c97a9..ca37e694836 100644 --- a/erpnext/patches/v7_0/migrate_schools_to_erpnext.py +++ b/erpnext/patches/v7_0/migrate_schools_to_erpnext.py @@ -1,7 +1,13 @@ from __future__ import unicode_literals import frappe +from erpnext.setup.setup_wizard import domainify def execute(): - frappe.db.sql("""update `tabDoctype` set module='Schools' where module='Academics'""") - from frappe.installer import remove_from_installed_apps - remove_from_installed_apps("schools") \ No newline at end of file + frappe.get_doc('Portal Settings', 'Portal Settings').sync_menu() + if 'schools' in frappe.get_installed_apps(): + frappe.db.sql("""update `tabDoctype` set module='Schools' where module='Academics'""") + from frappe.installer import remove_from_installed_apps + remove_from_installed_apps("schools") + domainify.setup_domain('Education') + else: + domainify.setup_sidebar_items(domainify.get_domain('Manufacturing')) diff --git a/erpnext/public/js/setup_wizard.js b/erpnext/public/js/setup_wizard.js index 9954ae03cea..4da4ce2a74c 100644 --- a/erpnext/public/js/setup_wizard.js +++ b/erpnext/public/js/setup_wizard.js @@ -9,28 +9,49 @@ frappe.pages['setup-wizard'].on_page_load = function(wrapper) { function load_erpnext_slides() { $.extend(erpnext.wiz, { - org: { - app_name: "erpnext", - title: __("The Organization"), - icon: "icon-building", + select_domain: { + domains: ["all"], + title: __('Select your Domain'), fields: [ - {fieldname:'company_name', label: __('Company Name'), fieldtype:'Data', reqd:1, - placeholder: __('e.g. "My Company LLC"')}, - {fieldname:'company_abbr', label: __('Company Abbreviation'), fieldtype:'Data', - description: __('Max 5 characters'), placeholder: __('e.g. "MC"'), reqd:1}, - {fieldname:'company_tagline', label: __('What does it do?'), fieldtype:'Data', - placeholder:__('e.g. "Build tools for builders"'), reqd:1}, - {fieldname:'bank_account', label: __('Bank Name'), fieldtype:'Data', - placeholder: __('e.g. "XYZ National Bank"'), reqd:1 }, {fieldname:'domain', label: __('Domain'), fieldtype:'Select', options: [ {"label": __("Distribution"), "value": "Distribution"}, + {"label": __("Education"), "value": "Education"}, {"label": __("Manufacturing"), "value": "Manufacturing"}, {"label": __("Retail"), "value": "Retail"}, - {"label": __("Services"), "value": "Services"}, - {"label": __("Education"), "value": "Education"}, - {"label": __("Other"), "value": "Other"}, + {"label": __("Services"), "value": "Services"} ], reqd:1}, + ], + help: __('Select the nature of your business.'), + onload: function(slide) { + slide.get_input("domain").on("change", function() { + frappe.wiz.domain = $(this).val(); + frappe.wizard.refresh_slides(); + }); + }, + css_class: "single-column" + }, + org: { + domains: ["all"], + title: __("The Organization"), + icon: "icon-building", + fields: [ + {fieldname:'company_name', + label: frappe.wiz.domain==='Education' ? + __('Institute Name') : __('Company Name'), + fieldtype:'Data', reqd:1}, + {fieldname:'company_abbr', + label: frappe.wiz.domain==='Education' ? + __('Institute Abbreviation') : __('Company Abbreviation'), + fieldtype:'Data'}, + {fieldname:'company_tagline', + label: __('What does it do?'), + fieldtype:'Data', + placeholder: frappe.wiz.domain==='Education' ? + __('e.g. "Primary School" or "University"') : + __('e.g. "Build tools for builders"'), + reqd:1}, + {fieldname:'bank_account', label: __('Bank Name'), fieldtype:'Data', reqd:1}, {fieldname:'chart_of_accounts', label: __('Chart of Accounts'), options: "", fieldtype: 'Select'}, @@ -41,7 +62,9 @@ function load_erpnext_slides() { {fieldname:'fy_end_date', label:__('Financial Year End Date'), fieldtype:'Date', description: __('Your financial year ends on'), reqd:1}, ], - help: __('The name of your company for which you are setting up this system.'), + help: (frappe.wiz.domain==='Education' ? + __('The name of the institute for which you are setting up this system.'): + __('The name of your company for which you are setting up this system.')), onload: function(slide) { erpnext.wiz.org.load_chart_of_accounts(slide); @@ -67,7 +90,7 @@ function load_erpnext_slides() { css_class: "single-column", set_fy_dates: function(slide) { - var country = slide.wiz.get_values().country; + var country = frappe.wizard.values.country; if(country) { var fy = erpnext.wiz.fiscal_years[country]; @@ -85,7 +108,7 @@ function load_erpnext_slides() { }, load_chart_of_accounts: function(slide) { - var country = slide.wiz.get_values().country; + var country = frappe.wizard.values.country; if(country) { frappe.call({ @@ -134,7 +157,7 @@ function load_erpnext_slides() { }, branding: { - app_name: "erpnext", + domains: ["all"], icon: "icon-bookmark", title: __("The Brand"), help: __('Upload your letter head and logo. (you can edit them later).'), @@ -156,7 +179,7 @@ function load_erpnext_slides() { }, users: { - app_name: "erpnext", + domains: ["all"], icon: "icon-money", title: __("Add Users"), help: __("Add users to your organization, other than yourself"), @@ -173,11 +196,14 @@ function load_erpnext_slides() { options: "Email"}, {fieldtype:"Column Break"}, {fieldtype: "Check", fieldname: "user_sales_" + i, - label:__("Sales"), default: 1}, + label:__("Sales"), "default": 1, + hidden: frappe.wiz.domain==='Education' ? 1 : 0}, {fieldtype: "Check", fieldname: "user_purchaser_" + i, - label:__("Purchaser"), default: 1}, + label:__("Purchaser"), "default": 1, + hidden: frappe.wiz.domain==='Education' ? 1 : 0}, {fieldtype: "Check", fieldname: "user_accountant_" + i, - label:__("Accountant"), default: 1}, + label:__("Accountant"), "default": 1, + hidden: frappe.wiz.domain==='Education' ? 1 : 0}, ]); } }, @@ -185,7 +211,7 @@ function load_erpnext_slides() { }, taxes: { - app_name: "erpnext", + domains: ['manufacturing', 'services', 'retail', 'distribution'], icon: "icon-money", title: __("Add Taxes"), help: __("List your tax heads (e.g. VAT, Customs etc; they should have unique names) and their standard rates. This will create a standard template, which you can edit and add more later."), @@ -206,7 +232,7 @@ function load_erpnext_slides() { }, customers: { - app_name: "erpnext", + domains: ['manufacturing', 'services', 'retail', 'distribution'], icon: "icon-group", title: __("Your Customers"), help: __("List a few of your customers. They could be organizations or individuals."), @@ -229,7 +255,7 @@ function load_erpnext_slides() { }, suppliers: { - app_name: "erpnext", + domains: ['manufacturing', 'services', 'retail', 'distribution'], icon: "icon-group", title: __("Your Suppliers"), help: __("List a few of your suppliers. They could be organizations or individuals."), @@ -252,7 +278,7 @@ function load_erpnext_slides() { }, items: { - app_name: "erpnext", + domains: ['manufacturing', 'services', 'retail', 'distribution'], icon: "icon-barcode", title: __("Your Products or Services"), help: __("List your products or services that you buy or sell. Make sure to check the Item Group, Unit of Measure and other properties when you start."), @@ -288,6 +314,81 @@ function load_erpnext_slides() { }, css_class: "two-column" }, + + program: { + domains: ["education"], + title: __("Program"), + help: __("Example: Masters in Computer Science"), + fields: [], + before_load: function(slide) { + slide.fields = []; + for(var i=1; i<6; i++) { + slide.fields = slide.fields.concat([ + {fieldtype:"Section Break", show_section_border: true}, + {fieldtype:"Data", fieldname:"program_" + i, label:__("Program") + " " + i, placeholder: __("Program Name")}, + ]) + } + slide.fields[1].reqd = 1; + }, + css_class: "single-column" + }, + + course: { + domains: ["education"], + title: __("Course"), + help: __("Example: Basic Mathematics"), + fields: [], + before_load: function(slide) { + slide.fields = []; + for(var i=1; i<6; i++) { + slide.fields = slide.fields.concat([ + {fieldtype:"Section Break", show_section_border: true}, + {fieldtype:"Data", fieldname:"course_" + i, label:__("Course") + " " + i, placeholder: __("Course Name")}, + ]) + } + slide.fields[1].reqd = 1; + }, + css_class: "single-column" + }, + + + instructor: { + domains: ["education"], + title: __("Instructor"), + help: __("People who teach at your organisation"), + fields: [], + before_load: function(slide) { + slide.fields = []; + for(var i=1; i<6; i++) { + slide.fields = slide.fields.concat([ + {fieldtype:"Section Break", show_section_border: true}, + {fieldtype:"Data", fieldname:"instructor_" + i, label:__("Instructor") + " " + i, placeholder: __("Instructor Name")}, + ]) + } + slide.fields[1].reqd = 1; + }, + css_class: "single-column" + }, + + room: { + domains: ["education"], + title: __("Room"), + help: __("Classrooms/ Laboratories etc where lectures can be scheduled."), + fields: [], + before_load: function(slide) { + slide.fields = []; + for(var i=1; i<4; i++) { + slide.fields = slide.fields.concat([ + {fieldtype:"Section Break", show_section_border: true}, + {fieldtype:"Data", fieldname:"room_" + i, label:__("Room") + " " + i}, + {fieldtype:"Column Break"}, + {fieldtype:"Int", fieldname:"room_capacity_" + i, label:__("Room") + " " + i + " Capacity"}, + ]) + } + slide.fields[1].reqd = 1; + }, + css_class: "two-column" + }, }); // Source: https://en.wikipedia.org/wiki/Fiscal_year @@ -316,6 +417,8 @@ function load_erpnext_slides() { frappe.wiz.on("before_load", function() { load_erpnext_slides(); + + frappe.wiz.add_slide(erpnext.wiz.select_domain); frappe.wiz.add_slide(erpnext.wiz.org); frappe.wiz.add_slide(erpnext.wiz.branding); @@ -327,5 +430,29 @@ frappe.wiz.on("before_load", function() { frappe.wiz.add_slide(erpnext.wiz.customers); frappe.wiz.add_slide(erpnext.wiz.suppliers); frappe.wiz.add_slide(erpnext.wiz.items); - frappe.wiz.welcome_page = "#welcome-to-erpnext"; + frappe.wiz.add_slide(erpnext.wiz.program); + frappe.wiz.add_slide(erpnext.wiz.course); + frappe.wiz.add_slide(erpnext.wiz.instructor); + frappe.wiz.add_slide(erpnext.wiz.room); + + if(frappe.wizard.domain && frappe.wizard.domain !== 'Education') { + frappe.wiz.welcome_page = "#welcome-to-erpnext"; + } }); + +test_values_edu = { + "language":"english", + "domain":"Education", + "country":"India", + "timezone":"Asia/Kolkata", + "currency":"INR", + "first_name":"Tester", + "email":"test@example.com", + "password":"test", + "company_name":"Hogwarts", + "company_abbr":"HS", + "company_tagline":"School for magicians", + "bank_account":"Gringotts Wizarding Bank", + "fy_start_date":"2016-04-01", + "fy_end_date":"2017-03-31" +} diff --git a/erpnext/schools/doctype/announcement/announcement.json b/erpnext/schools/doctype/announcement/announcement.json index c965da516c6..831b71f9730 100644 --- a/erpnext/schools/doctype/announcement/announcement.json +++ b/erpnext/schools/doctype/announcement/announcement.json @@ -9,6 +9,7 @@ "docstatus": 0, "doctype": "DocType", "document_type": "Document", + "editable_grid": 0, "fields": [ { "allow_on_submit": 0, @@ -276,8 +277,8 @@ "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2016-07-18 10:30:50.243271", - "modified_by": "Administrator", + "modified": "2016-07-21 06:30:12.825629", + "modified_by": "r@r.com", "module": "Schools", "name": "Announcement", "name_case": "", @@ -302,26 +303,6 @@ "share": 1, "submit": 1, "write": 1 - }, - { - "amend": 0, - "apply_user_permissions": 0, - "cancel": 0, - "create": 1, - "delete": 0, - "email": 1, - "export": 1, - "if_owner": 0, - "import": 0, - "permlevel": 0, - "print": 1, - "read": 1, - "report": 1, - "role": "Guest", - "set_user_permissions": 0, - "share": 1, - "submit": 0, - "write": 1 } ], "quick_entry": 0, diff --git a/erpnext/schools/doctype/fees/fees.json b/erpnext/schools/doctype/fees/fees.json index 8e3b5601b5f..576d69e1689 100644 --- a/erpnext/schools/doctype/fees/fees.json +++ b/erpnext/schools/doctype/fees/fees.json @@ -478,8 +478,8 @@ "istable": 0, "max_attachments": 0, "menu_index": 0, - "modified": "2016-07-18 10:30:50.243271", - "modified_by": "Administrator", + "modified": "2016-07-21 06:20:10.878913", + "modified_by": "r@r.com", "module": "Schools", "name": "Fees", "name_case": "", @@ -504,46 +504,6 @@ "share": 1, "submit": 1, "write": 1 - }, - { - "amend": 0, - "apply_user_permissions": 0, - "cancel": 1, - "create": 1, - "delete": 1, - "email": 1, - "export": 1, - "if_owner": 0, - "import": 0, - "permlevel": 0, - "print": 1, - "read": 1, - "report": 1, - "role": "Administrator", - "set_user_permissions": 0, - "share": 1, - "submit": 1, - "write": 1 - }, - { - "amend": 0, - "apply_user_permissions": 0, - "cancel": 0, - "create": 0, - "delete": 0, - "email": 0, - "export": 0, - "if_owner": 0, - "import": 0, - "permlevel": 0, - "print": 1, - "read": 1, - "report": 0, - "role": "Guest", - "set_user_permissions": 0, - "share": 0, - "submit": 0, - "write": 0 } ], "quick_entry": 0, diff --git a/erpnext/setup/setup_wizard/domainify.py b/erpnext/setup/setup_wizard/domainify.py index 02be189b820..07b2e19943c 100644 --- a/erpnext/setup/setup_wizard/domainify.py +++ b/erpnext/setup/setup_wizard/domainify.py @@ -4,86 +4,136 @@ from __future__ import unicode_literals import frappe -def get_domains(): +def get_domain(domain): '''Written as a function to prevent data mutation effects''' - return { + data = { 'Manufacturing': { 'desktop_icons': ['Item', 'BOM', 'Customer', 'Supplier', 'Sales Order', 'Production Order', 'Stock Entry', 'Purchase Order', 'Task', 'Buying', 'Selling', 'Accounts', 'HR', 'ToDo'], + 'remove_roles': ['Academics User'], 'properties': [ {'doctype': 'Item', 'fieldname': 'manufacturing', 'property': 'collapsible_depends_on', 'value': 'is_stock_item'}, ], 'set_value': [ ['Stock Settings', None, 'show_barcode_field', 1] - ] + ], + 'remove_sidebar_items': ['/announcement', '/course', '/examination', '/fees'] }, 'Retail': { 'desktop_icons': ['POS', 'Item', 'Customer', 'Sales Invoice', 'Purchase Order', 'Warranty Claim', 'Accounts', 'Buying', 'ToDo'], - 'remove_roles': ['Manufacturing User', 'Manufacturing Manager'], + 'remove_roles': ['Manufacturing User', 'Manufacturing Manager', 'Academics User'], '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] - ] + ], + 'remove_sidebar_items': ['/announcement', '/course', '/examination', '/fees'] }, 'Distribution': { 'desktop_icons': ['Item', 'Customer', 'Supplier', 'Lead', 'Sales Order', 'Sales Invoice', 'CRM', 'Selling', 'Buying', 'Stock', 'Accounts', 'HR', 'ToDo'], - 'remove_roles': ['Manufacturing User', 'Manufacturing Manager'], + 'remove_roles': ['Manufacturing User', 'Manufacturing Manager', 'Academics User'], 'properties': [ {'doctype': 'Item', 'fieldname': 'manufacturing', 'property': 'hidden', 'value': 1}, ], 'set_value': [ ['Stock Settings', None, 'show_barcode_field', 1] - ] + ], + 'remove_sidebar_items': ['/announcement', '/course', '/examination', '/fees'] }, 'Services': { 'desktop_icons': ['Project', 'Timesheet', 'Customer', 'Sales Order', 'Sales Invoice', 'Lead', 'Opportunity', 'Expense Claim', 'Employee', 'HR', 'ToDo'], - 'remove_roles': ['Manufacturing User', 'Manufacturing Manager'], + 'remove_roles': ['Manufacturing User', 'Manufacturing Manager', 'Academics User'], 'properties': [ {'doctype': 'Item', 'fieldname': 'is_stock_item', 'property': 'default', 'value': 0}, ], 'set_value': [ ['Stock Settings', None, 'show_barcode_field', 0] - ] - } + ], + 'remove_sidebar_items': ['/announcement', '/course', '/examination', '/fees'] + }, + 'Education': { + 'desktop_icons': ['Student', 'Program', 'Course', 'Student Group', 'Instructor', + 'Fees', 'ToDo', 'Schools'], + 'allow_roles': ['Academics User', 'Accounts User', 'Accounts Manager'], + 'allow_sidebar_items': ['/announcement', '/course', '/examination', '/fees'] + }, } + if not domain in data: + raise 'Invalid Domain {0}'.format(domain) + return frappe._dict(data[domain]) def setup_domain(domain): - domains = get_domains() - - if not domain in domains: - return + '''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) + frappe.clear_cache() +def setup_desktop_icons(data): + '''set desktop icons form `data.desktop_icons`''' from frappe.desk.doctype.desktop_icon.desktop_icon import set_desktop_icons - data = frappe._dict(domains[domain]) - - if data.remove_roles: - for role in data.remove_roles: - frappe.db.sql('delete from tabUserRole where role=%s', role) - if data.desktop_icons: set_desktop_icons(data.desktop_icons) +def setup_properties(data): if data.properties: for args in data.properties: frappe.make_property_setter(args) +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) + + if data.remove_roles: + for role in data.remove_roles: + remove_role(role) + + if data.allow_roles: + # remove all roles other than allowed roles + data.allow_roles += ['Administrator', 'Guest', 'System Manager'] + 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`''' 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() - frappe.clear_cache() +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]))) + def reset(): from frappe.desk.page.setup_wizard.setup_wizard import add_all_roles_to diff --git a/erpnext/setup/setup_wizard/setup_wizard.py b/erpnext/setup/setup_wizard/setup_wizard.py index 0284ca8195d..3cabde11a55 100644 --- a/erpnext/setup/setup_wizard/setup_wizard.py +++ b/erpnext/setup/setup_wizard/setup_wizard.py @@ -32,6 +32,15 @@ def setup_complete(args=None): create_items(args) create_customers(args) create_suppliers(args) + + if args.domain.lower() == 'education': + create_academic_term() + create_academic_year() + create_program(args) + create_course(args) + create_instructor(args) + create_room(args) + frappe.local.message_log = [] setup_domain(args.get('domain')) @@ -493,3 +502,47 @@ def create_users(args): emp.flags.ignore_mandatory = True emp.insert(ignore_permissions = True) +def create_academic_term(): + at = ["Semester 1", "Semester 2", "Semester 3"] + for d in at: + academic_term = frappe.new_doc("Academic Term") + academic_term.term_name = d + academic_term.save() + +def create_academic_year(): + ac = ["2013-14", "2014-15", "2015-16", "2016-17", "2017-18"] + for d in ac: + academic_year = frappe.new_doc("Academic Year") + academic_year.academic_year_name = d + academic_year.save() + +def create_program(args): + for i in xrange(1,6): + if args.get("program_" + str(i)): + program = frappe.new_doc("Program") + program.program_name = args.get("program_" + str(i)) + program.save() + +def create_course(args): + for i in xrange(1,6): + if args.get("course_" + str(i)): + course = frappe.new_doc("Course") + course.course_name = args.get("course_" + str(i)) + course.save() + +def create_instructor(args): + for i in xrange(1,6): + if args.get("instructor_" + str(i)): + instructor = frappe.new_doc("Instructor") + instructor.instructor_name = args.get("instructor_" + str(i)) + instructor.save() + +def create_room(args): + for i in xrange(1,6): + if args.get("room_" + str(i)): + room = frappe.new_doc("Room") + room.room_name = args.get("room_" + str(i)) + room.seating_capacity = args.get("room_capacity_" + str(i)) + room.save() + +