Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run Slack Sync weekly, Skip timesheet notification if taken leave on both halves #70

Merged
merged 3 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions frappe_slack_connector/api/sync_slack_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ def sync_slack_data():
Enqueues the background job to sync
"""
frappe.msgprint(_("Syncing Slack data..."))
frappe.enqueue(sync_slack_job, queue="long")
frappe.enqueue(sync_slack_job, queue="long", notify=True)


def sync_slack_job():
def sync_slack_job(notify: bool = False):
"""
Background job to sync the Slack data with the User Meta
"""
Expand All @@ -38,7 +38,8 @@ def sync_slack_job():
except Exception as e:
users_not_found.append((email, str(e)))

frappe.msgprint(_("Slack data synced successfully"), realtime=True, indicator="green")
if notify:
frappe.msgprint(_("Slack data synced successfully"), realtime=True, indicator="green")

# Check and display employees in ERPNext but not in Slack
employees = frappe.get_all(
Expand All @@ -53,12 +54,13 @@ def sync_slack_job():
unset_employees.append(employee.employee_name)

if users_not_found:
frappe.msgprint(
f"Users not found in ERPNext: {', '.join(user[0] for user in users_not_found)}",
title="Warning",
indicator="orange",
realtime=True,
)
if notify:
frappe.msgprint(
f"Users not found in ERPNext: {', '.join(user[0] for user in users_not_found)}",
title="Warning",
indicator="orange",
realtime=True,
)
generate_error_log(
title="Users not found in ERPNext",
message="\n".join(user[1] for user in users_not_found),
Expand All @@ -68,14 +70,14 @@ def sync_slack_job():
generate_error_log(
title="Employees not found in Slack",
message=f"Users not found in Slack: {', '.join(unset_employees)}",
realtime=True,
msgprint=True,
msgprint=notify,
realtime=notify,
)

except Exception as e:
generate_error_log(
title="Error syncing Slack data",
exception=e,
msgprint=True,
realtime=True,
msgprint=notify,
realtime=notify,
)
4 changes: 3 additions & 1 deletion frappe_slack_connector/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@
"hourly": [
"frappe_slack_connector.tasks.send_daily_reminder.send_reminder",
],
# "weekly": ["frappe_slack_connector.tasks.weekly"],
"weekly": [
"frappe_slack_connector.api.sync_slack_settings.sync_slack_job",
],
# "monthly": ["frappe_slack_connector.tasks.monthly"],
}

Expand Down
11 changes: 7 additions & 4 deletions frappe_slack_connector/tasks/send_daily_reminder.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,23 @@ def send_slack_notification(reminder_template: str, allowed_departments: list):

# check if the employee has taken a half-day
# and set the daily norm accordingly
is_half_day = frappe.db.exists(
half_days = frappe.get_all(
"Leave Application",
{
"employee": employee.name,
"from_date": ("<=", str(date)),
"to_date": (">=", str(date)),
"half_day_date": str(date),
"half_day": 1,
"status": (
"in",
["Open", "Approved"],
),
},
)
if is_half_day:
# if half day is taken for both the first and second half of the day,
# then consider full day leave
if len(half_days) > 1:
continue
elif half_days:
daily_norm = daily_norm / 2

hour = get_reported_time_by_employee(employee.name, date)
Expand Down