2
2
# See license.txt
3
3
4
4
import frappe
5
- from frappe .tests .utils import FrappeTestCase
5
+ from frappe .tests .utils import FrappeTestCase , change_settings
6
6
from frappe .utils import flt , nowdate
7
7
8
8
import erpnext
26
26
class TestEmployeeAdvance (FrappeTestCase ):
27
27
def setUp (self ):
28
28
frappe .db .delete ("Employee Advance" )
29
+ self .update_company_in_fiscal_year ()
29
30
30
31
def test_paid_amount_and_status (self ):
31
- employee_name = make_employee ("_T@employe .advance" )
32
+ employee_name = make_employee ("_T@employee .advance" , "_Test Company " )
32
33
advance = make_employee_advance (employee_name )
33
34
34
35
journal_entry = make_journal_entry_for_advance (advance )
@@ -44,7 +45,7 @@ def test_paid_amount_and_status(self):
44
45
self .assertRaises (EmployeeAdvanceOverPayment , journal_entry1 .submit )
45
46
46
47
def test_paid_amount_on_pe_cancellation (self ):
47
- employee_name = make_employee ("_T@employe .advance" )
48
+ employee_name = make_employee ("_T@employee .advance" , "_Test Company " )
48
49
advance = make_employee_advance (employee_name )
49
50
50
51
journal_entry = make_journal_entry_for_advance (advance )
@@ -159,14 +160,19 @@ def test_partly_claimed_and_returned_status(self):
159
160
self .assertTrue (advance .name in advances )
160
161
161
162
def test_repay_unclaimed_amount_from_salary (self ):
162
- employee_name = make_employee ("_T@employe .advance" )
163
+ employee_name = make_employee ("_T@employee .advance" , "_Test Company " )
163
164
advance = make_employee_advance (employee_name , {"repay_unclaimed_amount_from_salary" : 1 })
164
165
journal_entry = make_journal_entry_for_advance (advance )
165
166
journal_entry .submit ()
166
167
167
168
args = {"type" : "Deduction" }
168
169
create_salary_component ("Advance Salary - Deduction" , ** args )
169
- make_salary_structure ("Test Additional Salary for Advance Return" , "Monthly" , employee = employee_name )
170
+ make_salary_structure (
171
+ "Test Additional Salary for Advance Return" ,
172
+ "Monthly" ,
173
+ employee = employee_name ,
174
+ company = "_Test Company" ,
175
+ )
170
176
171
177
# additional salary for 700 first
172
178
advance .reload ()
@@ -199,7 +205,7 @@ def test_repay_unclaimed_amount_from_salary(self):
199
205
self .assertEqual (advance .status , "Paid" )
200
206
201
207
def test_payment_entry_against_advance (self ):
202
- employee_name = make_employee (
"[email protected] " )
208
+ employee_name = make_employee (
"[email protected] " , "_Test Company" )
203
209
advance = make_employee_advance (employee_name )
204
210
205
211
pe = make_payment_entry (advance , 700 )
@@ -218,7 +224,7 @@ def test_payment_entry_against_advance(self):
218
224
self .assertEqual (advance .paid_amount , 700 )
219
225
220
226
def test_precision (self ):
221
- employee_name = make_employee (
"[email protected] " )
227
+ employee_name = make_employee (
"[email protected] " , "_Test Company" )
222
228
advance = make_employee_advance (employee_name )
223
229
journal_entry = make_journal_entry_for_advance (advance )
224
230
journal_entry .submit ()
@@ -257,7 +263,7 @@ def test_precision(self):
257
263
self .assertEqual (advance .status , "Partly Claimed and Returned" )
258
264
259
265
def test_pending_amount (self ):
260
- employee_name = make_employee (
"[email protected] " )
266
+ employee_name = make_employee (
"[email protected] " , "_Test Company" )
261
267
262
268
advance1 = make_employee_advance (employee_name )
263
269
make_payment_entry (advance1 , 500 )
@@ -271,6 +277,33 @@ def test_pending_amount(self):
271
277
# (1000 - 500) + (1000 - 700)
272
278
self .assertEqual (advance3 .pending_amount , 800 )
273
279
280
+ @change_settings ("HR Settings" , {"unlink_payment_on_cancellation_of_employee_advance" : True })
281
+ def test_unlink_payment_entries (self ):
282
+ employee_name = make_employee (
"[email protected] " ,
"_Test Company" )
283
+ self .assertTrue (frappe .db .exists ("Employee" , employee_name ))
284
+
285
+ advance = make_employee_advance (employee_name )
286
+ self .assertTrue (advance )
287
+
288
+ advance_payment = make_payment_entry (advance , 1000 )
289
+ self .assertTrue (advance_payment )
290
+ self .assertEqual (advance_payment .total_allocated_amount , 1000 )
291
+
292
+ advance .reload ()
293
+ advance .cancel ()
294
+ advance_payment .reload ()
295
+ self .assertEqual (advance_payment .unallocated_amount , 1000 )
296
+ self .assertEqual (advance_payment .references , [])
297
+
298
+ def update_company_in_fiscal_year (self ):
299
+ fy_entries = frappe .get_all ("Fiscal Year" )
300
+ for fy_entry in fy_entries :
301
+ fiscal_year = frappe .get_doc ("Fiscal Year" , fy_entry .name )
302
+ company_list = [fy_c .company for fy_c in fiscal_year .companies if fy_c .company ]
303
+ if "_Test Company" not in company_list :
304
+ fiscal_year .append ("companies" , {"company" : "_Test Company" })
305
+ fiscal_year .save ()
306
+
274
307
275
308
def make_journal_entry_for_advance (advance ):
276
309
journal_entry = frappe .get_doc (make_bank_entry ("Employee Advance" , advance .name ))
0 commit comments