fix: update status on salary Slip submission

This commit is contained in:
Anurag Mishra 2020-10-28 15:46:51 +05:30
parent 46e1c09b45
commit 78fdd5d9b4
2 changed files with 21 additions and 5 deletions

View File

@ -14,11 +14,8 @@ class Gratuity(Document):
data = calculate_work_experience_and_amount(self.employee, self.gratuity_rule)
self.current_work_experience = data["current_work_experience"]
self.amount = data["amount"]
def before_submit(self):
self.status = "Unpaid"
if self.pay_via_salary_slip:
self.status = "Paid"
if self.docstatus == 1:
self.status = "Unpaid"
def on_submit(self):
self.create_additional_salary()

View File

@ -74,9 +74,27 @@ class SalarySlip(TransactionBase):
if (frappe.db.get_single_value("Payroll Settings", "email_salary_slip_to_employee")) and not frappe.flags.via_payroll_entry:
self.email_salary_slip()
self.update_payment_status_for_gratuity()
def update_payment_status_for_gratuity(self):
add_salary = frappe.db.get_all("Additional Salary",
filters = {
"payroll_date": ("BETWEEN", [self.start_date, self.end_date]),
"employee": self.employee,
"ref_doctype": "Gratuity",
"docstatus": 1,
}, fields = ["ref_docname", "name"])[0]
status = "Paid" if self.docstatus == 1 else "Unpaid"
if add_salary and add_salary.name in [data.additional_salary for data in self.earnings]:
frappe.db.set_value("Gratuity", add_salary.ref_docname, "status", status)
def on_cancel(self):
self.set_status()
self.update_status()
self.update_payment_status_for_gratuity()
self.cancel_loan_repayment_entry()
def on_trash(self):
@ -566,6 +584,7 @@ class SalarySlip(TransactionBase):
for d in self.get(key):
if d.salary_component == struct_row.salary_component:
component_row = d
if not component_row or (struct_row.get("is_additional_component") and not overwrite):
if amount:
self.append(key, {