fix: skip leave ledger entry creation for denied leaves (#19556)
* fix: skip leave ledger entry creation for denied leave application * patch: remove incorrect leave ledger entries * fix: create reverse ledger entry before setting status to cancel
This commit is contained in:
parent
5503b6cff5
commit
fc3b924d4d
@ -55,11 +55,11 @@ class LeaveApplication(Document):
|
|||||||
self.reload()
|
self.reload()
|
||||||
|
|
||||||
def on_cancel(self):
|
def on_cancel(self):
|
||||||
|
self.create_leave_ledger_entry(submit=False)
|
||||||
self.status = "Cancelled"
|
self.status = "Cancelled"
|
||||||
# notify leave applier about cancellation
|
# notify leave applier about cancellation
|
||||||
self.notify_employee()
|
self.notify_employee()
|
||||||
self.cancel_attendance()
|
self.cancel_attendance()
|
||||||
self.create_leave_ledger_entry(submit=False)
|
|
||||||
|
|
||||||
def validate_applicable_after(self):
|
def validate_applicable_after(self):
|
||||||
if self.leave_type:
|
if self.leave_type:
|
||||||
@ -351,6 +351,9 @@ class LeaveApplication(Document):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def create_leave_ledger_entry(self, submit=True):
|
def create_leave_ledger_entry(self, submit=True):
|
||||||
|
if self.status != 'Approved':
|
||||||
|
return
|
||||||
|
|
||||||
expiry_date = get_allocation_expiry(self.employee, self.leave_type,
|
expiry_date = get_allocation_expiry(self.employee, self.leave_type,
|
||||||
self.to_date, self.from_date)
|
self.to_date, self.from_date)
|
||||||
|
|
||||||
|
|||||||
@ -638,7 +638,6 @@ erpnext.patches.v12_0.add_variant_of_in_item_attribute_table
|
|||||||
erpnext.patches.v12_0.rename_bank_account_field_in_journal_entry_account
|
erpnext.patches.v12_0.rename_bank_account_field_in_journal_entry_account
|
||||||
erpnext.patches.v12_0.create_default_energy_point_rules
|
erpnext.patches.v12_0.create_default_energy_point_rules
|
||||||
erpnext.patches.v12_0.set_produced_qty_field_in_sales_order_for_work_order
|
erpnext.patches.v12_0.set_produced_qty_field_in_sales_order_for_work_order
|
||||||
erpnext.patches.v12_0.generate_leave_ledger_entries
|
|
||||||
erpnext.patches.v12_0.set_default_shopify_app_type
|
erpnext.patches.v12_0.set_default_shopify_app_type
|
||||||
erpnext.patches.v12_0.set_cwip_and_delete_asset_settings
|
erpnext.patches.v12_0.set_cwip_and_delete_asset_settings
|
||||||
erpnext.patches.v12_0.set_expense_account_in_landed_cost_voucher_taxes
|
erpnext.patches.v12_0.set_expense_account_in_landed_cost_voucher_taxes
|
||||||
@ -646,3 +645,4 @@ erpnext.patches.v12_0.replace_accounting_with_accounts_in_home_settings
|
|||||||
erpnext.patches.v12_0.set_payment_entry_status
|
erpnext.patches.v12_0.set_payment_entry_status
|
||||||
erpnext.patches.v12_0.update_owner_fields_in_acc_dimension_custom_fields
|
erpnext.patches.v12_0.update_owner_fields_in_acc_dimension_custom_fields
|
||||||
erpnext.patches.v12_0.set_default_for_add_taxes_from_item_tax_template
|
erpnext.patches.v12_0.set_default_for_add_taxes_from_item_tax_template
|
||||||
|
erpnext.patches.v12_0.remove_denied_leaves_from_leave_ledger
|
||||||
@ -0,0 +1,26 @@
|
|||||||
|
# Copyright (c) 2018, Frappe and Contributors
|
||||||
|
# License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
import frappe
|
||||||
|
from frappe.utils import getdate, today
|
||||||
|
|
||||||
|
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):
|
||||||
|
frappe.db.sql(''' Delete
|
||||||
|
FROM `tabLeave Ledger Entry`
|
||||||
|
WHERE
|
||||||
|
transaction_type = 'Leave Application'
|
||||||
|
AND transaction_name in {0} '''.format(tuple(leave_application_list))) #nosec
|
||||||
Loading…
x
Reference in New Issue
Block a user