Skip to content

Commit a519fb3

Browse files
committed
fix: fix test
1 parent b93fdf9 commit a519fb3

File tree

3 files changed

+48
-20
lines changed

3 files changed

+48
-20
lines changed

hrms/hr/doctype/employee_advance/test_employee_advance.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
make_bank_entry,
1515
make_return_entry,
1616
)
17-
from hrms.hr.doctype.expense_claim.expense_claim import get_advances
17+
from hrms.hr.doctype.expense_claim.expense_claim import get_advances, get_allocation_amount
1818
from hrms.hr.doctype.expense_claim.test_expense_claim import (
1919
get_payable_account,
2020
make_expense_claim,
@@ -353,7 +353,11 @@ def get_advances_for_claim(claim, advance_name, amount=None):
353353
if amount:
354354
allocated_amount = amount
355355
else:
356-
allocated_amount = flt(entry.paid_amount) - flt(entry.claimed_amount)
356+
allocated_amount = get_allocation_amount(
357+
paid_amount=entry.paid_amount,
358+
claimed_amount=entry.claimed_amount,
359+
return_amount=entry.return_amount,
360+
)
357361

358362
claim.append(
359363
"advances",
@@ -362,7 +366,8 @@ def get_advances_for_claim(claim, advance_name, amount=None):
362366
"posting_date": entry.posting_date,
363367
"advance_account": entry.advance_account,
364368
"advance_paid": entry.paid_amount,
365-
"unclaimed_amount": allocated_amount,
369+
"return_amount": entry.return_amount,
370+
"unclaimed_amount": entry.paid_amount - entry.claimed_amount,
366371
"allocated_amount": allocated_amount,
367372
},
368373
)

hrms/hr/doctype/expense_claim/expense_claim.py

+17-4
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,9 @@ def validate_advances(self):
333333
d.advance_paid = ref_doc.paid_amount
334334
d.unclaimed_amount = flt(ref_doc.paid_amount) - flt(ref_doc.claimed_amount)
335335

336-
if d.allocated_amount and flt(d.allocated_amount) > flt(d.unclaimed_amount):
336+
if d.allocated_amount and flt(d.allocated_amount) > (
337+
flt(d.unclaimed_amount) - flt(d.return_amount)
338+
):
337339
frappe.throw(
338340
_("Row {0}# Allocated amount {1} cannot be greater than unclaimed amount {2}").format(
339341
d.idx, d.allocated_amount, d.unclaimed_amount
@@ -537,7 +539,7 @@ def get_expense_claim(
537539
"advance_paid": flt(paid_amount),
538540
"unclaimed_amount": flt(paid_amount) - flt(claimed_amount),
539541
"allocated_amount": get_allocation_amount(
540-
flt(paid_amount), flt(claimed_amount), flt(return_amount)
542+
paid_amount=(paid_amount), claimed_amount=(claimed_amount), return_amount=(return_amount)
541543
),
542544
"return_amount": flt(return_amount),
543545
},
@@ -598,6 +600,17 @@ def make_expense_claim_for_delivery_trip(source_name, target_doc=None):
598600
return doc
599601

600602

603+
# // amke below fucntion reusable basef on wht is passed, if only unclaimed and return_amt is pased, return unclaimed - returne_amt else paid_amount - (claimed_amount + return_amount)
604+
# @frappe.whitelist()
605+
# def get_allocation_amount(paid_amount, claimed_amount, return_amount):
606+
# return paid_amount - (claimed_amount + return_amount)
607+
608+
601609
@frappe.whitelist()
602-
def get_allocation_amount(paid_amount, claimed_amount, return_amount):
603-
return paid_amount - (claimed_amount + return_amount)
610+
def get_allocation_amount(paid_amount=None, claimed_amount=None, return_amount=None, unclaimed_amount=None):
611+
if unclaimed_amount is not None and return_amount is not None:
612+
return flt(unclaimed_amount) - flt(return_amount)
613+
elif paid_amount is not None and claimed_amount is not None and return_amount is not None:
614+
return flt(paid_amount) - (flt(claimed_amount) + flt(return_amount))
615+
else:
616+
frappe.throw(_("Invalid parameters provided. Please pass the required arguments."))

hrms/hr/doctype/expense_claim/test_expense_claim.py

+23-13
Original file line numberDiff line numberDiff line change
@@ -256,50 +256,60 @@ def test_expense_claim_partially_paid_via_advance(self):
256256
def test_expense_claim_with_deducted_returned_advance(self):
257257
from hrms.hr.doctype.employee_advance.test_employee_advance import (
258258
create_return_through_additional_salary,
259+
get_advances_for_claim,
259260
make_employee_advance,
260261
make_journal_entry_for_advance,
261262
)
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
263264
from hrms.payroll.doctype.salary_component.test_salary_component import create_salary_component
264265
from hrms.payroll.doctype.salary_structure.test_salary_structure import make_salary_structure
265266

267+
# create employee and employee advance
266268
employee_name = make_employee("[email protected]", "_Test Company")
267269
advance = make_employee_advance(employee_name, {"repay_unclaimed_amount_from_salary": 1})
268270
journal_entry = make_journal_entry_for_advance(advance)
269271
journal_entry.submit()
272+
advance.reload()
270273

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")
273276
make_salary_structure(
274277
"Test Additional Salary for Advance Return",
275278
"Monthly",
276279
employee=employee_name,
277280
company="_Test Company",
278281
)
279282

280-
advance.reload()
283+
# create additional salary for advance return
281284
additional_salary = create_return_through_additional_salary(advance)
282285
additional_salary.salary_component = "Advance Salary - Deduction"
283286
additional_salary.payroll_date = nowdate()
284287
additional_salary.amount = 400
285288
additional_salary.insert()
286289
additional_salary.submit()
287-
288290
advance.reload()
291+
289292
self.assertEqual(advance.return_amount, 400)
290293

294+
# create an expense claim
291295
payable_account = get_payable_account("_Test Company")
292296
claim = make_expense_claim(
293297
payable_account, 200, 200, "_Test Company", "Travel Expenses - _TC", do_not_submit=True
294298
)
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+
)
303313

304314
def test_expense_claim_gl_entry(self):
305315
payable_account = get_payable_account(company_name)

0 commit comments

Comments
 (0)