Skip to content

Commit 4177b4a

Browse files
authored
Chore: prepend Toggl task name to description (#42)
2 parents accb7ab + 8e3e4d5 commit 4177b4a

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

compiler_admin/services/toggl.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import compiler_admin.services.files as files
1313

1414
# input columns needed for conversion
15-
TOGGL_COLUMNS = ["Email", "Project", "Client", "Start date", "Start time", "Duration", "Description"]
15+
TOGGL_COLUMNS = ["Email", "Project", "Task", "Client", "Start date", "Start time", "Duration", "Description"]
1616

1717
# default output CSV columns for Harvest
1818
HARVEST_COLUMNS = ["Date", "Client", "Project", "Task", "Notes", "Hours", "First name", "Last name"]
@@ -71,6 +71,13 @@ def _prepare_input(source_path: str | TextIO, column_renames: dict = {}) -> pd.D
7171
# calculate hours as a decimal from duration timedelta
7272
df["Hours"] = (df["Duration"].dt.total_seconds() / 3600).round(2)
7373

74+
# if there is a Task column, prepend to the Description column and remove
75+
if "Task" in df.columns:
76+
df["Description"] = df.apply(
77+
lambda row: (f"[{row['Task']}] {row['Description']}" if pd.notna(row["Task"]) else row["Description"]), axis=1
78+
)
79+
df.drop(columns=["Task"], inplace=True)
80+
7481
df.sort_values(["Start date", "Start time", "Email"], inplace=True)
7582

7683
if column_renames:

tests/services/test_toggl.py

-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ def test_prepare_input(toggl_file, spy_files):
153153
assert call_args.kwargs["cache_dates"] is True
154154

155155
df_cols = df.columns.to_list()
156-
assert set(df_cols) <= set(TOGGL_COLUMNS) or set(TOGGL_COLUMNS) <= set(df_cols)
157156

158157
assert "First name" in df_cols
159158
assert "Last name" in df_cols

0 commit comments

Comments
 (0)