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

Timesheet functionality on Standalone installations #48

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions frappe_slack_connector/api/slash_timesheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ def slash_timesheet():
ignore_permissions=True,
)

if not projects:
raise Exception("No projects found")
if not tasks:
raise Exception("No tasks found")

slack.slack_app.client.views_open(
trigger_id=frappe.form_dict.get("trigger_id"),
view={
Expand Down
63 changes: 46 additions & 17 deletions frappe_slack_connector/db/timesheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,22 @@ def get_employee_working_hours(employee: str = None):
"""
if not employee:
employee = get_employee_from_user()
working_hour, working_frequency = frappe.get_value(
"Employee",
employee,
["custom_working_hours", "custom_work_schedule"],
)

working_hour = None
working_frequency = None
if custom_timesheet_exists():
working_hour, working_frequency = frappe.get_value(
"Employee",
employee,
["custom_working_hours", "custom_work_schedule"],
)
if not working_hour:
working_hour = frappe.db.get_single_value(
"HR Settings", "standard_working_hours"
)
if not working_frequency:
working_frequency = "Per Day"

return {"working_hour": working_hour or 8, "working_frequency": working_frequency}


Expand Down Expand Up @@ -71,26 +76,50 @@ def create_timesheet_detail(
employee: str,
parent: str | None = None,
):
pms_installed = custom_timesheet_exists()

if parent:
timesheet = frappe.get_doc("Timesheet", parent)
else:
timesheet = frappe.get_doc({"doctype": "Timesheet", "employee": employee})

project, custom_is_billable = frappe.get_value(
"Task", task, ["project", "custom_is_billable"]
)
project = None
custom_is_billable = None

fields = ["project"]
if pms_installed:
fields.append("custom_is_billable")

field_values = frappe.get_value("Task", task, fields)
if pms_installed:
project, custom_is_billable = field_values
else:
project = field_values

logs = {
"task": task,
"hours": hours,
"description": description,
"from_time": getdate(date),
"to_time": getdate(date),
"project": project,
}

if pms_installed:
logs.update({"is_billable": custom_is_billable})

timesheet.update({"parent_project": project})
timesheet.append(
"time_logs",
{
"task": task,
"hours": hours,
"description": description,
"from_time": getdate(date),
"to_time": getdate(date),
"project": project,
"is_billable": custom_is_billable,
},
logs,
)
timesheet.save()


def custom_timesheet_exists() -> bool:
"""
Check if the custom fields for timesheet doctype exists
These fields are taken from the frappe_pms app if installed
"""
installed_apps = frappe.get_installed_apps()
return "frappe_pms" in installed_apps