mirror of
https://github.com/frappe/erpnext.git
synced 2026-04-01 11:22:11 +02:00
fix: allow creation of additional leave ledger entry
This commit is contained in:
@@ -69,10 +69,14 @@ class LeaveAllocation(Document):
|
||||
|
||||
def validate_allocation_overlap(self):
|
||||
leave_allocation = frappe.db.sql("""
|
||||
select name from `tabLeave Allocation`
|
||||
where employee=%s and leave_type=%s and docstatus=1
|
||||
and to_date >= %s and from_date <= %s""",
|
||||
(self.employee, self.leave_type, self.from_date, self.to_date))
|
||||
SELECT
|
||||
name
|
||||
FROM `tabLeave Allocation`
|
||||
WHERE
|
||||
employee=%s AND leave_type=%s
|
||||
AND name <> %s AND docstatus=1
|
||||
AND to_date >= %s AND from_date <= %s""",
|
||||
(self.employee, self.leave_type, self.name, self.from_date, self.to_date))
|
||||
|
||||
if leave_allocation:
|
||||
frappe.msgprint(_("{0} already allocated for Employee {1} for period {2} to {3}")
|
||||
|
||||
@@ -549,10 +549,10 @@ def get_leaves_for_period(employee, leave_type, from_date, to_date):
|
||||
leave_days += leave_entry.leaves
|
||||
|
||||
elif inclusive_period and leave_entry.transaction_type == 'Leave Allocation' \
|
||||
and not skip_expiry_leaves(leave_entry, to_date):
|
||||
and leave_entry.is_expired and not skip_expiry_leaves(leave_entry, to_date):
|
||||
leave_days += leave_entry.leaves
|
||||
|
||||
else:
|
||||
elif leave_entry.transaction_type == 'Leave Application':
|
||||
if leave_entry.from_date < getdate(from_date):
|
||||
leave_entry.from_date = from_date
|
||||
if leave_entry.to_date > getdate(to_date):
|
||||
@@ -579,14 +579,15 @@ def skip_expiry_leaves(leave_entry, date):
|
||||
def get_leave_entries(employee, leave_type, from_date, to_date):
|
||||
''' Returns leave entries between from_date and to_date '''
|
||||
return frappe.db.sql("""
|
||||
select employee, leave_type, from_date, to_date, leaves, transaction_type, is_carry_forward, transaction_name
|
||||
from `tabLeave Ledger Entry`
|
||||
where employee=%(employee)s and leave_type=%(leave_type)s
|
||||
and docstatus=1
|
||||
and leaves<0
|
||||
and (from_date between %(from_date)s and %(to_date)s
|
||||
or to_date between %(from_date)s and %(to_date)s
|
||||
or (from_date < %(from_date)s and to_date > %(to_date)s))
|
||||
SELECT
|
||||
employee, leave_type, from_date, to_date, leaves, transaction_name, transaction_type,
|
||||
is_carry_forward, is_expired
|
||||
FROM `tabLeave Ledger Entry`
|
||||
WHERE employee=%(employee)s AND leave_type=%(leave_type)s
|
||||
AND docstatus=1 AND leaves<0
|
||||
AND (from_date between %(from_date)s AND %(to_date)s
|
||||
OR to_date between %(from_date)s AND %(to_date)s
|
||||
OR (from_date < %(from_date)s AND to_date > %(to_date)s))
|
||||
""", {
|
||||
"from_date": from_date,
|
||||
"to_date": to_date,
|
||||
@@ -773,4 +774,4 @@ def get_leave_approver(employee):
|
||||
leave_approver = frappe.db.get_value('Department Approver', {'parent': department,
|
||||
'parentfield': 'leave_approvers', 'idx': 1}, 'approver')
|
||||
|
||||
return leave_approver
|
||||
return leave_approver
|
||||
@@ -43,10 +43,18 @@ class TestLeavePeriod(unittest.TestCase):
|
||||
leave_period.grant_leave_allocation(employee=employee_doc_name)
|
||||
self.assertEqual(get_leave_balance_on(employee_doc_name, leave_type, today()), 20)
|
||||
|
||||
def create_leave_period(from_date, to_date):
|
||||
def create_leave_period(from_date, to_date, company=None):
|
||||
leave_period = frappe.db.get_value('Leave Period',
|
||||
dict(company=company or erpnext.get_default_company(),
|
||||
from_date=from_date,
|
||||
to_date=to_date,
|
||||
is_active=1), 'name')
|
||||
if leave_period:
|
||||
return frappe.get_doc("Leave Period", leave_period)
|
||||
|
||||
leave_period = frappe.get_doc({
|
||||
"doctype": "Leave Period",
|
||||
"company": erpnext.get_default_company(),
|
||||
"company": company or erpnext.get_default_company(),
|
||||
"from_date": from_date,
|
||||
"to_date": to_date,
|
||||
"is_active": 1
|
||||
|
||||
@@ -321,11 +321,11 @@ def allocate_earned_leaves():
|
||||
if new_allocation == allocation.total_leaves_allocated:
|
||||
continue
|
||||
allocation.db_set("total_leaves_allocated", new_allocation, update_modified=False)
|
||||
create_earned_leave_ledger_entry(allocation, earned_leaves, today)
|
||||
create_additional_leave_ledger_entry(allocation, earned_leaves, today)
|
||||
|
||||
def create_earned_leave_ledger_entry(allocation, earned_leaves, date):
|
||||
''' Create leave ledger entry based on the earned leave frequency '''
|
||||
allocation.new_leaves_allocated = earned_leaves
|
||||
def create_additional_leave_ledger_entry(allocation, leaves, date):
|
||||
''' Create leave ledger entry for leave types '''
|
||||
allocation.new_leaves_allocated = leaves
|
||||
allocation.from_date = date
|
||||
allocation.unused_leaves = 0
|
||||
allocation.create_leave_ledger_entry()
|
||||
@@ -389,6 +389,7 @@ def get_sal_slip_total_benefit_given(employee, payroll_period, component=False):
|
||||
|
||||
def get_holidays_for_employee(employee, start_date, end_date):
|
||||
holiday_list = get_holiday_list_for_employee(employee)
|
||||
|
||||
holidays = frappe.db.sql_list('''select holiday_date from `tabHoliday`
|
||||
where
|
||||
parent=%(holiday_list)s
|
||||
@@ -437,4 +438,4 @@ def get_previous_claimed_amount(employee, payroll_period, non_pro_rata=False, co
|
||||
}, as_dict=True)
|
||||
if sum_of_claimed_amount and flt(sum_of_claimed_amount[0].total_amount) > 0:
|
||||
total_claimed_amount = sum_of_claimed_amount[0].total_amount
|
||||
return total_claimed_amount
|
||||
return total_claimed_amount
|
||||
Reference in New Issue
Block a user