The Pending Amount Not updated while process the Deduction from Salary from Employee Advance

  1. Create a Employee Advance

[Note: To be select the option Repay Unclaimed Amount from Salary]

  1. Process “Deduction from Salary” for the amount to be repaid back through Additinal salary

  2. 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

Checking the code base:
https://github.com/frappe/erpnext/blob/develop/erpnext/payroll/doctype/additional_salary/additional_salary.py

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

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)

The above change should help will publish PULL REQUEST shortly

FYI

This server script solved the problem:

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)