Skip to content

Commit

Permalink
refactor: separate logic for test_appraisal_using_formula from create…
Browse files Browse the repository at this point in the history
…_appraisal
  • Loading branch information
vinyselopal committed Apr 26, 2024
1 parent cc42051 commit bfb2d8c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
18 changes: 11 additions & 7 deletions hrms/hr/doctype/appraisal/test_appraisal.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,26 @@ def test_manual_kra_rating(self):
self.assertEqual(appraisal.final_score, 1.2)

def test_final_score(self):
cycle = create_appraisal_cycle(
designation="Engineer", kra_evaluation_method="Manual Rating", based_on_formula=0
)
cycle = create_appraisal_cycle(designation="Engineer", kra_evaluation_method="Manual Rating")
cycle.create_appraisals()
appraisal = self.setup_appraisal_cycle(cycle)

self.assertEqual(appraisal.final_score, 3.767)
self.assertEqual(appraisal.final_score, 3.77)

def test_final_score_using_formula(self):
cycle = create_appraisal_cycle(
designation="Engineer", kra_evaluation_method="Manual Rating", based_on_formula=1
cycle = create_appraisal_cycle(designation="Engineer", kra_evaluation_method="Manual Rating")
cycle.update(
{
"calculate_final_score_based_on_formula": 1,
"final_score_formula": "(goal_score + self_appraisal_score + average_feedback_score)/3 if self_appraisal_score else (goal_score + self_appraisal_score)/2",
}
)

cycle.save()
cycle.create_appraisals()
appraisal = self.setup_appraisal_cycle(cycle)

self.assertEqual(appraisal.final_score, 3.8)
self.assertEqual(appraisal.final_score, 3.77)

def setup_appraisal_cycle(self, cycle):
appraisal = frappe.db.exists("Appraisal", {"appraisal_cycle": cycle.name, "employee": self.employee1})
Expand Down
8 changes: 0 additions & 8 deletions hrms/hr/doctype/appraisal_cycle/test_appraisal_cycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,15 @@ def create_appraisal_cycle(**args):
if frappe.db.exists("Appraisal Cycle", name):
frappe.delete_doc("Appraisal Cycle", name, force=True)

based_on_formula = args.based_on_formula

appraisal_cycle = frappe.get_doc(
{
"doctype": "Appraisal Cycle",
"cycle_name": name,
"company": args.company or "_Test Appraisal",
"start_date": args.start_date or "2022-01-01",
"end_date": args.end_date or "2022-03-31",
"calculate_final_score_based_on_formula": based_on_formula,
}
)
if based_on_formula:
appraisal_cycle.final_score_formula = (
args.final_score_formula
or "goal_score * 0.2 + self_appraisal_score * 0.2 + average_feedback_score * 0.6"
)

if args.kra_evaluation_method:
appraisal_cycle.kra_evaluation_method = args.kra_evaluation_method
Expand Down

0 comments on commit bfb2d8c

Please sign in to comment.