[Minor] Apply Salary Slip validation only if it is submitted

This commit is contained in:
Kanchan Chauhan 2016-12-06 12:50:46 +05:30
parent b9ebbf18f2
commit dc80b35104
3 changed files with 16 additions and 3 deletions

View File

@ -38,6 +38,7 @@ class LeaveApplication(Document):
self.validate_block_days()
self.validate_salary_processed_days()
self.validate_leave_approver()
self.validate_attendance()
def on_update(self):
if (not self.previous_doc and self.leave_approver) or (self.previous_doc and \
@ -102,7 +103,7 @@ class LeaveApplication(Document):
last_processed_pay_slip = frappe.db.sql("""
select start_date, end_date from `tabSalary Slip`
where docstatus != 2 and employee = %s
where docstatus = 1 and employee = %s
and ((%s between start_date and end_date) or (%s between start_date and end_date))
order by modified desc limit 1
""",(self.employee, self.to_date, self.from_date))
@ -213,6 +214,13 @@ class LeaveApplication(Document):
frappe.throw(_("Only the selected Leave Approver can submit this Leave Application"),
LeaveApproverIdentityError)
def validate_attendance(self):
attendance = frappe.db.sql("""select name from `tabAttendance` where employee = %s and (att_date between %s and %s)
and docstatus = 1""",
(self.employee, self.from_date, self.to_date))
if attendance:
frappe.throw(_("Attendance for employee {0} is already marked for this day").format(self.employee))
def notify_employee(self, status):
employee = frappe.get_doc("Employee", self.employee)
if not employee.user_id:

View File

@ -231,10 +231,15 @@ class SalarySlip(TransactionBase):
if working_days < 0:
frappe.throw(_("There are more holidays than working days this month."))
actual_lwp = self.calculate_lwp(holidays, working_days)
if not lwp:
lwp = self.calculate_lwp(holidays, working_days)
lwp = actual_lwp
elif lwp != actual_lwp:
frappe.msgprint(_("Leave Without Pay does not match with approved Leave Application records"))
self.total_days_in_month = working_days
self.leave_without_pay = lwp
payment_days = flt(self.get_payment_days(joining_date, relieving_date)) - flt(lwp)
self.payment_days = payment_days > 0 and payment_days or 0

View File

@ -48,7 +48,7 @@ def get_columns(salary_slips):
from `tabSalary Detail` sd, `tabSalary Component` sc
where sc.name=sd.salary_component and sd.amount != 0 and sd.parent in (%s)""" %
(', '.join(['%s']*len(salary_slips))), tuple([d.name for d in salary_slips]), as_dict=1):
salary_components[component.type].append(component.salary_component)
salary_components[_(component.type)].append(component.salary_component)
columns = columns + [(e + ":Currency:120") for e in salary_components[_("Earning")]] + \
[ _("Arrear Amount") + ":Currency:120", _("Leave Encashment Amount") + ":Currency:150",