amsrk
November 23, 2021, 8:58am
#1
Create a Employee Advance
[Note: To be select the option Repay Unclaimed Amount from Salary]
Process “Deduction from Salary” for the amount to be repaid back through Additinal salary
Noticed the following:
Returned Amount value is properly updated after the Save and Submit of the Additional Salary
Pending Amount value is not udated after the Save and Submit of the Additional Salary
amsrk
November 23, 2021, 9:00am
#2
Checking the code base:
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
import frappe
from frappe import _, bold
from frappe.model.document import Document
from frappe.utils import comma_and, date_diff, formatdate, getdate
from erpnext.hr.utils import validate_active_employee
class AdditionalSalary(Document):
def on_submit(self):
self.update_return_amount_in_employee_advance()
self.update_employee_referral()
def on_cancel(self):
self.update_return_amount_in_employee_advance()
self.update_employee_referral(cancel=True)
This file has been truncated. show original
def update_return_amount_in_employee_advance(self):
if self.ref_doctype == “Employee Advance” and self.ref_docname:
return_amount = frappe.db.get_value(“Employee Advance”, self.ref_docname, “return_amount”)
if self.docstatus == 2:
return_amount -= self.amount
else:
return_amount += self.amount
frappe.db.set_value("Employee Advance", self.ref_docname, "return_amount", return_amount)
return amount is handled but pending amount not handled
amsrk
November 23, 2021, 9:07am
#3
def update_return_amount_in_employee_advance(self):
if self.ref_doctype == “Employee Advance” and self.ref_docname:
return_amount = frappe.db.get_value(“Employee Advance”, self.ref_docname, “return_amount”)
==> advance_amount = frappe.db.get_value(“Employee Advance”, self.ref_docname, “advance_amount”)
if self.docstatus == 2:
return_amount -= self.amount
else:
return_amount += self.amount
frappe.db.set_value("Employee Advance", self.ref_docname, "return_amount", return_amount)
==>frappe.db.set_value("Employee Advance", self.ref_docname, "pending_amount", (advance_amount - return_amount)
amsrk
November 23, 2021, 9:07am
#4
The above change should help will publish PULL REQUEST shortly
amsrk
November 29, 2021, 8:45am
#6
This server script solved the problem:
amsrk
November 29, 2021, 8:45am
#7
if doc.ref_doctype == “Employee Advance” and doc.ref_docname:
advance_amount = frappe.db.get_value(“Employee Advance”, doc.ref_docname, “advance_amount”)
pending_amount = advance_amount - doc.amount
frappe.db.set_value(“Employee Advance”, doc.ref_docname, “pending_amount”, pending_amount)