@@ -256,50 +256,60 @@ def test_expense_claim_partially_paid_via_advance(self):
256
256
def test_expense_claim_with_deducted_returned_advance (self ):
257
257
from hrms .hr .doctype .employee_advance .test_employee_advance import (
258
258
create_return_through_additional_salary ,
259
+ get_advances_for_claim ,
259
260
make_employee_advance ,
260
261
make_journal_entry_for_advance ,
261
262
)
262
- from hrms .hr .doctype .expense_claim .expense_claim import get_advances
263
+ from hrms .hr .doctype .expense_claim .expense_claim import get_allocation_amount
263
264
from hrms .payroll .doctype .salary_component .test_salary_component import create_salary_component
264
265
from hrms .payroll .doctype .salary_structure .test_salary_structure import make_salary_structure
265
266
267
+ # create employee and employee advance
266
268
employee_name = make_employee (
"[email protected] " ,
"_Test Company" )
267
269
advance = make_employee_advance (employee_name , {"repay_unclaimed_amount_from_salary" : 1 })
268
270
journal_entry = make_journal_entry_for_advance (advance )
269
271
journal_entry .submit ()
272
+ advance .reload ()
270
273
271
- args = { "type" : "Deduction" }
272
- create_salary_component ("Advance Salary - Deduction" , ** args )
274
+ # set up salary components and structure
275
+ create_salary_component ("Advance Salary - Deduction" , type = "Deduction" )
273
276
make_salary_structure (
274
277
"Test Additional Salary for Advance Return" ,
275
278
"Monthly" ,
276
279
employee = employee_name ,
277
280
company = "_Test Company" ,
278
281
)
279
282
280
- advance . reload ()
283
+ # create additional salary for advance return
281
284
additional_salary = create_return_through_additional_salary (advance )
282
285
additional_salary .salary_component = "Advance Salary - Deduction"
283
286
additional_salary .payroll_date = nowdate ()
284
287
additional_salary .amount = 400
285
288
additional_salary .insert ()
286
289
additional_salary .submit ()
287
-
288
290
advance .reload ()
291
+
289
292
self .assertEqual (advance .return_amount , 400 )
290
293
294
+ # create an expense claim
291
295
payable_account = get_payable_account ("_Test Company" )
292
296
claim = make_expense_claim (
293
297
payable_account , 200 , 200 , "_Test Company" , "Travel Expenses - _TC" , do_not_submit = True
294
298
)
295
- advances = get_advances (claim .employee )
296
- for entry in advances :
297
- if entry .name == advance .name :
298
- self .assertTrue (entry .return_amount , 400 )
299
- self .assertTrue (
300
- entry .allocated_amount ,
301
- advance .paid_amount - (advance .claimed_amount + advance .return_amount ),
302
- )
299
+
300
+ # link advance to the claim
301
+ claim = get_advances_for_claim (claim , advance .name , amount = 200 )
302
+ claim .save ()
303
+ claim .submit ()
304
+
305
+ # verify the allocation amount
306
+ advance = claim .advances [0 ]
307
+ self .assertEqual (
308
+ get_allocation_amount (
309
+ unclaimed_amount = advance .unclaimed_amount , return_amount = advance .return_amount
310
+ ),
311
+ 600 ,
312
+ )
303
313
304
314
def test_expense_claim_gl_entry (self ):
305
315
payable_account = get_payable_account (company_name )
0 commit comments