Set the guardian role automatically. (#12136)
* Add the guardian role for parent portal * invite guardian as user
This commit is contained in:
parent
6401678e63
commit
5807cd8e6f
@ -12,7 +12,7 @@ data = {
|
||||
'Student Attendance Tool',
|
||||
'Student Applicant'
|
||||
],
|
||||
'default_portal_role': 'Student',
|
||||
'default_portal_role': 'Guardian',
|
||||
'restricted_roles': [
|
||||
'Student',
|
||||
'Instructor',
|
||||
|
@ -3,6 +3,18 @@
|
||||
|
||||
frappe.ui.form.on('Guardian', {
|
||||
refresh: function(frm) {
|
||||
|
||||
if(!frm.doc.user && !frm.is_new()) {
|
||||
frm.add_custom_button(__("Invite as User"), function() {
|
||||
return frappe.call({
|
||||
method: "erpnext.education.doctype.guardian.guardian.invite_guardian",
|
||||
args: {
|
||||
guardian: frm.doc.name
|
||||
},
|
||||
callback: function(r) {
|
||||
frm.set_value("user", r.message);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -163,6 +163,37 @@
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "user",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "User Id",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "User",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
@ -476,7 +507,7 @@
|
||||
"issingle": 0,
|
||||
"istable": 0,
|
||||
"max_attachments": 0,
|
||||
"modified": "2017-11-10 19:06:57.122193",
|
||||
"modified": "2017-12-06 18:17:38.090252",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Education",
|
||||
"name": "Guardian",
|
||||
|
@ -4,7 +4,9 @@
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.model.document import Document
|
||||
from frappe.utils.csvutils import getlink
|
||||
|
||||
class Guardian(Document):
|
||||
def __setup__(self):
|
||||
@ -25,4 +27,27 @@ class Guardian(Document):
|
||||
})
|
||||
|
||||
def validate(self):
|
||||
self.students = []
|
||||
self.students = []
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def invite_guardian(guardian):
|
||||
guardian_doc = frappe.get_doc("Guardian", guardian)
|
||||
if not guardian_doc.email_address:
|
||||
frappe.throw(_("Please set Email Address"))
|
||||
else:
|
||||
guardian_as_user = frappe.get_value('User', dict(email=guardian_doc.email_address))
|
||||
print guardian_as_user
|
||||
if guardian_as_user:
|
||||
frappe.msgprint(_("User {0} already exists").format(getlink("User", guardian_as_user)))
|
||||
return guardian_as_user
|
||||
else:
|
||||
user = frappe.get_doc({
|
||||
"doctype": "User",
|
||||
"first_name": guardian_doc.guardian_name,
|
||||
"email": guardian_doc.email_address,
|
||||
"user_type": "Website User",
|
||||
"send_welcome_email": 1
|
||||
}).insert(ignore_permissions = True)
|
||||
frappe.msgprint(_("User {0} created").format(getlink("User", user.name)))
|
||||
return user.name
|
||||
|
@ -483,5 +483,4 @@ erpnext.patches.v10_0.set_primary_contact_for_customer
|
||||
erpnext.patches.v10_0.copy_projects_renamed_fields
|
||||
erpnext.patches.v10_0.enabled_regional_print_format_based_on_country
|
||||
erpnext.patches.v10_0.update_asset_calculate_depreciation
|
||||
erpnext.patches.v10_0.enabled_regional_print_format_based_on_country
|
||||
erpnext.patches.v10_0.update_asset_calculate_depreciation
|
||||
erpnext.patches.v10_0.add_guardian_role_for_parent_portal
|
||||
|
23
erpnext/patches/v10_0/add_guardian_role_for_parent_portal.py
Normal file
23
erpnext/patches/v10_0/add_guardian_role_for_parent_portal.py
Normal file
@ -0,0 +1,23 @@
|
||||
# Copyright (c) 2017, Frappe and Contributors
|
||||
# License: GNU General Public License v3. See license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
|
||||
def execute():
|
||||
# create guardian role
|
||||
if not frappe.get_value('Role', dict(role_name='Guardian')):
|
||||
frappe.get_doc({
|
||||
'doctype': 'Role',
|
||||
'role_name': 'Guardian',
|
||||
'desk_access': 0,
|
||||
'restrict_to_domain': 'Education'
|
||||
}).insert(ignore_permissions=True)
|
||||
|
||||
# set guardian roles in already created users
|
||||
if frappe.db.exists("Doctype", "Guardian"):
|
||||
for user in frappe.db.sql_list("""select u.name from `tabUser` u , `tabGuardian` g where g.email_address = u.name"""):
|
||||
user = frappe.get_doc('User', user)
|
||||
user.flags.ignore_validate = True
|
||||
user.flags.ignore_mandatory = True
|
||||
user.save()
|
@ -1,7 +1,7 @@
|
||||
import frappe
|
||||
|
||||
def set_default_role(doc, method):
|
||||
'''Set customer, supplier, student based on email'''
|
||||
'''Set customer, supplier, student, guardian based on email'''
|
||||
if frappe.flags.setting_role or frappe.flags.in_migrate:
|
||||
return
|
||||
|
||||
@ -18,3 +18,5 @@ def set_default_role(doc, method):
|
||||
doc.add_roles('Supplier')
|
||||
elif frappe.get_value('Student', dict(student_email_id=doc.email)) and 'Student' not in roles:
|
||||
doc.add_roles('Student')
|
||||
elif frappe.get_value('Guardian', dict(email_address=doc.email)) and 'Guardian' not in roles:
|
||||
doc.add_roles('Guardian')
|
||||
|
Loading…
Reference in New Issue
Block a user