From 94fcb0e9f9c640e14046eaa7e35dc7c9d18afffd Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Mon, 15 Oct 2018 14:57:46 +0530 Subject: [PATCH] [Enhance] Add user image in the employee from the user (#15680) --- erpnext/hr/doctype/employee/employee.py | 15 +++++++++++---- erpnext/patches.txt | 3 ++- .../v10_0/update_user_image_in_employee.py | 19 +++++++++++++++++++ 3 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 erpnext/patches/v10_0/update_user_image_in_employee.py diff --git a/erpnext/hr/doctype/employee/employee.py b/erpnext/hr/doctype/employee/employee.py index 25d3ec4bc9..81671c21dc 100755 --- a/erpnext/hr/doctype/employee/employee.py +++ b/erpnext/hr/doctype/employee/employee.py @@ -45,14 +45,21 @@ class Employee(NestedSet): self.validate_prefered_email() if self.user_id: - self.validate_for_enabled_user_id() - self.validate_duplicate_user_id() + self.validate_user_details() else: existing_user_id = frappe.db.get_value("Employee", self.name, "user_id") if existing_user_id: frappe.permissions.remove_user_permission( "Employee", self.name, existing_user_id) + def validate_user_details(self): + data = frappe.db.get_value('User', + self.user_id, ['enabled', 'user_image'], as_dict=1) + + self.image = data.get("user_image") + self.validate_for_enabled_user_id(data.get("enabled", 0)) + self.validate_duplicate_user_id() + def update_nsm_model(self): frappe.utils.nestedset.update_nsm(self) @@ -133,10 +140,10 @@ class Employee(NestedSet): if self.status == 'Left' and not self.relieving_date: throw(_("Please enter relieving date.")) - def validate_for_enabled_user_id(self): + def validate_for_enabled_user_id(self, enabled): if not self.status == 'Active': return - enabled = frappe.db.get_value("User", self.user_id, "enabled") + if enabled is None: frappe.throw(_("User {0} does not exist").format(self.user_id)) if enabled == 0: diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 313f3789fd..6c7a252b16 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -505,4 +505,5 @@ erpnext.patches.v10_0.update_status_in_purchase_receipt erpnext.patches.v10_0.update_address_template_for_india erpnext.patches.v10_0.set_discount_amount erpnext.patches.v10_0.recalculate_gross_margin_for_project -erpnext.patches.v10_0.delete_hub_documents \ No newline at end of file +erpnext.patches.v10_0.delete_hub_documents +erpnext.patches.v10_0.update_user_image_in_employee \ No newline at end of file diff --git a/erpnext/patches/v10_0/update_user_image_in_employee.py b/erpnext/patches/v10_0/update_user_image_in_employee.py new file mode 100644 index 0000000000..72d5d2a857 --- /dev/null +++ b/erpnext/patches/v10_0/update_user_image_in_employee.py @@ -0,0 +1,19 @@ +# Copyright (c) 2017, Frappe and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import frappe + +def execute(): + frappe.reload_doc('hr', 'doctype', 'employee') + + frappe.db.sql(""" + UPDATE + `tabEmployee`, `tabUser` + SET + `tabEmployee`.image = `tabUser`.user_image + WHERE + `tabEmployee`.user_id = `tabUser`.name and + `tabEmployee`.user_id is not null and + `tabEmployee`.user_id != '' and `tabEmployee`.image is null + """)