added status validation

This commit is contained in:
Anand Doshi
2012-12-28 19:42:49 +05:30
parent b72d8204e8
commit f9a3c8fcdc
19 changed files with 410 additions and 355 deletions

View File

@@ -57,6 +57,7 @@ class DocType:
def validate(self):
if not self.doc.status:
self.doc.status = "Draft"
self.validate_dates()
self.validate_existing_appraisal()
self.calculate_total()

View File

@@ -8,11 +8,11 @@
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
import webnotes
@@ -28,79 +28,81 @@ sql = webnotes.conn.sql
class DocType:
def __init__(self, doc, doclist=[]):
self.doc = doc
self.doclist = doclist
#autoname function
def autoname(self):
self.doc.name = make_autoname(self.doc.naming_series+'.#####')
#get employee name based on employee id selected
def get_emp_name(self):
emp_nm = sql("select employee_name from `tabEmployee` where name=%s", self.doc.employee)
def __init__(self, doc, doclist=[]):
self.doc = doc
self.doclist = doclist
#autoname function
def autoname(self):
self.doc.name = make_autoname(self.doc.naming_series+'.#####')
#get employee name based on employee id selected
def get_emp_name(self):
emp_nm = sql("select employee_name from `tabEmployee` where name=%s", self.doc.employee)
#this is done because sometimes user entered wrong employee name while uploading employee attendance
webnotes.conn.set(self.doc, 'employee_name', emp_nm and emp_nm[0][0] or '')
#this is done because sometimes user entered wrong employee name while uploading employee attendance
webnotes.conn.set(self.doc, 'employee_name', emp_nm and emp_nm[0][0] or '')
ret = { 'employee_name' : emp_nm and emp_nm[0][0] or ''}
return ret
#validation for duplicate record
def validate_duplicate_record(self):
res = sql("select name from `tabAttendance` where employee = '%s' and att_date = '%s' and not name = '%s' and docstatus = 1"%(self.doc.employee,self.doc.att_date, self.doc.name))
if res:
msgprint("Employee's attendance already marked.")
raise Exception
#check for already record present in leave transaction for same date
def check_leave_record(self):
if self.doc.status == 'Present':
chk = sql("select name from `tabLeave Application` where employee=%s and (from_date <= %s and to_date >= %s) and docstatus!=2", (self.doc.employee, self.doc.att_date, self.doc.att_date))
if chk:
msgprint("Leave Application created for employee "+self.doc.employee+" whom you are trying to mark as 'Present' ")
raise Exception
def validate_fiscal_year(self):
fy=sql("select year_start_date from `tabFiscal Year` where name='%s'"% self.doc.fiscal_year)
ysd=fy and fy[0][0] or ""
yed=add_days(str(ysd),365)
if str(self.doc.att_date) < str(ysd) or str(self.doc.att_date) > str(yed):
msgprint("'%s' Not Within The Fiscal Year selected"%(self.doc.att_date))
raise Exception
def validate_att_date(self):
import datetime
if getdate(self.doc.att_date)>getdate(datetime.datetime.now().date().strftime('%Y-%m-%d')):
msgprint("Attendance can not be marked for future dates")
raise Exception
ret = { 'employee_name' : emp_nm and emp_nm[0][0] or ''}
return ret
#validation for duplicate record
def validate_duplicate_record(self):
res = sql("select name from `tabAttendance` where employee = '%s' and att_date = '%s' and not name = '%s' and docstatus = 1"%(self.doc.employee,self.doc.att_date, self.doc.name))
if res:
msgprint("Employee's attendance already marked.")
raise Exception
#check for already record present in leave transaction for same date
def check_leave_record(self):
if self.doc.status == 'Present':
chk = sql("select name from `tabLeave Application` where employee=%s and (from_date <= %s and to_date >= %s) and docstatus!=2", (self.doc.employee, self.doc.att_date, self.doc.att_date))
if chk:
msgprint("Leave Application created for employee "+self.doc.employee+" whom you are trying to mark as 'Present' ")
raise Exception
def validate_fiscal_year(self):
fy=sql("select year_start_date from `tabFiscal Year` where name='%s'" % \
self.doc.fiscal_year)
ysd=fy and fy[0][0] or ""
yed=add_days(str(ysd),365)
if str(self.doc.att_date) < str(ysd) or str(self.doc.att_date) > str(yed):
msgprint("'%s' Not Within The Fiscal Year selected"%(self.doc.att_date))
raise Exception
def validate_att_date(self):
import datetime
if getdate(self.doc.att_date)>getdate(datetime.datetime.now().date().strftime('%Y-%m-%d')):
msgprint("Attendance can not be marked for future dates")
raise Exception
# Validate employee
#-------------------
def validate_employee(self):
emp = sql("select name, status from `tabEmployee` where name = '%s'" % self.doc.employee)
if not emp:
msgprint("Employee: %s does not exists in the system" % self.doc.employee, raise_exception=1)
elif emp[0][1] != 'Active':
msgprint("Employee: %s is not Active" % self.doc.employee, raise_exception=1)
# validate...
def validate(self):
self.validate_fiscal_year()
self.validate_att_date()
self.validate_duplicate_record()
#self.validate_status()
self.check_leave_record()
def on_update(self):
#self.validate()
#this is done because sometimes user entered wrong employee name while uploading employee attendance
x=self.get_emp_name()
# Validate employee
#-------------------
def validate_employee(self):
emp = sql("select name, status from `tabEmployee` where name = '%s'" % self.doc.employee)
if not emp:
msgprint("Employee: %s does not exists in the system" % self.doc.employee, raise_exception=1)
elif emp[0][1] != 'Active':
msgprint("Employee: %s is not Active" % self.doc.employee, raise_exception=1)
def validate(self):
import utilities
utilities.validate_status(self.doc.status, ["Present", "Absent", "Half Day"])
def on_submit(self):
#this is done because while uploading attendance chnage docstatus to 1 i.e. submit
webnotes.conn.set(self.doc,'docstatus',1)
pass
self.validate_fiscal_year()
self.validate_att_date()
self.validate_duplicate_record()
self.check_leave_record()
def on_update(self):
#self.validate()
#this is done because sometimes user entered wrong employee name while uploading employee attendance
x=self.get_emp_name()
def on_submit(self):
#this is done because while uploading attendance chnage docstatus to 1 i.e. submit
webnotes.conn.set(self.doc,'docstatus',1)
pass

View File

@@ -19,7 +19,7 @@ import webnotes
from webnotes.utils import getdate, validate_email_add
from webnotes.model.doc import make_autoname
from webnotes import msgprint
from webnotes import msgprint, _
sql = webnotes.conn.sql
@@ -39,6 +39,16 @@ class DocType:
self.doc.name = make_autoname(self.doc.employee_number)
self.doc.employee = self.doc.name
def validate(self):
import utilities
utilities.validate_status(self.doc.status, ["Active", "Left"])
self.doc.employee = self.doc.name
self.validate_date()
self.validate_email()
self.validate_name()
self.validate_status()
def get_retirement_date(self):
import datetime
@@ -52,13 +62,6 @@ class DocType:
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 ''
def validate(self):
self.doc.employee = self.doc.name
self.validate_date()
self.validate_email()
self.validate_name()
self.validate_status()
def on_update(self):
self.update_user_default()

View File

@@ -33,9 +33,8 @@ class DocType:
# if self.doc.exp_approver == self.doc.owner:
# webnotes.msgprint("""Self Approval is not allowed.""", raise_exception=1)
if self.doc.status not in ("Draft", "Approved", "Rejected"):
webnotes.msgprint("Status must be one of 'Draft', 'Approved' or 'Rejected'",
raise_exception=True)
import utilities
utilities.validate_status(self.doc.status, ["Draft", "Approved", "Rejected"])
self.validate_fiscal_year()
self.validate_exp_details()

View File

@@ -33,9 +33,8 @@ class DocType:
def validate(self):
# if self.doc.leave_approver == self.doc.owner:
# webnotes.msgprint("""Self Approval is not allowed.""", raise_exception=1)
if self.doc.status not in ("Open", "Approved", "Rejected"):
webnotes.msgprint("Status must be one of 'Open', 'Approved' or 'Rejected'",
raise_exception=True)
import utilities
utilities.validate_status(self.doc.status, ["Open", "Approved", "Rejected"])
self.validate_to_date()
self.validate_balance_leaves()

View File

@@ -8,11 +8,11 @@
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
import webnotes
@@ -28,87 +28,86 @@ sql = webnotes.conn.sql
class DocType:
#init function
def __init__(self,doc,doclist=[]):
self.doc = doc
self.doclist = doclist
#init function
def __init__(self,doc,doclist=[]):
self.doc = doc
self.doclist = doclist
#autoname function
#---------------------------------------------------------
def autoname(self):
self.doc.name = make_autoname(self.doc.employee + '/.SST' + '/.#####')
#get employee details
#---------------------------------------------------------
def get_employee_details(self):
ret = {}
det = sql("select employee_name, branch, designation, department, grade from `tabEmployee` where name = '%s'" %self.doc.employee)
if det:
ret = {
'employee_name' : cstr(det[0][0]),
'branch' : cstr(det[0][1]),
'designation' : cstr(det[0][2]),
'department' : cstr(det[0][3]),
'grade' : cstr(det[0][4]),
'backup_employee': cstr(self.doc.employee)
}
return ret
#autoname function
#---------------------------------------------------------
def autoname(self):
self.doc.name = make_autoname(self.doc.employee + '/.SST' + '/.#####')
#get employee details
#---------------------------------------------------------
def get_employee_details(self):
ret = {}
det = sql("select employee_name, branch, designation, department, grade from `tabEmployee` where name = '%s'" %self.doc.employee)
if det:
ret = {
'employee_name': cstr(det[0][0]),
'branch': cstr(det[0][1]),
'designation': cstr(det[0][2]),
'department': cstr(det[0][3]),
'grade': cstr(det[0][4]),
'backup_employee': cstr(self.doc.employee)
}
return ret
# Set Salary structure field values
#---------------------------------------------------------
def get_ss_values(self,employee):
basic_info = sql("select bank_name, bank_ac_no, esic_card_no, pf_number from `tabEmployee` where name ='%s'" % employee)
ret = {'bank_name' : basic_info and basic_info[0][0] or '',
'bank_ac_no' : basic_info and basic_info[0][1] or '',
'esic_no' : basic_info and basic_info[0][2] or '',
'pf_no' : basic_info and basic_info[0][3] or ''}
return ret
# Make earning and deduction table
#---------------------------------------------------------
def make_table(self, doct_name, tab_fname, tab_name):
list1 = sql("select name from `tab%s` where docstatus != 2" % doct_name)
for li in list1:
child = addchild(self.doc, tab_fname, tab_name, self.doclist)
if(tab_fname == 'earning_details'):
child.e_type = cstr(li[0])
child.modified_value = 0
elif(tab_fname == 'deduction_details'):
child.d_type = cstr(li[0])
child.d_modified_amt = 0
# add earning & deduction types to table
#---------------------------------------------------------
def make_earn_ded_table(self):
#Earning List
self.make_table('Earning Type','earning_details','Salary Structure Earning')
#Deduction List
self.make_table('Deduction Type','deduction_details', 'Salary Structure Deduction')
# Set Salary structure field values
#---------------------------------------------------------
def get_ss_values(self,employee):
basic_info = sql("select bank_name, bank_ac_no, esic_card_no, pf_number from `tabEmployee` where name ='%s'" % employee)
ret = {'bank_name': basic_info and basic_info[0][0] or '',
'bank_ac_no': basic_info and basic_info[0][1] or '',
'esic_no': basic_info and basic_info[0][2] or '',
'pf_no': basic_info and basic_info[0][3] or ''}
return ret
# Make earning and deduction table
#---------------------------------------------------------
def make_table(self, doct_name, tab_fname, tab_name):
list1 = sql("select name from `tab%s` where docstatus != 2" % doct_name)
for li in list1:
child = addchild(self.doc, tab_fname, tab_name, self.doclist)
if(tab_fname == 'earning_details'):
child.e_type = cstr(li[0])
child.modified_value = 0
elif(tab_fname == 'deduction_details'):
child.d_type = cstr(li[0])
child.d_modified_amt = 0
# add earning & deduction types to table
#---------------------------------------------------------
def make_earn_ded_table(self):
#Earning List
self.make_table('Earning Type','earning_details','Salary Structure Earning')
#Deduction List
self.make_table('Deduction Type','deduction_details',
'Salary Structure Deduction')
# Check if another active ss exists
#---------------------------------------------------------
def check_existing(self):
ret = sql("select name from `tabSalary Structure` where is_active = 'Yes' and employee = '%s' and name!='%s'" %(self.doc.employee,self.doc.name))
if ret and self.doc.is_active=='Yes':
msgprint("Another Salary Structure '%s' is active for employee '%s'. Please make its status 'Inactive' to proceed."%(cstr(ret), self.doc.employee))
raise Exception
# Check if another active ss exists
#---------------------------------------------------------
def check_existing(self):
ret = sql("select name from `tabSalary Structure` where is_active = 'Yes' and employee = '%s' and name!='%s'" %(self.doc.employee,self.doc.name))
if ret and self.doc.is_active=='Yes':
msgprint("Another Salary Structure '%s' is active for employee '%s'. Please make its status 'Inactive' to proceed."%(cstr(ret), self.doc.employee))
raise Exception
# Validate net pay
#---------------------------------------------------------
def validate_net_pay(self):
if flt(self.doc.net_pay) < 0:
msgprint("Net pay can not be negative")
raise Exception
elif flt(self.doc.net_pay) > flt(self.doc.ctc):
msgprint("Net pay can not be greater than CTC")
raise Exception
# Validate net pay
#---------------------------------------------------------
def validate_net_pay(self):
if flt(self.doc.net_pay) < 0:
msgprint("Net pay can not be negative")
raise Exception
elif flt(self.doc.net_pay) > flt(self.doc.ctc):
msgprint("Net pay can not be greater than CTC")
raise Exception
# Validate
#---------------------------------------------------------
def validate(self):
self.check_existing()
self.validate_net_pay()
def validate(self):
self.check_existing()
self.validate_net_pay()