From 0d6db6c42c3e1c1acb445ba0fb4b95115a15c82b Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Fri, 31 Mar 2017 23:01:45 +0530 Subject: [PATCH 1/2] [fix] add user default role --- erpnext/hooks.py | 4 ++-- erpnext/portal/utils.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 erpnext/portal/utils.py diff --git a/erpnext/hooks.py b/erpnext/hooks.py index f4b87d2689..5b4e687b3b 100644 --- a/erpnext/hooks.py +++ b/erpnext/hooks.py @@ -148,8 +148,8 @@ doc_events = { "User": { "after_insert": "frappe.email.doctype.contact.contact.update_contact", "validate": "erpnext.hr.doctype.employee.employee.validate_employee_role", - "on_update": "erpnext.hr.doctype.employee.employee.update_user_permissions", - "on_update": "frappe.geo.address_and_contact.set_default_role" + "on_update": ["erpnext.hr.doctype.employee.employee.update_user_permissions", + "erpnext.portal.utils.set_default_role"] }, ("Sales Taxes and Charges Template", 'Price List'): { "on_update": "erpnext.shopping_cart.doctype.shopping_cart_settings.shopping_cart_settings.validate_cart_settings" diff --git a/erpnext/portal/utils.py b/erpnext/portal/utils.py new file mode 100644 index 0000000000..7dffd03341 --- /dev/null +++ b/erpnext/portal/utils.py @@ -0,0 +1,17 @@ +import frappe + +def set_default_role(doc, method): + '''Set customer, supplier, student based on email''' + if frappe.flags.setting_role or frappe.flags.in_migrate: + return + contact_name = frappe.get_value('Contact', dict(email_id=doc.email)) + if contact_name: + contact = frappe.get_doc('Contact', contact_name) + for link in contact.links: + frappe.flags.setting_role = True + if link.link_doctype=='Customer': + doc.add_roles('Customer') + elif link.link_doctype=='Supplier': + doc.add_roles('Supplier') + elif frappe.get_value('Student', dict(student_email_id=doc.email)): + doc.add_roles('Student') From 31334328ed4ed55b7fa77cc1a655a65229f3e7f3 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Sat, 1 Apr 2017 19:32:55 +0600 Subject: [PATCH 2/2] bumped to version 8.0.5 --- erpnext/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/__init__.py b/erpnext/__init__.py index 69024178a8..dc2a0fa278 100644 --- a/erpnext/__init__.py +++ b/erpnext/__init__.py @@ -2,7 +2,7 @@ from __future__ import unicode_literals import frappe -__version__ = '8.0.4' +__version__ = '8.0.5' def get_default_company(user=None): '''Get default company for user'''