rtCamp / frappe-slack-connector

Frappe app that integrates the Leave Management module with Slack
GNU Affero General Public License v3.0
3 stars 2 forks source link

Add Notifications for Timesheet Submission to Project Manager #23

Open KanchanChauhan opened 1 month ago

KanchanChauhan commented 1 month ago

Notify the Project Manager when an employee submits a timesheet for approval and Send notification on Timesheet submitted for Approval is checked on Slack Settings.

Notification message: "{{employee}} has submitted a timesheet for approval. {{link to employee timesheet on app}}"

ananyo141 commented 2 weeks ago

BLOCKER:

For timesheet approval, the API in frappe_pms loops over the timesheet entries and updates the approval status like this:

#  file: api/timesheet.py
    length = len(timesheets)
    for index, timesheet in enumerate(timesheets):
        doc = frappe.get_doc("Timesheet", timesheet.name)
        doc.custom_approval_status = "Approval Pending"
        doc.save()

So, the slack notification is being triggered multiple times for each timesheet update:

def on_update(doc, method):
    """
    Send a slack message to the timesheet approver when a new timesheet
    is submitted for approval.
    """
    if doc.custom_weekly_approval_status == "Approval Pending":
        frappe.enqueue(
            send_timesheet_approval_notification_bg,
            queue="short",
            doc=doc,
        )

Getting multiples:

Screenshot 2024-10-03 at 3 25 23 PM

KanchanChauhan commented 1 week ago

@ananyo141 We will have to implement this particular Notification in rtCamp since it is very specific to rtCamp as Approval Status is our custom field and only we follow weekly submissions and approvals.