test: employee advance status
This commit is contained in:
parent
85be0d22d4
commit
17b1f5f256
@ -233,7 +233,8 @@ def make_return_entry(employee, company, employee_advance_name, return_amount,
|
|||||||
'reference_name': employee_advance_name,
|
'reference_name': employee_advance_name,
|
||||||
'party_type': 'Employee',
|
'party_type': 'Employee',
|
||||||
'party': employee,
|
'party': employee,
|
||||||
'is_advance': 'Yes'
|
'is_advance': 'Yes',
|
||||||
|
'cost_center': erpnext.get_default_cost_center(company)
|
||||||
})
|
})
|
||||||
|
|
||||||
bank_amount = flt(return_amount) if bank_cash_account.account_currency==currency \
|
bank_amount = flt(return_amount) if bank_cash_account.account_currency==currency \
|
||||||
@ -244,7 +245,8 @@ def make_return_entry(employee, company, employee_advance_name, return_amount,
|
|||||||
"debit_in_account_currency": bank_amount,
|
"debit_in_account_currency": bank_amount,
|
||||||
"account_currency": bank_cash_account.account_currency,
|
"account_currency": bank_cash_account.account_currency,
|
||||||
"account_type": bank_cash_account.account_type,
|
"account_type": bank_cash_account.account_type,
|
||||||
"exchange_rate": flt(exchange_rate) if bank_cash_account.account_currency == currency else 1
|
"exchange_rate": flt(exchange_rate) if bank_cash_account.account_currency == currency else 1,
|
||||||
|
"cost_center": erpnext.get_default_cost_center(company)
|
||||||
})
|
})
|
||||||
|
|
||||||
return je.as_dict()
|
return je.as_dict()
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe.utils import nowdate
|
from frappe.utils import flt, nowdate
|
||||||
|
|
||||||
import erpnext
|
import erpnext
|
||||||
from erpnext.hr.doctype.employee.test_employee import make_employee
|
from erpnext.hr.doctype.employee.test_employee import make_employee
|
||||||
@ -12,6 +12,12 @@ from erpnext.hr.doctype.employee_advance.employee_advance import (
|
|||||||
EmployeeAdvanceOverPayment,
|
EmployeeAdvanceOverPayment,
|
||||||
create_return_through_additional_salary,
|
create_return_through_additional_salary,
|
||||||
make_bank_entry,
|
make_bank_entry,
|
||||||
|
make_return_entry,
|
||||||
|
)
|
||||||
|
from erpnext.hr.doctype.expense_claim.expense_claim import get_advances
|
||||||
|
from erpnext.hr.doctype.expense_claim.test_expense_claim import (
|
||||||
|
get_payable_account,
|
||||||
|
make_expense_claim,
|
||||||
)
|
)
|
||||||
from erpnext.payroll.doctype.salary_component.test_salary_component import create_salary_component
|
from erpnext.payroll.doctype.salary_component.test_salary_component import create_salary_component
|
||||||
from erpnext.payroll.doctype.salary_structure.test_salary_structure import make_salary_structure
|
from erpnext.payroll.doctype.salary_structure.test_salary_structure import make_salary_structure
|
||||||
@ -52,9 +58,75 @@ class TestEmployeeAdvance(unittest.TestCase):
|
|||||||
self.assertEqual(advance.paid_amount, 0)
|
self.assertEqual(advance.paid_amount, 0)
|
||||||
self.assertEqual(advance.status, "Unpaid")
|
self.assertEqual(advance.status, "Unpaid")
|
||||||
|
|
||||||
|
def test_claimed_and_returned_status(self):
|
||||||
|
# Claimed Status check, full amount claimed
|
||||||
|
payable_account = get_payable_account("_Test Company")
|
||||||
|
claim = make_expense_claim(payable_account, 1000, 1000, "_Test Company", "Travel Expenses - _TC", do_not_submit=True)
|
||||||
|
|
||||||
|
advance = make_employee_advance(claim.employee)
|
||||||
|
pe = make_payment_entry(advance)
|
||||||
|
pe.submit()
|
||||||
|
|
||||||
|
claim = get_advances_for_claim(claim, advance.name)
|
||||||
|
claim.save()
|
||||||
|
claim.submit()
|
||||||
|
|
||||||
|
advance.reload()
|
||||||
|
self.assertEqual(advance.claimed_amount, 1000)
|
||||||
|
self.assertEqual(advance.status, "Claimed")
|
||||||
|
|
||||||
|
# cancel claim; status should be Paid
|
||||||
|
claim.cancel()
|
||||||
|
advance.reload()
|
||||||
|
self.assertEqual(advance.claimed_amount, 0)
|
||||||
|
self.assertEqual(advance.status, "Paid")
|
||||||
|
|
||||||
|
# Partly Claimed and Returned status check
|
||||||
|
# 500 Claimed, 500 Returned
|
||||||
|
claim = make_expense_claim(payable_account, 500, 500, "_Test Company", "Travel Expenses - _TC", do_not_submit=True)
|
||||||
|
|
||||||
|
advance = make_employee_advance(claim.employee)
|
||||||
|
pe = make_payment_entry(advance)
|
||||||
|
pe.submit()
|
||||||
|
|
||||||
|
claim = get_advances_for_claim(claim, advance.name, amount=500)
|
||||||
|
claim.save()
|
||||||
|
claim.submit()
|
||||||
|
|
||||||
|
advance.reload()
|
||||||
|
self.assertEqual(advance.claimed_amount, 500)
|
||||||
|
self.assertEqual(advance.status, "Paid")
|
||||||
|
|
||||||
|
entry = make_return_entry(
|
||||||
|
employee=advance.employee,
|
||||||
|
company=advance.company,
|
||||||
|
employee_advance_name=advance.name,
|
||||||
|
return_amount=flt(advance.paid_amount - advance.claimed_amount),
|
||||||
|
advance_account=advance.advance_account,
|
||||||
|
mode_of_payment=advance.mode_of_payment,
|
||||||
|
currency=advance.currency,
|
||||||
|
exchange_rate=advance.exchange_rate
|
||||||
|
)
|
||||||
|
|
||||||
|
entry = frappe.get_doc(entry)
|
||||||
|
entry.insert()
|
||||||
|
entry.submit()
|
||||||
|
|
||||||
|
advance.reload()
|
||||||
|
self.assertEqual(advance.return_amount, 500)
|
||||||
|
self.assertEqual(advance.status, "Partly Claimed and Returned")
|
||||||
|
|
||||||
|
# Cancel return entry; status should change to Paid
|
||||||
|
entry.cancel()
|
||||||
|
advance.reload()
|
||||||
|
self.assertEqual(advance.return_amount, 0)
|
||||||
|
self.assertEqual(advance.status, "Paid")
|
||||||
|
|
||||||
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})
|
||||||
|
pe = make_payment_entry(advance)
|
||||||
|
pe.submit()
|
||||||
|
|
||||||
args = {"type": "Deduction"}
|
args = {"type": "Deduction"}
|
||||||
create_salary_component("Advance Salary - Deduction", **args)
|
create_salary_component("Advance Salary - Deduction", **args)
|
||||||
@ -82,11 +154,13 @@ class TestEmployeeAdvance(unittest.TestCase):
|
|||||||
|
|
||||||
advance.reload()
|
advance.reload()
|
||||||
self.assertEqual(advance.return_amount, 1000)
|
self.assertEqual(advance.return_amount, 1000)
|
||||||
|
self.assertEqual(advance.status, "Returned")
|
||||||
|
|
||||||
# update advance return amount on additional salary cancellation
|
# update advance return amount on additional salary cancellation
|
||||||
additional_salary.cancel()
|
additional_salary.cancel()
|
||||||
advance.reload()
|
advance.reload()
|
||||||
self.assertEqual(advance.return_amount, 700)
|
self.assertEqual(advance.return_amount, 700)
|
||||||
|
self.assertEqual(advance.status, "Paid")
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
frappe.db.rollback()
|
frappe.db.rollback()
|
||||||
@ -118,3 +192,24 @@ def make_employee_advance(employee_name, args=None):
|
|||||||
doc.submit()
|
doc.submit()
|
||||||
|
|
||||||
return doc
|
return doc
|
||||||
|
|
||||||
|
|
||||||
|
def get_advances_for_claim(claim, advance_name, amount=None):
|
||||||
|
advances = get_advances(claim.employee, advance_name)
|
||||||
|
|
||||||
|
for entry in advances:
|
||||||
|
if amount:
|
||||||
|
allocated_amount = amount
|
||||||
|
else:
|
||||||
|
allocated_amount = flt(entry.paid_amount) - flt(entry.claimed_amount)
|
||||||
|
|
||||||
|
claim.append("advances", {
|
||||||
|
"employee_advance": entry.name,
|
||||||
|
"posting_date": entry.posting_date,
|
||||||
|
"advance_account": entry.advance_account,
|
||||||
|
"advance_paid": entry.paid_amount,
|
||||||
|
"unclaimed_amount": allocated_amount,
|
||||||
|
"allocated_amount": allocated_amount
|
||||||
|
})
|
||||||
|
|
||||||
|
return claim
|
Loading…
x
Reference in New Issue
Block a user