fix: improve filter for from_date
; validation for joining and relieving date
This commit is contained in:
parent
447c978757
commit
74818c7b62
@ -115,10 +115,23 @@ class SalarySlip(TransactionBase):
|
||||
status = "Cancelled"
|
||||
return status
|
||||
|
||||
def validate_dates(self):
|
||||
def validate_dates(self, joining_date=None, relieving_date=None):
|
||||
if date_diff(self.end_date, self.start_date) < 0:
|
||||
frappe.throw(_("To date cannot be before From date"))
|
||||
|
||||
if not joining_date:
|
||||
joining_date, relieving_date = frappe.get_cached_value(
|
||||
"Employee",
|
||||
self.employee,
|
||||
("date_of_joining", "relieving_date")
|
||||
)
|
||||
|
||||
if date_diff(self.end_date, joining_date) < 0:
|
||||
frappe.throw(_("Cannot create Salary Slip for Employee joining after Payroll Period"))
|
||||
|
||||
if relieving_date and date_diff(relieving_date, self.start_date) < 0:
|
||||
frappe.throw(_("Cannot create Salary Slip for Employee who has left before Payroll Period"))
|
||||
|
||||
def is_rounding_total_disabled(self):
|
||||
return cint(frappe.db.get_single_value("Payroll Settings", "disable_rounded_total"))
|
||||
|
||||
@ -154,9 +167,14 @@ class SalarySlip(TransactionBase):
|
||||
|
||||
if not self.salary_slip_based_on_timesheet:
|
||||
self.get_date_details()
|
||||
self.validate_dates()
|
||||
joining_date, relieving_date = frappe.get_cached_value("Employee", self.employee,
|
||||
["date_of_joining", "relieving_date"])
|
||||
|
||||
joining_date, relieving_date = frappe.get_cached_value(
|
||||
"Employee",
|
||||
self.employee,
|
||||
("date_of_joining", "relieving_date")
|
||||
)
|
||||
|
||||
self.validate_dates(joining_date, relieving_date)
|
||||
|
||||
#getin leave details
|
||||
self.get_working_days_details(joining_date, relieving_date)
|
||||
@ -492,13 +510,21 @@ class SalarySlip(TransactionBase):
|
||||
def get_data_for_eval(self):
|
||||
'''Returns data for evaluating formula'''
|
||||
data = frappe._dict()
|
||||
employee = frappe.get_doc("Employee", self.employee).as_dict()
|
||||
|
||||
start_date = getdate(self.start_date)
|
||||
date_to_validate = (
|
||||
employee.date_of_joining
|
||||
if employee.date_of_joining > start_date
|
||||
else start_date
|
||||
)
|
||||
|
||||
salary_structure_assignment = frappe.get_value(
|
||||
"Salary Structure Assignment",
|
||||
{
|
||||
"employee": self.employee,
|
||||
"salary_structure": self.salary_structure,
|
||||
"from_date": ("<=", self.start_date),
|
||||
"from_date": ("<=", date_to_validate),
|
||||
"docstatus": 1,
|
||||
},
|
||||
order_by="from_date desc",
|
||||
@ -509,14 +535,14 @@ class SalarySlip(TransactionBase):
|
||||
_("Please assign a Salary Structure for Employee {0} "
|
||||
"applicable from or before {1} first").format(
|
||||
frappe.bold(self.employee_name),
|
||||
frappe.bold(self.start_date)
|
||||
frappe.bold(formatdate(date_to_validate)),
|
||||
)
|
||||
)
|
||||
|
||||
data.update(frappe.get_doc("Salary Structure Assignment",
|
||||
salary_structure_assignment).as_dict())
|
||||
|
||||
data.update(frappe.get_doc("Employee", self.employee).as_dict())
|
||||
data.update(employee)
|
||||
data.update(self.as_dict())
|
||||
|
||||
# set values for components
|
||||
|
Loading…
Reference in New Issue
Block a user