Merge branch 'master' into edge

Conflicts:
	home/page/latest_updates/latest_updates.js
	hr/doctype/employee/employee.txt
This commit is contained in:
Anand Doshi
2013-04-16 21:32:06 +05:30
22 changed files with 465 additions and 167 deletions

View File

@@ -14,62 +14,95 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
cur_frm.cscript.onload = function(doc) {
// bc
var india_specific = ["esic_card_no", "gratuity_lic_id", "pan_number", "pf_number"]
if(wn.control_panel.country!="India") {
hide_field(india_specific);
}
}
cur_frm.cscript.refresh = function(doc) {
if(!doc.__islocal) {
hide_field("naming_series");
cur_frm.add_custom_button('Make Salary Structure',
cur_frm.cscript['Make Salary Structure']);
}
}
cur_frm.cscript.date_of_birth = function(doc, dt, dn) {
get_server_fields('get_retirement_date','','',doc,dt,dn,1);
}
cur_frm.cscript.salutation = function(doc,dt,dn) {
if(doc.salutation){
if(doc.salutation=='Mr')
doc.gender='Male';
else if(doc.salutation=='Ms')
doc.gender='Female';
refresh_field('gender');
}
}
cur_frm.cscript['Make Salary Structure']=function(){
$c_obj(make_doclist (cur_frm.doc.doctype, cur_frm.doc.name), 'check_sal_structure',
cur_frm.doc.name, function(r, rt) {
if(r.message)
msgprint("You have already created Active salary structure.\n \
If you want to create new one, please ensure that no active salary structure \
exist.\nTo inactive salary structure select 'Is Active' as 'No'.");
else
cur_frm.cscript.make_salary_structure(cur_frm.doc);
wn.provide("erpnext.hr");
erpnext.hr.EmployeeController = wn.ui.form.Controller.extend({
setup: function() {
this.setup_leave_approver_select();
this.frm.fields_dict.user_id.get_query = erpnext.utils.profile_query;
this.frm.fields_dict.reports_to.get_query = erpnext.utils.employee_query;
},
onload: function() {
this.frm.toggle_display(["esic_card_no", "gratuity_lic_id", "pan_number", "pf_number"],
wn.control_panel.country==="India");
},
refresh: function() {
var me = this;
erpnext.hide_naming_series();
if(!this.frm.doc.__islocal) {
cur_frm.add_custom_button('View Active Salary Structure', function() {
me.view_active_salary_structure(this); });
cur_frm.add_custom_button('Make Salary Structure', function() {
me.make_salary_structure(this); });
}
);
}
cur_frm.cscript.make_salary_structure = function(doc, dt, dn, det){
var st = wn.model.make_new_doc_and_get_name('Salary Structure');
st = locals['Salary Structure'][st];
st.employee = doc.name;
st.employee_name = doc.employee_name;
st.branch=doc.branch;
st.designation=doc.designation;
st.department=doc.department;
st.fiscal_year = doc.fiscal_year
st.grade=doc.grade;
loaddoc('Salary Structure', st.name);
}
cur_frm.fields_dict.user_id.get_query = erpnext.utils.profile_query;
cur_frm.fields_dict.reports_to.get_query = erpnext.utils.employee_query;
},
setup_leave_approver_select: function() {
var me = this;
this.frm.call({
method:"hr.utils.get_leave_approver_list",
callback: function(r) {
me.frm.fields_dict.employee_leave_approvers.grid.get_field("leave_approver").df.options =
$.map(r.message, function(profile) {
return {value: profile, label: wn.user_info(profile).fullname};
});
}
});
},
date_of_birth: function() {
cur_frm.call({
method: "get_retirement_date",
args: {date_of_birth: this.frm.doc.date_of_birth}
});
},
salutation: function() {
if(this.frm.doc.salutation) {
this.frm.set_value("gender", {
"Mr": "Male",
"Ms": "Female"
}[this.frm.doc.salutation]);
}
},
make_salary_structure: function(btn) {
var me = this;
this.validate_salary_structure(btn, function(r) {
if(r.message) {
msgprint(wn._("Employee") + ' "' + me.frm.doc.name + '": '
+ wn._("An active Salary Structure already exists. \
If you want to create new one, please ensure that no active Salary Structure \
exists for this Employee. Go to the active Salary Structure and set \
\"Is Active\" = \"No\""));
} else if(!r.exc) {
wn.model.map({
source: wn.model.get_doclist(me.frm.doc.doctype, me.frm.doc.name),
target: "Salary Structure"
});
}
});
},
validate_salary_structure: function(btn, callback) {
var me = this;
this.frm.call({
btn: btn,
method: "webnotes.client.get_value",
args: {
doctype: "Salary Structure",
fieldname: "name",
filters: {
employee: me.frm.doc.name,
is_active: "Yes",
docstatus: ["!=", 2]
},
},
callback: callback
});
},
});
cur_frm.cscript = new erpnext.hr.EmployeeController({frm: cur_frm});

View File

@@ -27,7 +27,7 @@ class DocType:
def __init__(self,doc,doclist=[]):
self.doc = doc
self.doclist = doclist
def autoname(self):
ret = sql("select value from `tabSingles` where doctype = 'Global Defaults' and field = 'emp_created_by'")
if not ret:
@@ -49,30 +49,31 @@ class DocType:
self.validate_email()
self.validate_name()
self.validate_status()
def get_retirement_date(self):
import datetime
ret = {}
if self.doc.date_of_birth:
dt = getdate(self.doc.date_of_birth) + datetime.timedelta(21915)
ret = {'date_of_retirement': dt.strftime('%Y-%m-%d')}
return ret
def check_sal_structure(self, nm):
ret_sal_struct=sql("select name from `tabSalary Structure` where employee='%s' and is_active = 'Yes' and docstatus!= 2"%nm)
return ret_sal_struct and ret_sal_struct[0][0] or ''
self.validate_employee_leave_approver()
def on_update(self):
if self.doc.user_id:
self.update_user_default()
self.update_profile()
def update_user_default(self):
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)
if self.doc.reports_to:
webnotes.conn.set_default("leave_approver", webnotes.conn.get_value("Employee", self.doc.reports_to, "user_id"), self.doc.user_id)
self.set_default_leave_approver()
def set_default_leave_approver(self):
employee_leave_approvers = self.doclist.get({"parentfield": "employee_leave_approvers"})
if len(employee_leave_approvers):
webnotes.conn.set_default("leave_approver", employee_leave_approvers[0].leave_approver,
self.doc.user_id)
elif self.doc.reports_to:
from webnotes.profile import Profile
reports_to_user = webnotes.conn.get_value("Employee", self.doc.reports_to, "user_id")
if "Leave Approver" in Profile(reports_to_user).get_roles():
webnotes.conn.set_default("leave_approver", reports_to_user, self.doc.user_id)
def update_profile(self):
# add employee role if missing
@@ -118,7 +119,6 @@ class DocType:
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):
msgprint('Date of Joining must be greater than Date of Birth')
raise Exception
@@ -169,3 +169,21 @@ class DocType:
if self.doc.status == 'Left' and not self.doc.relieving_date:
msgprint("Please enter relieving date.")
raise Exception
def validate_employee_leave_approver(self):
from webnotes.profile import Profile
from hr.doctype.leave_application.leave_application import InvalidLeaveApproverError
for l in self.doclist.get({"parentfield": "employee_leave_approvers"}):
if "Leave Approver" not in Profile(l.leave_approver).get_roles():
msgprint(_("Invalid Leave Approver") + ": \"" + l.leave_approver + "\"",
raise_exception=InvalidLeaveApproverError)
@webnotes.whitelist()
def get_retirement_date(date_of_birth=None):
import datetime
ret = {}
if date_of_birth:
dt = getdate(date_of_birth) + datetime.timedelta(21915)
ret = {'date_of_retirement': dt.strftime('%Y-%m-%d')}
return ret

View File

@@ -1,8 +1,8 @@
[
{
"creation": "2013-03-07 14:48:31",
"creation": "2013-03-07 09:04:18",
"docstatus": 0,
"modified": "2013-02-08 13:07:25",
"modified": "2013-04-12 07:16:42",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -320,15 +320,6 @@
"options": "Grade",
"reqd": 0
},
{
"doctype": "DocField",
"fieldname": "reports_to",
"fieldtype": "Link",
"label": "Reports to",
"oldfieldname": "reports_to",
"oldfieldtype": "Link",
"options": "Employee"
},
{
"description": "Provide email id registered in company",
"doctype": "DocField",
@@ -340,6 +331,14 @@
"oldfieldtype": "Data",
"reqd": 0
},
{
"doctype": "DocField",
"fieldname": "notice_number_of_days",
"fieldtype": "Int",
"label": "Notice - Number of Days",
"oldfieldname": "notice_number_of_days",
"oldfieldtype": "Int"
},
{
"doctype": "DocField",
"fieldname": "salary_information",
@@ -403,6 +402,29 @@
"oldfieldname": "gratuity_lic_id",
"oldfieldtype": "Data"
},
{
"doctype": "DocField",
"fieldname": "organization_profile",
"fieldtype": "Section Break",
"label": "Organization Profile"
},
{
"doctype": "DocField",
"fieldname": "reports_to",
"fieldtype": "Link",
"label": "Reports to",
"oldfieldname": "reports_to",
"oldfieldtype": "Link",
"options": "Employee"
},
{
"description": "The first Leave Approver in the list will be set as the default Leave Approver",
"doctype": "DocField",
"fieldname": "employee_leave_approvers",
"fieldtype": "Table",
"label": "Leave Approvers",
"options": "Employee Leave Approver"
},
{
"doctype": "DocField",
"fieldname": "contact_details",
@@ -427,14 +449,6 @@
"fieldtype": "Data",
"label": "Personal Email"
},
{
"doctype": "DocField",
"fieldname": "notice_number_of_days",
"fieldtype": "Int",
"label": "Notice - Number of Days",
"oldfieldname": "notice_number_of_days",
"oldfieldtype": "Int"
},
{
"doctype": "DocField",
"fieldname": "emergency_contact_details",