mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-03 12:19:12 +00:00
fix: remove HR/Payroll patches
This commit is contained in:
@@ -1,100 +0,0 @@
|
||||
# Copyright (c) 2018, Frappe and Contributors
|
||||
# License: GNU General Public License v3. See license.txt
|
||||
|
||||
|
||||
import frappe
|
||||
from frappe.utils import getdate, today
|
||||
|
||||
|
||||
def execute():
|
||||
"""Generates leave ledger entries for leave allocation/application/encashment
|
||||
for last allocation"""
|
||||
frappe.reload_doc("HR", "doctype", "Leave Ledger Entry")
|
||||
frappe.reload_doc("HR", "doctype", "Leave Encashment")
|
||||
frappe.reload_doc("HR", "doctype", "Leave Type")
|
||||
|
||||
if not frappe.get_meta("Leave Allocation").has_field("unused_leaves"):
|
||||
frappe.reload_doc("HR", "doctype", "Leave Allocation")
|
||||
update_leave_allocation_fieldname()
|
||||
|
||||
generate_allocation_ledger_entries()
|
||||
generate_application_leave_ledger_entries()
|
||||
generate_encashment_leave_ledger_entries()
|
||||
generate_expiry_allocation_ledger_entries()
|
||||
|
||||
|
||||
def update_leave_allocation_fieldname():
|
||||
"""maps data from old field to the new field"""
|
||||
frappe.db.sql(
|
||||
"""
|
||||
UPDATE `tabLeave Allocation`
|
||||
SET `unused_leaves` = `carry_forwarded_leaves`
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
def generate_allocation_ledger_entries():
|
||||
"""fix ledger entries for missing leave allocation transaction"""
|
||||
allocation_list = get_allocation_records()
|
||||
|
||||
for allocation in allocation_list:
|
||||
if not frappe.db.exists(
|
||||
"Leave Ledger Entry",
|
||||
{"transaction_type": "Leave Allocation", "transaction_name": allocation.name},
|
||||
):
|
||||
allocation_obj = frappe.get_doc("Leave Allocation", allocation)
|
||||
allocation_obj.create_leave_ledger_entry()
|
||||
|
||||
|
||||
def generate_application_leave_ledger_entries():
|
||||
"""fix ledger entries for missing leave application transaction"""
|
||||
leave_applications = get_leaves_application_records()
|
||||
|
||||
for application in leave_applications:
|
||||
if not frappe.db.exists(
|
||||
"Leave Ledger Entry",
|
||||
{"transaction_type": "Leave Application", "transaction_name": application.name},
|
||||
):
|
||||
frappe.get_doc("Leave Application", application.name).create_leave_ledger_entry()
|
||||
|
||||
|
||||
def generate_encashment_leave_ledger_entries():
|
||||
"""fix ledger entries for missing leave encashment transaction"""
|
||||
leave_encashments = get_leave_encashment_records()
|
||||
|
||||
for encashment in leave_encashments:
|
||||
if not frappe.db.exists(
|
||||
"Leave Ledger Entry",
|
||||
{"transaction_type": "Leave Encashment", "transaction_name": encashment.name},
|
||||
):
|
||||
frappe.get_doc("Leave Encashment", encashment).create_leave_ledger_entry()
|
||||
|
||||
|
||||
def generate_expiry_allocation_ledger_entries():
|
||||
"""fix ledger entries for missing leave allocation transaction"""
|
||||
from erpnext.hr.doctype.leave_ledger_entry.leave_ledger_entry import expire_allocation
|
||||
|
||||
allocation_list = get_allocation_records()
|
||||
|
||||
for allocation in allocation_list:
|
||||
if not frappe.db.exists(
|
||||
"Leave Ledger Entry",
|
||||
{"transaction_type": "Leave Allocation", "transaction_name": allocation.name, "is_expired": 1},
|
||||
):
|
||||
allocation_obj = frappe.get_doc("Leave Allocation", allocation)
|
||||
if allocation_obj.to_date <= getdate(today()):
|
||||
expire_allocation(allocation_obj)
|
||||
|
||||
|
||||
def get_allocation_records():
|
||||
return frappe.get_all(
|
||||
"Leave Allocation", filters={"docstatus": 1}, fields=["name"], order_by="to_date ASC"
|
||||
)
|
||||
|
||||
|
||||
def get_leaves_application_records():
|
||||
return frappe.get_all("Leave Application", filters={"docstatus": 1}, fields=["name"])
|
||||
|
||||
|
||||
def get_leave_encashment_records():
|
||||
return frappe.get_all("Leave Encashment", filters={"docstatus": 1}, fields=["name"])
|
||||
@@ -1,12 +0,0 @@
|
||||
# Copyright (c) 2019, Frappe and Contributors
|
||||
# License: GNU General Public License v3. See license.txt
|
||||
|
||||
|
||||
import frappe
|
||||
|
||||
|
||||
def execute():
|
||||
"""Move from due_advance_amount to pending_amount"""
|
||||
|
||||
if frappe.db.has_column("Employee Advance", "due_advance_amount"):
|
||||
frappe.db.sql(""" UPDATE `tabEmployee Advance` SET pending_amount=due_advance_amount """)
|
||||
@@ -1,35 +0,0 @@
|
||||
# Copyright (c) 2018, Frappe and Contributors
|
||||
# License: GNU General Public License v3. See license.txt
|
||||
|
||||
|
||||
import frappe
|
||||
|
||||
|
||||
def execute():
|
||||
"""Delete leave ledger entry created
|
||||
via leave applications with status != Approved"""
|
||||
if not frappe.db.a_row_exists("Leave Ledger Entry"):
|
||||
return
|
||||
|
||||
leave_application_list = get_denied_leave_application_list()
|
||||
if leave_application_list:
|
||||
delete_denied_leaves_from_leave_ledger_entry(leave_application_list)
|
||||
|
||||
|
||||
def get_denied_leave_application_list():
|
||||
return frappe.db.sql_list(
|
||||
""" Select name from `tabLeave Application` where status <> 'Approved' """
|
||||
)
|
||||
|
||||
|
||||
def delete_denied_leaves_from_leave_ledger_entry(leave_application_list):
|
||||
if leave_application_list:
|
||||
frappe.db.sql(
|
||||
""" Delete
|
||||
FROM `tabLeave Ledger Entry`
|
||||
WHERE
|
||||
transaction_type = 'Leave Application'
|
||||
AND transaction_name in (%s) """
|
||||
% (", ".join(["%s"] * len(leave_application_list))), # nosec
|
||||
tuple(leave_application_list),
|
||||
)
|
||||
@@ -1,55 +0,0 @@
|
||||
# Copyright (c) 2018, Frappe and Contributors
|
||||
# License: GNU General Public License v3. See license.txt
|
||||
|
||||
|
||||
import frappe
|
||||
|
||||
|
||||
def execute():
|
||||
"""Delete duplicate leave ledger entries of type allocation created."""
|
||||
frappe.reload_doc("hr", "doctype", "leave_ledger_entry")
|
||||
if not frappe.db.a_row_exists("Leave Ledger Entry"):
|
||||
return
|
||||
|
||||
duplicate_records_list = get_duplicate_records()
|
||||
delete_duplicate_ledger_entries(duplicate_records_list)
|
||||
|
||||
|
||||
def get_duplicate_records():
|
||||
"""Fetch all but one duplicate records from the list of expired leave allocation."""
|
||||
return frappe.db.sql(
|
||||
"""
|
||||
SELECT name, employee, transaction_name, leave_type, is_carry_forward, from_date, to_date
|
||||
FROM `tabLeave Ledger Entry`
|
||||
WHERE
|
||||
transaction_type = 'Leave Allocation'
|
||||
AND docstatus = 1
|
||||
AND is_expired = 1
|
||||
GROUP BY
|
||||
employee, transaction_name, leave_type, is_carry_forward, from_date, to_date
|
||||
HAVING
|
||||
count(name) > 1
|
||||
ORDER BY
|
||||
creation
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
def delete_duplicate_ledger_entries(duplicate_records_list):
|
||||
"""Delete duplicate leave ledger entries."""
|
||||
if not duplicate_records_list:
|
||||
return
|
||||
for d in duplicate_records_list:
|
||||
frappe.db.sql(
|
||||
"""
|
||||
DELETE FROM `tabLeave Ledger Entry`
|
||||
WHERE name != %s
|
||||
AND employee = %s
|
||||
AND transaction_name = %s
|
||||
AND leave_type = %s
|
||||
AND is_carry_forward = %s
|
||||
AND from_date = %s
|
||||
AND to_date = %s
|
||||
""",
|
||||
tuple(d),
|
||||
)
|
||||
@@ -1,6 +0,0 @@
|
||||
import frappe
|
||||
|
||||
|
||||
def execute():
|
||||
frappe.reload_doc("hr", "doctype", "hr_settings")
|
||||
frappe.db.set_value("HR Settings", None, "payroll_based_on", "Leave")
|
||||
@@ -1,14 +0,0 @@
|
||||
import frappe
|
||||
|
||||
|
||||
def execute():
|
||||
frappe.reload_doc("hr", "doctype", "job_offer")
|
||||
|
||||
frappe.db.sql(
|
||||
"""
|
||||
UPDATE
|
||||
`tabJob Offer` AS offer
|
||||
SET
|
||||
applicant_email = (SELECT email_id FROM `tabJob Applicant` WHERE name = offer.job_applicant)
|
||||
"""
|
||||
)
|
||||
Reference in New Issue
Block a user