fix: handle negative leaves without allocation

This commit is contained in:
Mangesh-Khairnar 2019-06-06 20:37:34 +05:30
parent f13243a92e
commit 00c607116b
4 changed files with 8 additions and 19 deletions

View File

@ -7,7 +7,6 @@ from frappe.utils import flt, date_diff, formatdate, add_days
from frappe import _
from frappe.model.document import Document
from erpnext.hr.utils import set_employee_name, get_leave_period
from erpnext.hr.doctype.leave_application.leave_application import get_approved_leaves_for_period
from erpnext.hr.doctype.leave_ledger_entry.leave_ledger_entry import create_leave_ledger_entry
class OverlapError(frappe.ValidationError): pass
@ -133,9 +132,9 @@ class LeaveAllocation(Document):
''' expire previous allocation leaves '''
leaves = get_unused_leaves(self.employee, self.leave_type, self.from_date)
if flt(leaves) > 0:
if leaves:
args = dict(
leaves=leaves * -1,
leaves=flt(leaves) * -1,
from_date=self.from_date,
to_date=self.from_date,
is_carry_forward=0,
@ -198,6 +197,7 @@ def get_unused_leaves(employee, leave_type, date):
"employee": employee,
"docstatus": 1,
"leave_type": leave_type,
"is_lwp": 0
}, fieldname=['SUM(leaves)'])
def validate_carry_forward(leave_type):

View File

@ -62,7 +62,7 @@
},
{
"fieldname": "leaves",
"fieldtype": "Int",
"fieldtype": "Float",
"in_list_view": 1,
"label": "Leaves"
},
@ -101,7 +101,7 @@
],
"in_create": 1,
"is_submittable": 1,
"modified": "2019-06-05 12:56:04.980160",
"modified": "2019-06-06 20:33:37.531161",
"modified_by": "Administrator",
"module": "HR",
"name": "Leave Ledger Entry",

View File

@ -9,11 +9,6 @@ from frappe import _
from frappe.utils import add_days, today, flt
class LeaveLedgerEntry(Document):
def validate_entries(self):
total_leaves = frappe.get_all('Leave Ledger Entry', ['SUM(leaves)'])
if total_leaves < 0:
frappe.throw(_("Invalid Ledger Entry"))
def on_cancel(self):
# allow cancellation of expiry leaves
if not self.is_expired:
@ -43,7 +38,8 @@ def create_leave_ledger_entry(ref_doc, args, submit=True):
transaction_type=ref_doc.doctype,
transaction_name=ref_doc.name,
is_carry_forward=0,
is_expired=0
is_expired=0,
is_lwp=0
)
ledger.update(args)
if submit:

View File

@ -10,11 +10,4 @@ from frappe import _
from frappe.model.document import Document
class LeaveType(Document):
def validate(self):
if self.is_carry_forward:
self.validate_carry_forward()
def validate_carry_forward(self):
max_days = 367 if calendar.isleap(datetime.now().year) else 366
if not (0 <= self.carry_forward_leave_expiry <= max_days):
frappe.throw(_('Invalid entry!! Carried forward days need to expire within a year'))
pass