From 4c721cbe0ff5b28807e1c0ff80fbb96d63223cfe Mon Sep 17 00:00:00 2001 From: Ranjith Date: Tue, 15 May 2018 16:39:20 +0530 Subject: [PATCH] Leave Encashment - submit, cancel Additional Salary Component --- .../doctype/leave_encashment/leave_encashment.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/erpnext/hr/doctype/leave_encashment/leave_encashment.py b/erpnext/hr/doctype/leave_encashment/leave_encashment.py index 1e2c3b9dce4..25db392df6b 100644 --- a/erpnext/hr/doctype/leave_encashment/leave_encashment.py +++ b/erpnext/hr/doctype/leave_encashment/leave_encashment.py @@ -26,15 +26,25 @@ class LeaveEncashment(Document): def on_submit(self): if not self.leave_allocation: self.leave_allocation = self.get_leave_allocation() - - #ToDo: Create Additional Salary Component + additional_component = frappe.new_doc({"doctype": "Additional Salary Component", + "company": frappe.get_value("Employee", self.employee, "company"), + "employee": self.employee, + "salary_component": frappe.get_value("Leave Type", self.leave_type, "earning_component"), + "from_date": self.encashment_date, + "to_date": self.encashment_date, + "amount": self.encashment_amount, + "docstatus": 1 + }).insert() + self.set_value("additional_component", additional_component.name) # Set encashed leaves in Allocation frappe.db.set_value("Leave Allocation", self.leave_allocation, "total_leaves_encashed", frappe.db.get_value('Leave Allocation', self.leave_allocation, 'total_leaves_encashed') + self.encashable_days) def on_cancel(self): - # ToDo: Cancel Additional Salary Component + if self.additional_component: + frappe.get_doc("Additional Salary Component", self.additional_component).cancel() + if self.leave_allocation: frappe.db.set_value("Leave Allocation", self.leave_allocation, "total_leaves_encashed", frappe.db.get_value('Leave Allocation', self.leave_allocation, 'total_leaves_encashed') - self.encashable_days)