mirror of
https://github.com/frappe/erpnext.git
synced 2026-02-14 02:04:17 +00:00
fix: avoid over allocation during backdated assignment creation
This commit is contained in:
@@ -100,7 +100,7 @@ class LeavePolicyAssignment(Document):
|
|||||||
return leave_allocations
|
return leave_allocations
|
||||||
|
|
||||||
def create_leave_allocation(
|
def create_leave_allocation(
|
||||||
self, leave_type, new_leaves_allocated, leave_type_details, date_of_joining
|
self, leave_type, annual_allocation, leave_type_details, date_of_joining
|
||||||
):
|
):
|
||||||
# Creates leave allocation for the given employee in the provided leave period
|
# Creates leave allocation for the given employee in the provided leave period
|
||||||
carry_forward = self.carry_forward
|
carry_forward = self.carry_forward
|
||||||
@@ -108,7 +108,7 @@ class LeavePolicyAssignment(Document):
|
|||||||
carry_forward = 0
|
carry_forward = 0
|
||||||
|
|
||||||
new_leaves_allocated = self.get_new_leaves(
|
new_leaves_allocated = self.get_new_leaves(
|
||||||
leave_type, new_leaves_allocated, leave_type_details, date_of_joining
|
leave_type, annual_allocation, leave_type_details, date_of_joining
|
||||||
)
|
)
|
||||||
|
|
||||||
allocation = frappe.get_doc(
|
allocation = frappe.get_doc(
|
||||||
@@ -129,7 +129,7 @@ class LeavePolicyAssignment(Document):
|
|||||||
allocation.submit()
|
allocation.submit()
|
||||||
return allocation.name, new_leaves_allocated
|
return allocation.name, new_leaves_allocated
|
||||||
|
|
||||||
def get_new_leaves(self, leave_type, new_leaves_allocated, leave_type_details, date_of_joining):
|
def get_new_leaves(self, leave_type, annual_allocation, leave_type_details, date_of_joining):
|
||||||
from frappe.model.meta import get_field_precision
|
from frappe.model.meta import get_field_precision
|
||||||
|
|
||||||
precision = get_field_precision(
|
precision = get_field_precision(
|
||||||
@@ -146,7 +146,7 @@ class LeavePolicyAssignment(Document):
|
|||||||
else:
|
else:
|
||||||
# get leaves for past months if assignment is based on Leave Period / Joining Date
|
# get leaves for past months if assignment is based on Leave Period / Joining Date
|
||||||
new_leaves_allocated = self.get_leaves_for_passed_months(
|
new_leaves_allocated = self.get_leaves_for_passed_months(
|
||||||
leave_type, new_leaves_allocated, leave_type_details, date_of_joining
|
leave_type, annual_allocation, leave_type_details, date_of_joining
|
||||||
)
|
)
|
||||||
|
|
||||||
# Calculate leaves at pro-rata basis for employees joining after the beginning of the given leave period
|
# Calculate leaves at pro-rata basis for employees joining after the beginning of the given leave period
|
||||||
@@ -156,10 +156,14 @@ class LeavePolicyAssignment(Document):
|
|||||||
)
|
)
|
||||||
new_leaves_allocated = ceil(new_leaves_allocated * remaining_period)
|
new_leaves_allocated = ceil(new_leaves_allocated * remaining_period)
|
||||||
|
|
||||||
|
# leave allocation should not exceed annual allocation as per policy assignment
|
||||||
|
if new_leaves_allocated > annual_allocation:
|
||||||
|
new_leaves_allocated = annual_allocation
|
||||||
|
|
||||||
return flt(new_leaves_allocated, precision)
|
return flt(new_leaves_allocated, precision)
|
||||||
|
|
||||||
def get_leaves_for_passed_months(
|
def get_leaves_for_passed_months(
|
||||||
self, leave_type, new_leaves_allocated, leave_type_details, date_of_joining
|
self, leave_type, annual_allocation, leave_type_details, date_of_joining
|
||||||
):
|
):
|
||||||
from erpnext.hr.utils import get_monthly_earned_leave
|
from erpnext.hr.utils import get_monthly_earned_leave
|
||||||
|
|
||||||
@@ -184,7 +188,7 @@ class LeavePolicyAssignment(Document):
|
|||||||
|
|
||||||
if months_passed > 0:
|
if months_passed > 0:
|
||||||
monthly_earned_leave = get_monthly_earned_leave(
|
monthly_earned_leave = get_monthly_earned_leave(
|
||||||
new_leaves_allocated,
|
annual_allocation,
|
||||||
leave_type_details.get(leave_type).earned_leave_frequency,
|
leave_type_details.get(leave_type).earned_leave_frequency,
|
||||||
leave_type_details.get(leave_type).rounding,
|
leave_type_details.get(leave_type).rounding,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user