Merge pull request #7279 from KanchanChauhan/automate-user-creation

Create User button in Employee if no User ID selected
This commit is contained in:
Nabin Hait 2016-12-23 15:31:55 +05:30 committed by GitHub
commit 06c6628481
3 changed files with 84 additions and 4 deletions

View File

@ -48,8 +48,8 @@ erpnext.hr.EmployeeController = frappe.ui.form.Controller.extend({
});
frappe.ui.form.on('Employee',{
prefered_contact_email:function(frm){
frm.events.update_contact(frm)
prefered_contact_email:function(frm){
frm.events.update_contact(frm)
},
personal_email:function(frm){
frm.events.update_contact(frm)
@ -74,5 +74,19 @@ frappe.ui.form.on('Employee',{
}
});
},
create_user: function(frm) {
if (!frm.doc.prefered_email)
{
frappe.throw(__("Please enter Preferred Contact Email"))
}
frappe.call({
method: "erpnext.hr.doctype.employee.employee.create_user",
args: { employee: cur_frm.doc.name },
callback: function(r)
{
frm.set_value("user_id", r.message)
}
});
}
});
cur_frm.cscript = new erpnext.hr.EmployeeController({frm: cur_frm});

View File

@ -212,6 +212,35 @@
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"depends_on": "eval:(!doc.user_id)",
"fieldname": "create_user",
"fieldtype": "Button",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Create User",
"length": 0,
"no_copy": 0,
"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_on_submit": 0,
"bold": 0,
@ -2244,7 +2273,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2016-11-07 05:15:16.925799",
"modified": "2016-12-19 17:24:22.941738",
"modified_by": "Administrator",
"module": "HR",
"name": "Employee",

View File

@ -6,7 +6,7 @@ import frappe
from frappe.utils import getdate, validate_email_add, today, add_years
from frappe.model.naming import make_autoname
from frappe import throw, _
from frappe import throw, _, scrub
import frappe.permissions
from frappe.model.document import Document
from erpnext.utilities.transaction_base import delete_events
@ -39,6 +39,7 @@ class Employee(Document):
self.validate_status()
self.validate_employee_leave_approver()
self.validate_reports_to()
self.validate_prefered_email()
if self.user_id:
self.validate_for_enabled_user_id()
@ -153,6 +154,11 @@ class Employee(Document):
def on_trash(self):
delete_events(self.doctype, self.name)
def validate_prefered_email(self):
if not self.get(scrub(self.prefered_contact_email)):
frappe.msgprint(_("Please enter " + self.prefered_contact_email))
def get_timeline_data(doctype, name):
'''Return timeline for attendance'''
return dict(frappe.db.sql('''select unix_timestamp(att_date), count(*)
@ -250,3 +256,34 @@ def deactivate_sales_person(status = None, employee = None):
sales_person = frappe.db.get_value("Sales Person", {"Employee": employee})
if sales_person:
frappe.db.set_value("Sales Person", sales_person, "enabled", 0)
@frappe.whitelist()
def create_user(employee, user = None):
emp = frappe.get_doc("Employee", employee)
employee_name = emp.employee_name.split(" ")
middle_name = last_name = ""
if len(employee_name) >= 3:
last_name = " ".join(employee_name[2:])
middle_name = employee_name[1]
elif len(employee_name) == 2:
last_name = employee_name[1]
first_name = employee_name[0]
user = frappe.new_doc("User")
user.update({
"name": emp.employee_name,
"email": emp.prefered_email,
"enabled": 1,
"first_name": first_name,
"middle_name": middle_name,
"last_name": last_name,
"gender": emp.gender,
"birth_date": emp.date_of_birth,
"phone": emp.cell_number,
"bio": emp.bio
})
user.insert()
return user.name