Skip to content

Commit 8ceb682

Browse files
committed
closes: #196 include customer information for time-entries
1 parent 93649c1 commit 8ceb682

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

time_tracker_api/time_entries/time_entries_model.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717

1818
from commons.data_access_layer.database import EventContext
1919
from time_tracker_api.activities import activities_model
20+
from time_tracker_api.customers import customers_model
2021

2122
from utils.extend_model import (
2223
add_project_name_to_time_entries,
2324
add_activity_name_to_time_entries,
2425
create_in_condition,
2526
create_custom_query_from_str,
26-
add_user_email_to_time_entries,
27+
add_user_email_to_time_entries, add_customer_name_to_projects,
2728
)
2829
from utils.time import (
2930
datetime_str,
@@ -219,10 +220,16 @@ def find_all(
219220
time_entries, "activity_id"
220221
)
221222

223+
customer_dao = customers_model.create_dao()
224+
customers = customer_dao.get_all(visible_only=False)
225+
222226
project_dao = projects_model.create_dao()
223227
projects = project_dao.get_all(
224228
custom_sql_conditions=[custom_conditions], visible_only=False
225229
)
230+
231+
add_customer_name_to_projects(projects, customers)
232+
226233
add_project_name_to_time_entries(time_entries, projects)
227234

228235
activity_dao = activities_model.create_dao()

time_tracker_api/time_entries/time_entries_namespace.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,20 @@
138138
description='Email of the user that owns the time-entry',
139139
example=faker.email(),
140140
),
141+
'customer_id': fields.String(
142+
required=False,
143+
title='Customer ID',
144+
max_length=50,
145+
description='Unique ID for the customer the entry belongs to',
146+
example=faker.uuid4(),
147+
),
148+
'customer_name': fields.String(
149+
required=False,
150+
title='Customer Name',
151+
max_length=50,
152+
description='Name of the customer the entry belongs to',
153+
example=faker.word(['development', 'QA']),
154+
),
141155
}
142156
time_entry_response_fields.update(common_fields)
143157

utils/extend_model.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ def add_project_name_to_time_entries(time_entries, projects):
3030
if time_entry.project_id == project.id:
3131
name = project.name + " (archived)" if project.is_deleted() else project.name
3232
setattr(time_entry, 'project_name', name)
33+
setattr(time_entry, 'customer_id', project.customer_id)
34+
setattr(time_entry, 'customer_name', project.customer_name)
3335

3436

3537
def add_activity_name_to_time_entries(time_entries, activities):

0 commit comments

Comments
 (0)