Skip to content

Commit

Permalink
test: payment entry against employee advance
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchamahabal committed Jun 27, 2023
1 parent fc7f08a commit fc45a0b
Showing 1 changed file with 46 additions and 17 deletions.
63 changes: 46 additions & 17 deletions hrms/hr/doctype/employee_advance/test_employee_advance.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import unittest

import frappe
from frappe.tests.utils import FrappeTestCase
from frappe.utils import flt, nowdate

import erpnext
Expand All @@ -24,15 +25,15 @@
from hrms.payroll.doctype.salary_structure.test_salary_structure import make_salary_structure


class TestEmployeeAdvance(unittest.TestCase):
class TestEmployeeAdvance(FrappeTestCase):
def setUp(self):
frappe.db.delete("Employee Advance")

def test_paid_amount_and_status(self):
employee_name = make_employee("_T@employe.advance")
advance = make_employee_advance(employee_name)

journal_entry = make_payment_entry(advance)
journal_entry = make_journal_entry(advance)
journal_entry.submit()

advance.reload()
Expand All @@ -41,22 +42,22 @@ def test_paid_amount_and_status(self):
self.assertEqual(advance.status, "Paid")

# try making over payment
journal_entry1 = make_payment_entry(advance)
journal_entry1 = make_journal_entry(advance)
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()
journal_entry = make_journal_entry(advance)
journal_entry.submit()

advance.reload()

self.assertEqual(advance.paid_amount, 1000)
self.assertEqual(advance.status, "Paid")

pe.cancel()
journal_entry.cancel()
advance.reload()

self.assertEqual(advance.paid_amount, 0)
Expand All @@ -74,8 +75,8 @@ def test_claimed_status(self):
)

advance = make_employee_advance(claim.employee)
pe = make_payment_entry(advance)
pe.submit()
journal_entry = make_journal_entry(advance)
journal_entry.submit()

claim = get_advances_for_claim(claim, advance.name)
claim.save()
Expand Down Expand Up @@ -103,8 +104,8 @@ def test_partly_claimed_and_returned_status(self):
)

advance = make_employee_advance(claim.employee)
pe = make_payment_entry(advance)
pe.submit()
journal_entry = make_journal_entry(advance)
journal_entry.submit()

# PARTLY CLAIMED AND RETURNED status check
# 500 Claimed, 500 Returned
Expand All @@ -113,8 +114,8 @@ def test_partly_claimed_and_returned_status(self):
)

advance = make_employee_advance(claim.employee)
pe = make_payment_entry(advance)
pe.submit()
journal_entry = make_journal_entry(advance)
journal_entry.submit()

claim = get_advances_for_claim(claim, advance.name, amount=500)
claim.save()
Expand Down Expand Up @@ -162,8 +163,8 @@ def test_partly_claimed_and_returned_status(self):
def test_repay_unclaimed_amount_from_salary(self):
employee_name = make_employee("_T@employe.advance")
advance = make_employee_advance(employee_name, {"repay_unclaimed_amount_from_salary": 1})
pe = make_payment_entry(advance)
pe.submit()
journal_entry = make_journal_entry(advance)
journal_entry.submit()

args = {"type": "Deduction"}
create_salary_component("Advance Salary - Deduction", **args)
Expand Down Expand Up @@ -201,11 +202,27 @@ def test_repay_unclaimed_amount_from_salary(self):
self.assertEqual(advance.return_amount, 700)
self.assertEqual(advance.status, "Paid")

def tearDown(self):
frappe.db.rollback()
def test_payment_entry_against_advance(self):
employee_name = make_employee("_T@employee.advance")
advance = make_employee_advance(employee_name)

pe = make_payment_entry(advance, 700)
advance.reload()
self.assertEqual(advance.status, "Unpaid")
self.assertEqual(advance.paid_amount, 700)

pe = make_payment_entry(advance, 300)
advance.reload()
self.assertEqual(advance.status, "Paid")
self.assertEqual(advance.paid_amount, 1000)

pe.cancel()
advance.reload()
self.assertEqual(advance.status, "Unpaid")
self.assertEqual(advance.paid_amount, 700)


def make_payment_entry(advance):
def make_journal_entry(advance):
journal_entry = frappe.get_doc(make_bank_entry("Employee Advance", advance.name))
journal_entry.cheque_no = "123123"
journal_entry.cheque_date = nowdate()
Expand All @@ -214,6 +231,18 @@ def make_payment_entry(advance):
return journal_entry


def make_payment_entry(advance, amount):
from hrms.overrides.employee_payment_entry import get_payment_entry_for_employee

payment_entry = get_payment_entry_for_employee(advance.doctype, advance.name)
payment_entry.reference_no = "1"
payment_entry.reference_date = nowdate()
payment_entry.references[0].allocated_amount = amount
payment_entry.submit()

return payment_entry


def make_employee_advance(employee_name, args=None):
doc = frappe.new_doc("Employee Advance")
doc.employee = employee_name
Expand Down

0 comments on commit fc45a0b

Please sign in to comment.