mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-08 15:42:52 +00:00
test: employee property update via Employee Promotion
This commit is contained in:
@@ -4,21 +4,22 @@
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
|
from frappe.tests.utils import FrappeTestCase
|
||||||
from frappe.utils import add_days, getdate
|
from frappe.utils import add_days, getdate
|
||||||
|
|
||||||
from erpnext.payroll.doctype.salary_structure.test_salary_structure import make_employee
|
from erpnext.payroll.doctype.salary_structure.test_salary_structure import make_employee
|
||||||
|
|
||||||
|
|
||||||
class TestEmployeePromotion(unittest.TestCase):
|
class TestEmployeePromotion(FrappeTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.employee = make_employee("employee@promotions.com")
|
frappe.db.delete("Employee Promotion")
|
||||||
frappe.db.sql("""delete from `tabEmployee Promotion`""")
|
|
||||||
|
|
||||||
def test_submit_before_promotion_date(self):
|
def test_submit_before_promotion_date(self):
|
||||||
promotion_obj = frappe.get_doc(
|
employee = make_employee("employee@promotions.com")
|
||||||
|
promotion = frappe.get_doc(
|
||||||
{
|
{
|
||||||
"doctype": "Employee Promotion",
|
"doctype": "Employee Promotion",
|
||||||
"employee": self.employee,
|
"employee": employee,
|
||||||
"promotion_details": [
|
"promotion_details": [
|
||||||
{
|
{
|
||||||
"property": "Designation",
|
"property": "Designation",
|
||||||
@@ -29,10 +30,63 @@ class TestEmployeePromotion(unittest.TestCase):
|
|||||||
],
|
],
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
promotion_obj.promotion_date = add_days(getdate(), 1)
|
promotion.promotion_date = add_days(getdate(), 1)
|
||||||
promotion_obj.save()
|
self.assertRaises(frappe.DocstatusTransitionError, promotion.submit)
|
||||||
self.assertRaises(frappe.DocstatusTransitionError, promotion_obj.submit)
|
|
||||||
promotion = frappe.get_doc("Employee Promotion", promotion_obj.name)
|
|
||||||
promotion.promotion_date = getdate()
|
promotion.promotion_date = getdate()
|
||||||
promotion.submit()
|
promotion.submit()
|
||||||
self.assertEqual(promotion.docstatus, 1)
|
self.assertEqual(promotion.docstatus, 1)
|
||||||
|
|
||||||
|
def test_employee_history(self):
|
||||||
|
for grade in ["L1", "L2"]:
|
||||||
|
frappe.get_doc({"doctype": "Employee Grade", "__newname": grade}).insert()
|
||||||
|
|
||||||
|
employee = make_employee(
|
||||||
|
"test_employee_promotion@example.com",
|
||||||
|
company="Test Company",
|
||||||
|
date_of_birth=getdate("30-09-1980"),
|
||||||
|
date_of_joining=getdate("01-10-2021"),
|
||||||
|
designation="Software Developer",
|
||||||
|
grade="L1",
|
||||||
|
salary_currency="INR",
|
||||||
|
annual_ctc="500000",
|
||||||
|
)
|
||||||
|
|
||||||
|
promotion = frappe.get_doc(
|
||||||
|
{
|
||||||
|
"doctype": "Employee Promotion",
|
||||||
|
"employee": employee,
|
||||||
|
"promotion_date": getdate(),
|
||||||
|
"revised_annual_ctc": "1000000",
|
||||||
|
"promotion_details": [
|
||||||
|
{
|
||||||
|
"property": "Designation",
|
||||||
|
"current": "Software Developer",
|
||||||
|
"new": "Project Manager",
|
||||||
|
"fieldname": "designation",
|
||||||
|
},
|
||||||
|
{"property": "Grade", "current": "L1", "new": "L2", "fieldname": "grade"},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
).submit()
|
||||||
|
|
||||||
|
# employee fields updated
|
||||||
|
employee = frappe.get_doc("Employee", employee)
|
||||||
|
self.assertEqual(employee.grade, "L2")
|
||||||
|
self.assertEqual(employee.designation, "Project Manager")
|
||||||
|
self.assertEqual(employee.annual_ctc, 1000000)
|
||||||
|
|
||||||
|
# internal work history updated
|
||||||
|
self.assertEqual(employee.internal_work_history[0].designation, "Software Developer")
|
||||||
|
self.assertEqual(employee.internal_work_history[0].from_date, getdate("01-10-2021"))
|
||||||
|
|
||||||
|
self.assertEqual(employee.internal_work_history[1].designation, "Project Manager")
|
||||||
|
self.assertEqual(employee.internal_work_history[1].from_date, getdate())
|
||||||
|
|
||||||
|
promotion.cancel()
|
||||||
|
employee.reload()
|
||||||
|
|
||||||
|
# internal work history updated on cancellation
|
||||||
|
self.assertEqual(len(employee.internal_work_history), 1)
|
||||||
|
self.assertEqual(employee.internal_work_history[0].designation, "Software Developer")
|
||||||
|
self.assertEqual(employee.internal_work_history[0].from_date, getdate("01-10-2021"))
|
||||||
|
|||||||
Reference in New Issue
Block a user