From 09572d989272a5f73d18c1cfaa3af238f73dde27 Mon Sep 17 00:00:00 2001 From: Anurag Mishra Date: Mon, 4 May 2020 17:07:15 +0530 Subject: [PATCH] patch: to link additional salary with salary slip and leave encashment, incentive with additional salary --- .../doctype/salary_detail/salary_detail.json | 2 +- erpnext/patches.txt | 1 + ...itional_salary_encashment_and_incentive.py | 35 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 erpnext/patches/v13_0/patch_to_fix_reverse_linking_in_additional_salary_encashment_and_incentive.py diff --git a/erpnext/hr/doctype/salary_detail/salary_detail.json b/erpnext/hr/doctype/salary_detail/salary_detail.json index 92942d8a63..fe5f83b532 100644 --- a/erpnext/hr/doctype/salary_detail/salary_detail.json +++ b/erpnext/hr/doctype/salary_detail/salary_detail.json @@ -211,7 +211,7 @@ ], "istable": 1, "links": [], - "modified": "2020-04-24 20:00:16.475295", + "modified": "2020-04-04 20:00:16.475295", "modified_by": "Administrator", "module": "HR", "name": "Salary Detail", diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 5295399695..533a349072 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -677,3 +677,4 @@ erpnext.patches.v13_0.move_tax_slabs_from_payroll_period_to_income_tax_slab #123 erpnext.patches.v12_0.fix_quotation_expired_status erpnext.patches.v12_0.update_appointment_reminder_scheduler_entry erpnext.patches.v12_0.retain_permission_rules_for_video_doctype +erpnext.patches.v13_0.patch_to_fix_reverse_linking_in_additional_salary_encashment_and_incentive #gyhdghksdhsjsd diff --git a/erpnext/patches/v13_0/patch_to_fix_reverse_linking_in_additional_salary_encashment_and_incentive.py b/erpnext/patches/v13_0/patch_to_fix_reverse_linking_in_additional_salary_encashment_and_incentive.py new file mode 100644 index 0000000000..8b8e60db0b --- /dev/null +++ b/erpnext/patches/v13_0/patch_to_fix_reverse_linking_in_additional_salary_encashment_and_incentive.py @@ -0,0 +1,35 @@ +from __future__ import unicode_literals + +import frappe + +def execute(): + + additional_salaries = frappe.get_all("Additional Salary", fields = ['name', "salary_slip", "type", "salary_component"], group_by = 'salary_slip') + leave_encashments = frappe.get_all("Leave Encashment", fields = ["name","additional_salary"]) + employee_incentives = frappe.get_all("Employee Incentive", fields= ["name", "additional_salary"]) + + for incentive in employee_incentives: + frappe.db.sql(""" UPDATE `tabAdditional Salary` + SET ref_doctype = 'Employee Incentive', ref_docname = %s + WHERE name = %s + """, (incentive['name'], incentive['additional_salary'])) + + + for leave_encashment in leave_encashments: + frappe.db.sql(""" UPDATE `tabAdditional Salary` + SET ref_doctype = 'Leave Encashment', ref_docname = %s + WHERE name = %s + """, (leave_encashment['name'], leave_encashment['additional_salary'])) + + salary_slips = [sal["salary_slip"] for sal in additional_salaries] + + for salary in additional_salaries: + comp_type = "earnings" if salary['type'] == 'Earning' else 'deductions' + if salary["salary_slip"] and salary_slips.count(salary["salary_slip"]) == 1: + frappe.db.sql(""" UPDATE `tabsalary Detail` + SET additional_salary = %s + WHERE parenttype = 'Salary Slip' + and parentfield = %s + and parent = %s + and salary_component = %s""", (salary["name"], comp_type, salary["salary_slip"], salary["salary_component"])) +