Merge branch 'develop' of github.com:frappe/erpnext into develop
This commit is contained in:
commit
053a87edf6
@ -86,33 +86,32 @@ class Employee(Document):
|
|||||||
|
|
||||||
def update_user(self):
|
def update_user(self):
|
||||||
# add employee role if missing
|
# add employee role if missing
|
||||||
if not "Employee" in frappe.db.sql_list("""select role from tabUserRole
|
user = frappe.get_doc("User", self.user_id)
|
||||||
where parent=%s""", self.user_id):
|
user.ignore_permissions = True
|
||||||
from frappe.utils.user import add_role
|
|
||||||
add_role(self.user_id, "Employee")
|
|
||||||
|
|
||||||
user_wrapper = frappe.get_doc("User", self.user_id)
|
if "Employee" not in user.get("user_roles"):
|
||||||
|
user.add_roles("Employee")
|
||||||
|
|
||||||
# copy details like Fullname, DOB and Image to User
|
# copy details like Fullname, DOB and Image to User
|
||||||
if self.employee_name:
|
if self.employee_name:
|
||||||
employee_name = self.employee_name.split(" ")
|
employee_name = self.employee_name.split(" ")
|
||||||
if len(employee_name) >= 3:
|
if len(employee_name) >= 3:
|
||||||
user_wrapper.last_name = " ".join(employee_name[2:])
|
user.last_name = " ".join(employee_name[2:])
|
||||||
user_wrapper.middle_name = employee_name[1]
|
user.middle_name = employee_name[1]
|
||||||
elif len(employee_name) == 2:
|
elif len(employee_name) == 2:
|
||||||
user_wrapper.last_name = employee_name[1]
|
user.last_name = employee_name[1]
|
||||||
|
|
||||||
user_wrapper.first_name = employee_name[0]
|
user.first_name = employee_name[0]
|
||||||
|
|
||||||
if self.date_of_birth:
|
if self.date_of_birth:
|
||||||
user_wrapper.birth_date = self.date_of_birth
|
user.birth_date = self.date_of_birth
|
||||||
|
|
||||||
if self.gender:
|
if self.gender:
|
||||||
user_wrapper.gender = self.gender
|
user.gender = self.gender
|
||||||
|
|
||||||
if self.image:
|
if self.image:
|
||||||
if not user_wrapper.user_image == self.image:
|
if not user.user_image:
|
||||||
user_wrapper.user_image = self.image
|
user.user_image = self.image
|
||||||
try:
|
try:
|
||||||
frappe.get_doc({
|
frappe.get_doc({
|
||||||
"doctype": "File Data",
|
"doctype": "File Data",
|
||||||
@ -123,8 +122,8 @@ class Employee(Document):
|
|||||||
except frappe.DuplicateEntryError, e:
|
except frappe.DuplicateEntryError, e:
|
||||||
# already exists
|
# already exists
|
||||||
pass
|
pass
|
||||||
user_wrapper.ignore_permissions = True
|
|
||||||
user_wrapper.save()
|
user.save()
|
||||||
|
|
||||||
def validate_date(self):
|
def validate_date(self):
|
||||||
if self.date_of_birth and self.date_of_joining and getdate(self.date_of_birth) >= getdate(self.date_of_joining):
|
if self.date_of_birth and self.date_of_joining and getdate(self.date_of_birth) >= getdate(self.date_of_joining):
|
||||||
|
@ -4,20 +4,20 @@
|
|||||||
cur_frm.add_fetch('employee','employee_name','employee_name');
|
cur_frm.add_fetch('employee','employee_name','employee_name');
|
||||||
|
|
||||||
cur_frm.cscript.onload = function(doc, dt, dn) {
|
cur_frm.cscript.onload = function(doc, dt, dn) {
|
||||||
if(!doc.posting_date)
|
if(!doc.posting_date)
|
||||||
set_multiple(dt,dn,{posting_date:get_today()});
|
set_multiple(dt,dn,{posting_date:get_today()});
|
||||||
if(doc.__islocal) {
|
if(doc.__islocal) {
|
||||||
cur_frm.set_value("status", "Open");
|
cur_frm.set_value("status", "Open");
|
||||||
cur_frm.cscript.calculate_total_days(doc, dt, dn);
|
cur_frm.cscript.calculate_total_days(doc, dt, dn);
|
||||||
}
|
}
|
||||||
|
|
||||||
var leave_approver = doc.leave_approver;
|
var leave_approver = doc.leave_approver;
|
||||||
return cur_frm.call({
|
return cur_frm.call({
|
||||||
method: "erpnext.hr.utils.get_leave_approver_list",
|
method: "erpnext.hr.utils.get_leave_approver_list",
|
||||||
callback: function(r) {
|
callback: function(r) {
|
||||||
cur_frm.set_df_property("leave_approver", "options", $.map(r.message,
|
cur_frm.set_df_property("leave_approver", "options", $.map(r.message,
|
||||||
function(user) {
|
function(user) {
|
||||||
return {value: user, label: frappe.user_info(user).fullname};
|
return {value: user, label: frappe.user_info(user).fullname};
|
||||||
}));
|
}));
|
||||||
if(leave_approver) cur_frm.set_value("leave_approver", leave_approver);
|
if(leave_approver) cur_frm.set_value("leave_approver", leave_approver);
|
||||||
cur_frm.cscript.get_leave_balance(cur_frm.doc);
|
cur_frm.cscript.get_leave_balance(cur_frm.doc);
|
||||||
@ -54,7 +54,7 @@ cur_frm.cscript.refresh = function(doc, dt, dn) {
|
|||||||
cur_frm.set_intro(__("Leave application has been rejected."));
|
cur_frm.set_intro(__("Leave application has been rejected."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cur_frm.cscript.employee = function (doc, dt, dn){
|
cur_frm.cscript.employee = function (doc, dt, dn){
|
||||||
@ -86,11 +86,11 @@ cur_frm.cscript.from_date = function(doc, dt, dn) {
|
|||||||
cur_frm.cscript.to_date = function(doc, dt, dn) {
|
cur_frm.cscript.to_date = function(doc, dt, dn) {
|
||||||
if(cint(doc.half_day) == 1 && cstr(doc.from_date) && doc.from_date != doc.to_date){
|
if(cint(doc.half_day) == 1 && cstr(doc.from_date) && doc.from_date != doc.to_date){
|
||||||
msgprint(__("To Date should be same as From Date for Half Day leave"));
|
msgprint(__("To Date should be same as From Date for Half Day leave"));
|
||||||
set_multiple(dt,dn,{to_date:doc.from_date});
|
set_multiple(dt,dn,{to_date:doc.from_date});
|
||||||
}
|
}
|
||||||
cur_frm.cscript.calculate_total_days(doc, dt, dn);
|
cur_frm.cscript.calculate_total_days(doc, dt, dn);
|
||||||
}
|
}
|
||||||
|
|
||||||
cur_frm.cscript.get_leave_balance = function(doc, dt, dn) {
|
cur_frm.cscript.get_leave_balance = function(doc, dt, dn) {
|
||||||
if(doc.docstatus==0 && doc.employee && doc.leave_type && doc.fiscal_year) {
|
if(doc.docstatus==0 && doc.employee && doc.leave_type && doc.fiscal_year) {
|
||||||
return cur_frm.call({
|
return cur_frm.call({
|
||||||
@ -114,8 +114,4 @@ cur_frm.cscript.calculate_total_days = function(doc, dt, dn) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cur_frm.fields_dict.employee.get_query = function() {
|
cur_frm.fields_dict.employee.get_query = erpnext.queries.employee;
|
||||||
return {
|
|
||||||
query: "erpnext.hr.doctype.leave_application.leave_application.query_for_permitted_employees"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
@ -318,28 +318,3 @@ def add_holidays(events, start, end, employee, company):
|
|||||||
"title": _("Holiday") + ": " + cstr(holiday.description),
|
"title": _("Holiday") + ": " + cstr(holiday.description),
|
||||||
"name": holiday.name
|
"name": holiday.name
|
||||||
})
|
})
|
||||||
|
|
||||||
@frappe.whitelist()
|
|
||||||
def query_for_permitted_employees(doctype, txt, searchfield, start, page_len, filters):
|
|
||||||
txt = "%" + cstr(txt) + "%"
|
|
||||||
|
|
||||||
if "Leave Approver" in frappe.user.get_roles():
|
|
||||||
user = frappe.session.user.replace('"', '\"')
|
|
||||||
condition = """and (exists(select ela.name from `tabEmployee Leave Approver` ela
|
|
||||||
where ela.parent=`tabEmployee`.name and ela.leave_approver= "%s") or
|
|
||||||
not exists(select ela.name from `tabEmployee Leave Approver` ela
|
|
||||||
where ela.parent=`tabEmployee`.name)
|
|
||||||
or user_id = "%s")""" % (user, user)
|
|
||||||
else:
|
|
||||||
from frappe.widgets.reportview import build_match_conditions
|
|
||||||
condition = build_match_conditions("Employee")
|
|
||||||
condition = ("and " + condition) if condition else ""
|
|
||||||
|
|
||||||
return frappe.db.sql("""select name, employee_name from `tabEmployee`
|
|
||||||
where status = 'Active' and docstatus < 2 and
|
|
||||||
(`%s` like %s or employee_name like %s) %s
|
|
||||||
order by
|
|
||||||
case when name like %s then 0 else 1 end,
|
|
||||||
case when employee_name like %s then 0 else 1 end,
|
|
||||||
name limit %s, %s""" % tuple([searchfield] + ["%s"]*2 + [condition] + ["%s"]*4),
|
|
||||||
(txt, txt, txt, txt, start, page_len))
|
|
||||||
|
@ -40,7 +40,7 @@ class LeaveControlPanel(Document):
|
|||||||
|
|
||||||
for d in self.get_employees():
|
for d in self.get_employees():
|
||||||
try:
|
try:
|
||||||
la = frappe.get_doc('Leave Allocation')
|
la = frappe.new_doc('Leave Allocation')
|
||||||
la.set("__islocal", 1)
|
la.set("__islocal", 1)
|
||||||
la.employee = cstr(d[0])
|
la.employee = cstr(d[0])
|
||||||
la.employee_name = frappe.db.get_value('Employee',cstr(d[0]),'employee_name')
|
la.employee_name = frappe.db.get_value('Employee',cstr(d[0]),'employee_name')
|
||||||
|
@ -64,4 +64,8 @@ $.extend(erpnext.queries, {
|
|||||||
not_a_group_filter: function() {
|
not_a_group_filter: function() {
|
||||||
return { filters: { is_group: "No" } };
|
return { filters: { is_group: "No" } };
|
||||||
},
|
},
|
||||||
|
|
||||||
|
employee: function() {
|
||||||
|
return { query: "erpnext.controllers.queries.employee_query" }
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user