Skip to content

Commit

Permalink
Merge pull request #1517 from frappe/mergify/bp/version-15-hotfix/pr-…
Browse files Browse the repository at this point in the history
…1367

feat: Bulk Salary Structure Assignment (backport #1367)
  • Loading branch information
ruchamahabal authored Mar 11, 2024
2 parents 4fb352d + 9e991f6 commit a55ac1e
Show file tree
Hide file tree
Showing 14 changed files with 951 additions and 138 deletions.
48 changes: 6 additions & 42 deletions hrms/hr/doctype/leave_control_panel/leave_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@


import frappe
from frappe import _, msgprint
from frappe import _
from frappe.model.document import Document
from frappe.utils import cint, comma_and, flt
from frappe.utils import cint, flt

from erpnext import get_default_company

from hrms.hr.utils import notify_bulk_action_status


class LeaveControlPanel(Document):
def validate_fields(self, employees: list):
Expand Down Expand Up @@ -65,7 +67,7 @@ def create_leave_allocations(self, employees: list) -> dict:
allocation.log_error(f"Leave Allocation failed for employee {employee}")
failure.append(employee)

self.notify_status("Leave Allocation", failure, success)
notify_bulk_action_status("Leave Allocation", failure, success)
return {"failed": failure, "success": success}

def create_leave_policy_assignments(self, employees: list) -> dict:
Expand Down Expand Up @@ -96,7 +98,7 @@ def create_leave_policy_assignments(self, employees: list) -> dict:
assignment.log_error(f"Leave Policy Assignment failed for employee {employee}")
failure.append(employee)

self.notify_status("Leave Policy Assignment", failure, success)
notify_bulk_action_status("Leave Policy Assignment", failure, success)
return {"failed": failure, "success": success}

def get_from_to_date(self):
Expand All @@ -107,44 +109,6 @@ def get_from_to_date(self):
else:
return self.from_date, self.to_date

def notify_status(self, doctype: str, failure: list, success: list) -> None:
frappe.clear_messages()

msg = ""
title = ""
if failure:
msg += _("Failed to create/submit {0} for employees:").format(doctype)
msg += " " + comma_and(failure, False) + "<hr>"
msg += (
_("Check {0} for more details")
.format("<a href='/app/List/Error Log?reference_doctype={0}'>{1}</a>")
.format(doctype, _("Error Log"))
)

if success:
title = _("Partial Success")
msg += "<hr>"
else:
title = _("Creation Failed")
else:
title = _("Success")

if success:
msg += _("Successfully created {0} records for:").format(doctype)
msg += " " + comma_and(success, False)

if failure:
indicator = "orange" if success else "red"
else:
indicator = "green"

msgprint(
msg,
indicator=indicator,
title=title,
is_minimizable=True,
)

@frappe.whitelist()
def get_employees(self, advanced_filters: list) -> list:
from_date, to_date = self.get_from_to_date()
Expand Down
40 changes: 40 additions & 0 deletions hrms/hr/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from frappe.model.document import Document
from frappe.utils import (
add_days,
comma_and,
cstr,
flt,
format_datetime,
Expand Down Expand Up @@ -773,3 +774,42 @@ def get_ec_matching_query(bank_account, company, exact_match, from_date=None, to
AND mode_of_payment in {mode_of_payments}
{filter_by_date}
"""


def notify_bulk_action_status(doctype: str, failure: list, success: list) -> None:
frappe.clear_messages()

msg = ""
title = ""
if failure:
msg += _("Failed to create/submit {0} for employees:").format(doctype)
msg += " " + comma_and(failure, False) + "<hr>"
msg += (
_("Check {0} for more details")
.format("<a href='/app/List/Error Log?reference_doctype={0}'>{1}</a>")
.format(doctype, _("Error Log"))
)

if success:
title = _("Partial Success")
msg += "<hr>"
else:
title = _("Creation Failed")
else:
title = _("Success")

if success:
msg += _("Successfully created {0} for employees:").format(doctype)
msg += " " + comma_and(success, False)

if failure:
indicator = "orange" if success else "red"
else:
indicator = "green"

frappe.msgprint(
msg,
indicator=indicator,
title=title,
is_minimizable=True,
)
Empty file.
Loading

0 comments on commit a55ac1e

Please sign in to comment.