2015-03-03 09:25:30 +00:00
|
|
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
2013-08-05 09:29:54 +00:00
|
|
|
# License: GNU General Public License v3. See license.txt
|
2013-04-12 14:49:53 +00:00
|
|
|
|
|
|
|
from __future__ import unicode_literals
|
2014-02-14 10:17:51 +00:00
|
|
|
import frappe
|
|
|
|
from frappe import _
|
2018-05-05 07:57:26 +00:00
|
|
|
from frappe.utils import formatdate, format_datetime
|
|
|
|
from frappe.utils import getdate, get_datetime
|
2013-04-12 14:49:53 +00:00
|
|
|
|
2014-05-30 09:13:36 +00:00
|
|
|
def set_employee_name(doc):
|
|
|
|
if doc.employee and not doc.employee_name:
|
|
|
|
doc.employee_name = frappe.db.get_value("Employee", doc.employee, "employee_name")
|
2018-05-05 07:57:26 +00:00
|
|
|
|
|
|
|
@frappe.whitelist()
|
|
|
|
def get_employee_fields_label():
|
|
|
|
fields = []
|
|
|
|
for df in frappe.get_meta("Employee").get("fields"):
|
|
|
|
if df.fieldtype in ["Data", "Date", "Datetime", "Float", "Int",
|
|
|
|
"Link", "Percent", "Select", "Small Text"] and df.fieldname not in ["lft", "rgt", "old_parent"]:
|
|
|
|
fields.append({"value": df.fieldname, "label": df.label})
|
|
|
|
return fields
|
|
|
|
|
|
|
|
@frappe.whitelist()
|
|
|
|
def get_employee_field_property(employee, fieldname):
|
|
|
|
if employee and fieldname:
|
|
|
|
field = frappe.get_meta("Employee").get_field(fieldname)
|
|
|
|
value = frappe.db.get_value("Employee", employee, fieldname)
|
|
|
|
options = field.options
|
|
|
|
if field.fieldtype == "Date":
|
|
|
|
value = formatdate(value)
|
|
|
|
elif field.fieldtype == "Datetime":
|
|
|
|
value = format_datetime(value)
|
|
|
|
return {
|
|
|
|
"value" : value,
|
|
|
|
"datatype" : field.fieldtype,
|
|
|
|
"label" : field.label,
|
|
|
|
"options" : options
|
|
|
|
}
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
|
|
|
def update_employee(employee, details, cancel=False):
|
|
|
|
for item in details:
|
|
|
|
fieldtype = frappe.get_meta("Employee").get_field(item.fieldname).fieldtype
|
|
|
|
new_data = item.new if not cancel else item.current
|
|
|
|
if fieldtype == "Date" and new_data:
|
|
|
|
new_data = getdate(new_data)
|
|
|
|
elif fieldtype =="Datetime" and new_data:
|
|
|
|
new_data = get_datetime(new_data)
|
|
|
|
setattr(employee, item.fieldname, new_data)
|
|
|
|
return employee
|