diff --git a/home/page/latest_updates/latest_updates.js b/home/page/latest_updates/latest_updates.js index 7e28824229..dea571d177 100644 --- a/home/page/latest_updates/latest_updates.js +++ b/home/page/latest_updates/latest_updates.js @@ -1,4 +1,9 @@ erpnext.updates = [ + ["13th February, 2013", [ + "Employee: If Employee is linked to a Profile, copy Full Name, Date of Birth, \ + Image and Gender to Profile", + "Leave Application: Select Leave Approver by their Full Name", + ]], ["6th February, 2013", [ "Bookmarks: Add bookmarks via toolbar by clicking on the sign.", ]], diff --git a/hr/doctype/employee/employee.py b/hr/doctype/employee/employee.py index 6846c5efba..cef6fdc697 100644 --- a/hr/doctype/employee/employee.py +++ b/hr/doctype/employee/employee.py @@ -63,19 +63,56 @@ class DocType: return ret_sal_struct and ret_sal_struct[0][0] or '' def on_update(self): - self.update_user_default() + if self.doc.user_id: + self.update_user_default() + self.update_profile() def update_user_default(self): - if self.doc.user_id: - webnotes.conn.set_default("employee", self.doc.name, self.doc.user_id) - webnotes.conn.set_default("employee_name", self.doc.employee_name, self.doc.user_id) - webnotes.conn.set_default("company", self.doc.company, self.doc.user_id) - - # add employee role if missing - if not "Employee" in webnotes.conn.sql_list("""select role from tabUserRole + webnotes.conn.set_default("employee", self.doc.name, self.doc.user_id) + webnotes.conn.set_default("employee_name", self.doc.employee_name, self.doc.user_id) + webnotes.conn.set_default("company", self.doc.company, self.doc.user_id) + + def update_profile(self): + # add employee role if missing + if not "Employee" in webnotes.conn.sql_list("""select role from tabUserRole where parent=%s""", self.doc.user_id): - webnotes.get_obj("Profile", self.doc.user_id).add_role("Employee") - + from webnotes.profile import add_role + add_role(self.doc.user_id, "HR User") + + profile_wrapper = webnotes.model_wrapper("Profile", self.doc.user_id) + + # copy details like Fullname, DOB and Image to Profile + if self.doc.employee_name: + employee_name = self.doc.employee_name.split(" ") + if len(employee_name) >= 3: + profile_wrapper.doc.last_name = " ".join(employee_name[2:]) + profile_wrapper.doc.middle_name = employee_name[1] + elif len(employee_name) == 2: + profile_wrapper.doc.last_name = employee_name[1] + + profile_wrapper.doc.first_name = employee_name[0] + + if self.doc.date_of_birth: + profile_wrapper.doc.birth_date = self.doc.date_of_birth + + if self.doc.gender: + profile_wrapper.doc.gender = self.doc.gender + + if self.doc.image and self.doc.file_list: + # add to file list and user_image + for file_args in self.doc.file_list.split("\n"): + fname, fid = file_args.split(",") + if self.doc.image == fname: + new_file_args = fname + "," + fid + file_list = profile_wrapper.doc.file_list.split("\n") + if new_file_args not in file_list: + file_list += [new_file_args] + profile_wrapper.doc.file_list = "\n".join(file_list) + profile_wrapper.doc.user_image = fname + break + + profile_wrapper.save() + def validate_date(self): import datetime if self.doc.date_of_birth and self.doc.date_of_joining and getdate(self.doc.date_of_birth) >= getdate(self.doc.date_of_joining): diff --git a/hr/doctype/employee/test_employee.py b/hr/doctype/employee/test_employee.py index a9c715b9d8..01c2087ec0 100644 --- a/hr/doctype/employee/test_employee.py +++ b/hr/doctype/employee/test_employee.py @@ -7,7 +7,7 @@ test_records = [[{ "gender": "Female", "status": "Active", "company": "_Test Company", - "user_id": "test@erpnext.com" + "user_id": "test@example.com" }], [{ "doctype":"Employee", @@ -18,5 +18,17 @@ test_records = [[{ "gender": "Male", "status": "Active", "company": "_Test Company", - "user_id": "test1@erpnext.com" -}]] \ No newline at end of file + "user_id": "test1@example.com" +}], +[{ + "doctype":"Employee", + "employee_name": "_Test Employee 2", + "naming_series": "_T-Employee-", + "date_of_joining": "2010-01-01", + "date_of_birth": "1980-01-01", + "gender": "Male", + "status": "Active", + "company": "_Test Company", + "user_id": "test2@example.com" +}] +] \ No newline at end of file diff --git a/hr/doctype/holiday_block_list/test_holiday_block_list.py b/hr/doctype/holiday_block_list/test_holiday_block_list.py index 5ec4dd1af5..e9f3b78472 100644 --- a/hr/doctype/holiday_block_list/test_holiday_block_list.py +++ b/hr/doctype/holiday_block_list/test_holiday_block_list.py @@ -15,6 +15,6 @@ test_records = [[{ "parent": "_Test Holiday Block List", "parenttype": "Holiday Block List", "parentfield": "holiday_block_list_allowed", - "allow_user": "test1@erpnext.com", + "allow_user": "test1@example.com", } ]] \ No newline at end of file diff --git a/hr/doctype/leave_application/leave_application.js b/hr/doctype/leave_application/leave_application.js index 3c26a51d25..9df348a17e 100755 --- a/hr/doctype/leave_application/leave_application.js +++ b/hr/doctype/leave_application/leave_application.js @@ -23,10 +23,14 @@ cur_frm.cscript.onload = function(doc, dt, dn) { if(doc.__islocal) { cur_frm.set_value("status", "Open") } + cur_frm.set_df_property("leave_approver", "options", ""); cur_frm.call({ method:"get_approver_list", callback: function(r) { - cur_frm.set_df_property("leave_approver", "options", r.message); + cur_frm.set_df_property("leave_approver", "options", $.map(r.message, + function(profile) { + return {value: profile, label: wn.user_info(profile).fullname}; + })); cur_frm.cscript.get_leave_balance(cur_frm.doc); } }); diff --git a/hr/doctype/leave_application/leave_application.py b/hr/doctype/leave_application/leave_application.py index 204514789e..bc685dfd55 100755 --- a/hr/doctype/leave_application/leave_application.py +++ b/hr/doctype/leave_application/leave_application.py @@ -78,7 +78,9 @@ class DocType: if block_date > from_date and block_date < to_date: webnotes.msgprint(_("You cannot apply for a leave on the following date because it is blocked") + ": " + formatdate(d.block_date) + _(" Reason: ") + d.reason) - raise LeaveDayBlockedError + if self.doc.docstatus == 1: + # throw exception only when submitting + raise LeaveDayBlockedError def is_user_in_allow_list(self, block_list): return webnotes.session.user in webnotes.conn.sql_list("""select allow_user diff --git a/hr/doctype/leave_application/test_leave_application.py b/hr/doctype/leave_application/test_leave_application.py index 7195826bf9..cd74d01399 100644 --- a/hr/doctype/leave_application/test_leave_application.py +++ b/hr/doctype/leave_application/test_leave_application.py @@ -4,8 +4,8 @@ import unittest from hr.doctype.leave_application.leave_application import LeaveDayBlockedError class TestLeaveApplication(unittest.TestCase): - def get_application(self): - application = webnotes.model_wrapper(test_records[1]) + def get_application(self, doclist): + application = webnotes.model_wrapper(doclist) application.doc.from_date = "2013-01-01" application.doc.to_date = "2013-01-05" return application @@ -15,22 +15,37 @@ class TestLeaveApplication(unittest.TestCase): webnotes.conn.set_value("Employee", "_T-Employee-0001", "department", "_Test Department with Block List") - application = self.get_application() - self.assertRaises(LeaveDayBlockedError, application.insert) + application = self.get_application(test_records[1]) + application.insert() + self.assertRaises(LeaveDayBlockedError, application.submit) - webnotes.session.user = "test1@erpnext.com" - webnotes.get_obj("Profile", "test1@erpnext.com").add_role("HR User") + webnotes.session.user = "test1@example.com" + + from webnotes.profile import add_role + add_role("test1@example.com", "HR User") + + application = self.get_application(test_records[1]) self.assertTrue(application.insert()) def test_global_block_list(self): - application = self.get_application() + application = self.get_application(test_records[3]) + application.doc.leave_approver = "test@example.com" webnotes.conn.set_value("Holiday Block List", "_Test Holiday Block List", "applies_to_all_departments", 1) - webnotes.conn.set_value("Employee", "_T-Employee-0001", "department", + webnotes.conn.set_value("Employee", "_T-Employee-0002", "department", "_Test Department") - webnotes.session.user = "test@erpnext.com" + + webnotes.session.user = "test2@example.com" + from webnotes.profile import add_role + add_role("test2@example.com", "Employee") - self.assertRaises(LeaveDayBlockedError, application.insert) + application.insert() + + webnotes.session.user = "test@example.com" + from webnotes.profile import add_role + add_role("test@example.com", "Leave Approver") + + self.assertRaises(LeaveDayBlockedError, application.submit) test_records = [ [{ @@ -50,4 +65,23 @@ test_records = [ "fiscal_year": "_Test Fiscal Year 2013", "employee": "_T-Employee-0001", "company": "_Test Company" - }]] + }], + [{ + "doctype": "Leave Allocation", + "leave_type": "_Test Leave Type", + "fiscal_year": "_Test Fiscal Year 2013", + "employee":"_T-Employee-0002", + "new_leaves_allocated": 15, + "docstatus": 1 + }], + [{ + "doctype": "Leave Application", + "leave_type": "_Test Leave Type", + "from_date": "2013-05-01", + "to_date": "2013-05-05", + "posting_date": "2013-01-02", + "fiscal_year": "_Test Fiscal Year 2013", + "employee": "_T-Employee-0002", + "company": "_Test Company" + }] +] diff --git a/patches/patch_list.py b/patches/patch_list.py index 97bdc52e79..c00744ea36 100644 --- a/patches/patch_list.py +++ b/patches/patch_list.py @@ -168,4 +168,5 @@ patch_list = [ "patches.february_2013.remove_account_utils_folder", "patches.february_2013.update_company_in_leave_application", "execute:webnotes.conn.sql_ddl('alter table tabSeries change `name` `name` varchar(100)')", + "execute:webnotes.conn.sql('update tabUserRole set parentfield=\"user_roles\" where parentfield=\"userroles\"')", ] \ No newline at end of file