From 9f1e018e4f868220a985af6784c1940a67d47b82 Mon Sep 17 00:00:00 2001 From: Ganga Manoj Date: Fri, 18 Dec 2020 01:35:27 +0530 Subject: [PATCH] feat: Compute year_to_date --- .../doctype/salary_slip/salary_slip.py | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/erpnext/payroll/doctype/salary_slip/salary_slip.py b/erpnext/payroll/doctype/salary_slip/salary_slip.py index 20365b191d..27de46acc3 100644 --- a/erpnext/payroll/doctype/salary_slip/salary_slip.py +++ b/erpnext/payroll/doctype/salary_slip/salary_slip.py @@ -35,6 +35,9 @@ class SalarySlip(TransactionBase): def autoname(self): self.name = make_autoname(self.series) + def before_save(self): + self.compute_year_to_date() + def validate(self): self.status = self.get_status() self.validate_dates() @@ -1125,6 +1128,26 @@ class SalarySlip(TransactionBase): self.gross_pay += self.earnings[i].amount self.net_pay = flt(self.gross_pay) - flt(self.total_deduction) + def compute_year_to_date(self): + year_to_date = 0 + fiscal_year = frappe.get_list('Fiscal Year', + fields = ['year','year_start_date','year_end_date'], + filters= {'year_start_date' : ['<=', self.start_date], + 'year_end_date' : ['>=', self.end_date] + })[0] + salary_slips_from_current_fiscal_year = frappe.get_list('Salary Slip', + fields = ['employee_name', 'start_date', 'end_date', 'net_pay'], + filters = {'employee_name' : self.employee_name, + 'start_date' : ['>=', fiscal_year.year_start_date], + 'end_date' : ['<=', fiscal_year.year_end_date] + }) + + for salary_slip in salary_slips_from_current_fiscal_year: + year_to_date += salary_slip.net_pay + + year_to_date += self.net_pay + self.year_to_date = year_to_date + def unlink_ref_doc_from_salary_slip(ref_no): linked_ss = frappe.db.sql_list("""select name from `tabSalary Slip` where journal_entry=%s and docstatus < 2""", (ref_no)) @@ -1135,4 +1158,4 @@ def unlink_ref_doc_from_salary_slip(ref_no): def generate_password_for_pdf(policy_template, employee): employee = frappe.get_doc("Employee", employee) - return policy_template.format(**employee.as_dict()) + return policy_template.format(**employee.as_dict()) \ No newline at end of file