Merge branch 'master' into edge
This commit is contained in:
commit
8da053a7f3
@ -1,4 +1,9 @@
|
|||||||
erpnext.updates = [
|
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", [
|
["6th February, 2013", [
|
||||||
"Bookmarks: Add bookmarks via toolbar by clicking on the <i class='icon-star'></i> sign.",
|
"Bookmarks: Add bookmarks via toolbar by clicking on the <i class='icon-star'></i> sign.",
|
||||||
]],
|
]],
|
||||||
|
@ -63,18 +63,55 @@ class DocType:
|
|||||||
return ret_sal_struct and ret_sal_struct[0][0] or ''
|
return ret_sal_struct and ret_sal_struct[0][0] or ''
|
||||||
|
|
||||||
def on_update(self):
|
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):
|
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", 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("employee_name", self.doc.employee_name, self.doc.user_id)
|
webnotes.conn.set_default("company", self.doc.company, self.doc.user_id)
|
||||||
webnotes.conn.set_default("company", self.doc.company, self.doc.user_id)
|
|
||||||
|
|
||||||
# add employee role if missing
|
def update_profile(self):
|
||||||
if not "Employee" in webnotes.conn.sql_list("""select role from tabUserRole
|
# add employee role if missing
|
||||||
|
if not "Employee" in webnotes.conn.sql_list("""select role from tabUserRole
|
||||||
where parent=%s""", self.doc.user_id):
|
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):
|
def validate_date(self):
|
||||||
import datetime
|
import datetime
|
||||||
|
@ -7,7 +7,7 @@ test_records = [[{
|
|||||||
"gender": "Female",
|
"gender": "Female",
|
||||||
"status": "Active",
|
"status": "Active",
|
||||||
"company": "_Test Company",
|
"company": "_Test Company",
|
||||||
"user_id": "test@erpnext.com"
|
"user_id": "test@example.com"
|
||||||
}],
|
}],
|
||||||
[{
|
[{
|
||||||
"doctype":"Employee",
|
"doctype":"Employee",
|
||||||
@ -18,5 +18,17 @@ test_records = [[{
|
|||||||
"gender": "Male",
|
"gender": "Male",
|
||||||
"status": "Active",
|
"status": "Active",
|
||||||
"company": "_Test Company",
|
"company": "_Test Company",
|
||||||
"user_id": "test1@erpnext.com"
|
"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"
|
||||||
|
}]
|
||||||
|
]
|
@ -15,6 +15,6 @@ test_records = [[{
|
|||||||
"parent": "_Test Holiday Block List",
|
"parent": "_Test Holiday Block List",
|
||||||
"parenttype": "Holiday Block List",
|
"parenttype": "Holiday Block List",
|
||||||
"parentfield": "holiday_block_list_allowed",
|
"parentfield": "holiday_block_list_allowed",
|
||||||
"allow_user": "test1@erpnext.com",
|
"allow_user": "test1@example.com",
|
||||||
}
|
}
|
||||||
]]
|
]]
|
@ -23,10 +23,14 @@ cur_frm.cscript.onload = function(doc, dt, dn) {
|
|||||||
if(doc.__islocal) {
|
if(doc.__islocal) {
|
||||||
cur_frm.set_value("status", "Open")
|
cur_frm.set_value("status", "Open")
|
||||||
}
|
}
|
||||||
|
cur_frm.set_df_property("leave_approver", "options", "");
|
||||||
cur_frm.call({
|
cur_frm.call({
|
||||||
method:"get_approver_list",
|
method:"get_approver_list",
|
||||||
callback: function(r) {
|
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);
|
cur_frm.cscript.get_leave_balance(cur_frm.doc);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -78,7 +78,9 @@ class DocType:
|
|||||||
if block_date > from_date and block_date < to_date:
|
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")
|
webnotes.msgprint(_("You cannot apply for a leave on the following date because it is blocked")
|
||||||
+ ": " + formatdate(d.block_date) + _(" Reason: ") + d.reason)
|
+ ": " + 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):
|
def is_user_in_allow_list(self, block_list):
|
||||||
return webnotes.session.user in webnotes.conn.sql_list("""select allow_user
|
return webnotes.session.user in webnotes.conn.sql_list("""select allow_user
|
||||||
|
@ -4,8 +4,8 @@ import unittest
|
|||||||
from hr.doctype.leave_application.leave_application import LeaveDayBlockedError
|
from hr.doctype.leave_application.leave_application import LeaveDayBlockedError
|
||||||
|
|
||||||
class TestLeaveApplication(unittest.TestCase):
|
class TestLeaveApplication(unittest.TestCase):
|
||||||
def get_application(self):
|
def get_application(self, doclist):
|
||||||
application = webnotes.model_wrapper(test_records[1])
|
application = webnotes.model_wrapper(doclist)
|
||||||
application.doc.from_date = "2013-01-01"
|
application.doc.from_date = "2013-01-01"
|
||||||
application.doc.to_date = "2013-01-05"
|
application.doc.to_date = "2013-01-05"
|
||||||
return application
|
return application
|
||||||
@ -15,22 +15,37 @@ class TestLeaveApplication(unittest.TestCase):
|
|||||||
webnotes.conn.set_value("Employee", "_T-Employee-0001", "department",
|
webnotes.conn.set_value("Employee", "_T-Employee-0001", "department",
|
||||||
"_Test Department with Block List")
|
"_Test Department with Block List")
|
||||||
|
|
||||||
application = self.get_application()
|
application = self.get_application(test_records[1])
|
||||||
self.assertRaises(LeaveDayBlockedError, application.insert)
|
application.insert()
|
||||||
|
self.assertRaises(LeaveDayBlockedError, application.submit)
|
||||||
|
|
||||||
webnotes.session.user = "test1@erpnext.com"
|
webnotes.session.user = "test1@example.com"
|
||||||
webnotes.get_obj("Profile", "test1@erpnext.com").add_role("HR User")
|
|
||||||
|
from webnotes.profile import add_role
|
||||||
|
add_role("test1@example.com", "HR User")
|
||||||
|
|
||||||
|
application = self.get_application(test_records[1])
|
||||||
self.assertTrue(application.insert())
|
self.assertTrue(application.insert())
|
||||||
|
|
||||||
def test_global_block_list(self):
|
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",
|
webnotes.conn.set_value("Holiday Block List", "_Test Holiday Block List",
|
||||||
"applies_to_all_departments", 1)
|
"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")
|
"_Test Department")
|
||||||
webnotes.session.user = "test@erpnext.com"
|
|
||||||
|
|
||||||
self.assertRaises(LeaveDayBlockedError, application.insert)
|
webnotes.session.user = "test2@example.com"
|
||||||
|
from webnotes.profile import add_role
|
||||||
|
add_role("test2@example.com", "Employee")
|
||||||
|
|
||||||
|
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 = [
|
test_records = [
|
||||||
[{
|
[{
|
||||||
@ -50,4 +65,23 @@ test_records = [
|
|||||||
"fiscal_year": "_Test Fiscal Year 2013",
|
"fiscal_year": "_Test Fiscal Year 2013",
|
||||||
"employee": "_T-Employee-0001",
|
"employee": "_T-Employee-0001",
|
||||||
"company": "_Test Company"
|
"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"
|
||||||
|
}]
|
||||||
|
]
|
||||||
|
@ -168,4 +168,5 @@ patch_list = [
|
|||||||
"patches.february_2013.remove_account_utils_folder",
|
"patches.february_2013.remove_account_utils_folder",
|
||||||
"patches.february_2013.update_company_in_leave_application",
|
"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_ddl('alter table tabSeries change `name` `name` varchar(100)')",
|
||||||
|
"execute:webnotes.conn.sql('update tabUserRole set parentfield=\"user_roles\" where parentfield=\"userroles\"')",
|
||||||
]
|
]
|
Loading…
x
Reference in New Issue
Block a user