fix: Employee Advance paid amount not updated on PE cancellation (#28572)
* fix: employee advance paid amount not updated on PE cancellation * fix: convert raw sql queries to qb * test: Employee Advance Paid Amount on PE cancellation * chore: disable no copy for sanctioned amount in Expense Claim
This commit is contained in:
parent
c7701ace80
commit
baf41fdc9c
@ -5,6 +5,7 @@
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
from frappe.query_builder.functions import Sum
|
||||||
from frappe.utils import flt, nowdate
|
from frappe.utils import flt, nowdate
|
||||||
|
|
||||||
import erpnext
|
import erpnext
|
||||||
@ -41,24 +42,34 @@ class EmployeeAdvance(Document):
|
|||||||
self.status = "Cancelled"
|
self.status = "Cancelled"
|
||||||
|
|
||||||
def set_total_advance_paid(self):
|
def set_total_advance_paid(self):
|
||||||
paid_amount = frappe.db.sql("""
|
gle = frappe.qb.DocType("GL Entry")
|
||||||
select ifnull(sum(debit), 0) as paid_amount
|
|
||||||
from `tabGL Entry`
|
|
||||||
where against_voucher_type = 'Employee Advance'
|
|
||||||
and against_voucher = %s
|
|
||||||
and party_type = 'Employee'
|
|
||||||
and party = %s
|
|
||||||
""", (self.name, self.employee), as_dict=1)[0].paid_amount
|
|
||||||
|
|
||||||
return_amount = frappe.db.sql("""
|
paid_amount = (
|
||||||
select ifnull(sum(credit), 0) as return_amount
|
frappe.qb.from_(gle)
|
||||||
from `tabGL Entry`
|
.select(Sum(gle.debit).as_("paid_amount"))
|
||||||
where against_voucher_type = 'Employee Advance'
|
.where(
|
||||||
and voucher_type != 'Expense Claim'
|
(gle.against_voucher_type == 'Employee Advance')
|
||||||
and against_voucher = %s
|
& (gle.against_voucher == self.name)
|
||||||
and party_type = 'Employee'
|
& (gle.party_type == 'Employee')
|
||||||
and party = %s
|
& (gle.party == self.employee)
|
||||||
""", (self.name, self.employee), as_dict=1)[0].return_amount
|
& (gle.docstatus == 1)
|
||||||
|
& (gle.is_cancelled == 0)
|
||||||
|
)
|
||||||
|
).run(as_dict=True)[0].paid_amount or 0
|
||||||
|
|
||||||
|
return_amount = (
|
||||||
|
frappe.qb.from_(gle)
|
||||||
|
.select(Sum(gle.credit).as_("return_amount"))
|
||||||
|
.where(
|
||||||
|
(gle.against_voucher_type == 'Employee Advance')
|
||||||
|
& (gle.voucher_type != 'Expense Claim')
|
||||||
|
& (gle.against_voucher == self.name)
|
||||||
|
& (gle.party_type == 'Employee')
|
||||||
|
& (gle.party == self.employee)
|
||||||
|
& (gle.docstatus == 1)
|
||||||
|
& (gle.is_cancelled == 0)
|
||||||
|
)
|
||||||
|
).run(as_dict=True)[0].return_amount or 0
|
||||||
|
|
||||||
if paid_amount != 0:
|
if paid_amount != 0:
|
||||||
paid_amount = flt(paid_amount) / flt(self.exchange_rate)
|
paid_amount = flt(paid_amount) / flt(self.exchange_rate)
|
||||||
|
@ -34,6 +34,24 @@ class TestEmployeeAdvance(unittest.TestCase):
|
|||||||
journal_entry1 = make_payment_entry(advance)
|
journal_entry1 = make_payment_entry(advance)
|
||||||
self.assertRaises(EmployeeAdvanceOverPayment, journal_entry1.submit)
|
self.assertRaises(EmployeeAdvanceOverPayment, journal_entry1.submit)
|
||||||
|
|
||||||
|
def test_paid_amount_on_pe_cancellation(self):
|
||||||
|
employee_name = make_employee("_T@employe.advance")
|
||||||
|
advance = make_employee_advance(employee_name)
|
||||||
|
|
||||||
|
pe = make_payment_entry(advance)
|
||||||
|
pe.submit()
|
||||||
|
|
||||||
|
advance.reload()
|
||||||
|
|
||||||
|
self.assertEqual(advance.paid_amount, 1000)
|
||||||
|
self.assertEqual(advance.status, "Paid")
|
||||||
|
|
||||||
|
pe.cancel()
|
||||||
|
advance.reload()
|
||||||
|
|
||||||
|
self.assertEqual(advance.paid_amount, 0)
|
||||||
|
self.assertEqual(advance.status, "Unpaid")
|
||||||
|
|
||||||
def test_repay_unclaimed_amount_from_salary(self):
|
def test_repay_unclaimed_amount_from_salary(self):
|
||||||
employee_name = make_employee("_T@employe.advance")
|
employee_name = make_employee("_T@employe.advance")
|
||||||
advance = make_employee_advance(employee_name, {"repay_unclaimed_amount_from_salary": 1})
|
advance = make_employee_advance(employee_name, {"repay_unclaimed_amount_from_salary": 1})
|
||||||
|
@ -94,7 +94,6 @@
|
|||||||
"fieldtype": "Currency",
|
"fieldtype": "Currency",
|
||||||
"in_list_view": 1,
|
"in_list_view": 1,
|
||||||
"label": "Sanctioned Amount",
|
"label": "Sanctioned Amount",
|
||||||
"no_copy": 1,
|
|
||||||
"oldfieldname": "sanctioned_amount",
|
"oldfieldname": "sanctioned_amount",
|
||||||
"oldfieldtype": "Currency",
|
"oldfieldtype": "Currency",
|
||||||
"options": "Company:company:default_currency",
|
"options": "Company:company:default_currency",
|
||||||
@ -120,7 +119,7 @@
|
|||||||
"idx": 1,
|
"idx": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2020-09-18 17:26:09.703215",
|
"modified": "2021-11-26 14:23:45.539922",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "HR",
|
"module": "HR",
|
||||||
"name": "Expense Claim Detail",
|
"name": "Expense Claim Detail",
|
||||||
|
Loading…
Reference in New Issue
Block a user