Leave allocation fix
This commit is contained in:
parent
73083dc960
commit
102842ba79
@ -7,7 +7,7 @@ import frappe
|
|||||||
from frappe.utils import cint, cstr, flt, nowdate
|
from frappe.utils import cint, cstr, flt, nowdate
|
||||||
from frappe.model.doc import Document
|
from frappe.model.doc import Document
|
||||||
from frappe.model.code import get_obj
|
from frappe.model.code import get_obj
|
||||||
from frappe import msgprint
|
from frappe import msgprint, _
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -17,8 +17,7 @@ class DocType:
|
|||||||
self.doc = doc
|
self.doc = doc
|
||||||
self.doclist = doclist
|
self.doclist = doclist
|
||||||
|
|
||||||
# Get Employees
|
|
||||||
# **********************************************************************
|
|
||||||
def get_employees(self):
|
def get_employees(self):
|
||||||
lst1 = [[self.doc.employee_type,"employment_type"],[self.doc.branch,"branch"],[self.doc.designation,"designation"],[self.doc.department, "department"],[self.doc.grade,"grade"]]
|
lst1 = [[self.doc.employee_type,"employment_type"],[self.doc.branch,"branch"],[self.doc.designation,"designation"],[self.doc.department, "department"],[self.doc.grade,"grade"]]
|
||||||
condition = "where "
|
condition = "where "
|
||||||
@ -36,22 +35,21 @@ class DocType:
|
|||||||
e = frappe.db.sql(emp_query)
|
e = frappe.db.sql(emp_query)
|
||||||
return e
|
return e
|
||||||
|
|
||||||
# ----------------
|
|
||||||
# validate values
|
|
||||||
# ----------------
|
|
||||||
def validate_values(self):
|
def validate_values(self):
|
||||||
val_dict = {self.doc.fiscal_year:'Fiscal Year', self.doc.leave_type:'Leave Type', self.doc.no_of_days:'New Leaves Allocated'}
|
meta = frappe.get_doctype(self.doc.doctype)
|
||||||
for d in val_dict:
|
for f in ["fiscal_year", "leave_type", "no_of_days"]:
|
||||||
if not d:
|
if not self.doc.fields[f]:
|
||||||
msgprint("Please enter : "+val_dict[d])
|
frappe.throw(_(meta.get_label(f)) + _(" is mandatory"))
|
||||||
raise Exception
|
|
||||||
|
|
||||||
|
|
||||||
# Allocation
|
|
||||||
# **********************************************************************
|
|
||||||
def allocate_leave(self):
|
def allocate_leave(self):
|
||||||
self.validate_values()
|
self.validate_values()
|
||||||
|
leave_allocated_for = []
|
||||||
|
employees = self.get_employees()
|
||||||
|
if not employees:
|
||||||
|
frappe.throw(_("No employee found"))
|
||||||
|
|
||||||
for d in self.get_employees():
|
for d in self.get_employees():
|
||||||
|
try:
|
||||||
la = Document('Leave Allocation')
|
la = Document('Leave Allocation')
|
||||||
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')
|
||||||
@ -65,4 +63,8 @@ class DocType:
|
|||||||
la_obj.validate()
|
la_obj.validate()
|
||||||
la_obj.on_update()
|
la_obj.on_update()
|
||||||
la_obj.doc.save(1)
|
la_obj.doc.save(1)
|
||||||
msgprint("Leaves Allocated Successfully")
|
leave_allocated_for.append(d[0])
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
if leave_allocated_for:
|
||||||
|
msgprint("Leaves Allocated Successfully for " + ", ".join(leave_allocated_for))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user