@ -4,6 +4,7 @@
from __future__ import unicode_literals
import unittest
from datetime import date
import frappe
from frappe . utils import add_days , getdate
@ -15,7 +16,12 @@ class TestEmployeeTransfer(unittest.TestCase):
def setUp ( self ) :
make_employee ( " employee2@transfers.com " )
make_employee ( " employee3@transfers.com " )
frappe . db . sql ( """ delete from `tabEmployee Transfer` """ )
create_company ( )
create_employee ( )
create_employee_transfer ( )
def tearDown ( self ) :
frappe . db . rollback ( )
def test_submit_before_transfer_date ( self ) :
transfer_obj = frappe . get_doc ( {
@ -57,3 +63,77 @@ class TestEmployeeTransfer(unittest.TestCase):
self . assertTrue ( transfer . new_employee_id )
self . assertEqual ( frappe . get_value ( " Employee " , transfer . new_employee_id , " status " ) , " Active " )
self . assertEqual ( frappe . get_value ( " Employee " , transfer . employee , " status " ) , " Left " )
def test_employee_history ( self ) :
name = frappe . get_value ( " Employee " , { " first_name " : " John " , " company " : " Test Company " } , " name " )
doc = frappe . get_doc ( " Employee " , name )
count = 0
department = [ " Accounts - TC " , " Management - TC " ]
designation = [ " Accountant " , " Manager " ]
dt = [ getdate ( " 01-10-2021 " ) , date . today ( ) ]
for data in doc . internal_work_history :
self . assertEqual ( data . department , department [ count ] )
self . assertEqual ( data . designation , designation [ count ] )
self . assertEqual ( data . from_date , dt [ count ] )
count = count + 1
data = frappe . db . get_list ( " Employee Transfer " , filters = { " employee " : name } , fields = [ " * " ] )
doc = frappe . get_doc ( " Employee Transfer " , data [ 0 ] [ " name " ] )
doc . cancel ( )
employee_doc = frappe . get_doc ( " Employee " , name )
for data in employee_doc . internal_work_history :
self . assertEqual ( data . designation , designation [ 0 ] )
self . assertEqual ( data . department , department [ 0 ] )
self . assertEqual ( data . from_date , dt [ 0 ] )
def create_employee ( ) :
doc = frappe . get_doc ( {
" doctype " : " Employee " ,
" first_name " : " John " ,
" company " : " Test Company " ,
" gender " : " Male " ,
" date_of_birth " : getdate ( " 30-09-1980 " ) ,
" date_of_joining " : getdate ( " 01-10-2021 " ) ,
" department " : " Accounts - TC " ,
" designation " : " Accountant "
} )
doc . save ( )
def create_company ( ) :
exists = frappe . db . exists ( " Company " , " Test Company " )
if not exists :
doc = frappe . get_doc ( {
" doctype " : " Company " ,
" company_name " : " Test Company " ,
" default_currency " : " INR " ,
" country " : " India "
} )
doc . save ( )
def create_employee_transfer ( ) :
doc = frappe . get_doc ( {
" doctype " : " Employee Transfer " ,
" employee " : frappe . get_value ( " Employee " , { " first_name " : " John " , " company " : " Test Company " } , " name " ) ,
" transfer_date " : date . today ( ) ,
" transfer_details " : [
{
" property " : " Designation " ,
" current " : " Accountant " ,
" new " : " Manager " ,
" fieldname " : " designation "
} ,
{
" property " : " Department " ,
" current " : " Accounts - TC " ,
" new " : " Management - TC " ,
" fieldname " : " department "
}
]
} )
doc . save ( )
doc . submit ( )