Skip to content

Commit

Permalink
Merge pull request #3016 from ONE-F-M/186747807
Browse files Browse the repository at this point in the history
CHORE: UPDATE MADE TO PARENT GOAL SHOULD NOT REFLECT ON ALL CHILD GOAL
  • Loading branch information
mymi14s authored Jan 2, 2024
2 parents 4c4fe54 + bda6eee commit 481c465
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
21 changes: 21 additions & 0 deletions one_fm/after_migrate/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,24 @@ def replace_job_opening():
for i in [user_files_path, user_magic_link]:
if not os.path.exists(bench_path+i):
os.mkdir(bench_path+i)


def replace_prompt_message_in_goal():
"""
Replace the prompt message that pop us while changing the KRA of a parent goal
"""
doctype_path = frappe.utils.get_bench_path() + "/apps/hrms/hrms/hr/doctype/goal/"
file_path = os.path.join(doctype_path, "goal.js")

if os.path.exists(file_path):
with open(file_path, 'r') as f:
filedata = f.read()

if not filedata.find("Modifying the KRA in the parent goal will specifically impact those child goals that share the same KRA; any other child goals with different KRAs will remain unaffected.") > 0:
newdata = filedata.replace(
"Changing KRA in this parent goal will align all the child goals to the same KRA, if any.",
"Modifying the KRA in the parent goal will specifically impact those child goals that share the same KRA; any other child goals with different KRAs will remain unaffected."
)

with open(file_path, 'w') as f:
f.write(newdata)
1 change: 1 addition & 0 deletions one_fm/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,7 @@
"one_fm.after_migrate.execute.disable_workflow_emails",
"one_fm.after_migrate.execute.comment_payment_entry_in_hrms",
"one_fm.after_migrate.execute.comment_process_expired_allocation_in_hrms",
"one_fm.after_migrate.execute.replace_prompt_message_in_goal",
]

before_migrate = [
Expand Down
15 changes: 13 additions & 2 deletions one_fm/overrides/goal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
from hrms.hr.doctype.goal.goal import Goal

class GoalOverride(Goal):

def on_update(self):
super(GoalOverride, self).on_update()

def validate_parent_fields(self):
'''
Overriding the super class method here to remove the validation of employee link in the parent
Expand All @@ -22,8 +26,15 @@ def validate_parent_fields(self):
# )
if self.appraisal_cycle != parent_details.appraisal_cycle:
frappe.throw(
_("Goal should belong to the same Appraisal Cycle as its parent goal."), title=_("Not Allowed"),

_("Goal should belong to the same Appraisal Cycle as its parent goal."), title=_("Not Allowed"),
)

def update_kra_in_child_goals(self, doc_before_save):
"""Aligns children's KRA to parent goal's KRA if parent goal's KRA is changed"""
parent_previous_kra = doc_before_save.kra
if parent_previous_kra != self.kra and self.is_group:
Goal = frappe.qb.DocType("Goal")
(frappe.qb.update(Goal).set(Goal.kra, self.kra).where((Goal.parent_goal == self.name) & (Goal.kra == parent_previous_kra))).run()
frappe.msgprint(_("KRA updated for the child goals that share the same KRA as the parent."), alert=True, indicator="green")


0 comments on commit 481c465

Please sign in to comment.