Skip to content
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
5 changes: 3 additions & 2 deletions time_tracker_api/time_entries/time_entries_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from time_tracker_api.activities import activities_model

from utils.extend_model import (
add_project_name_to_time_entries,
add_project_info_to_time_entries,
add_activity_name_to_time_entries,
create_in_condition,
create_custom_query_from_str,
Expand Down Expand Up @@ -223,7 +223,8 @@ def find_all(
projects = project_dao.get_all(
custom_sql_conditions=[custom_conditions], visible_only=False
)
add_project_name_to_time_entries(time_entries, projects)

add_project_info_to_time_entries(time_entries, projects)

activity_dao = activities_model.create_dao()
activities = activity_dao.get_all(
Expand Down
14 changes: 14 additions & 0 deletions time_tracker_api/time_entries/time_entries_namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,20 @@
description='Email of the user that owns the time-entry',
example=faker.email(),
),
'customer_id': fields.String(
required=False,
title='Customer ID',
max_length=50,
description='Unique ID for the customer the entry belongs to',
example=faker.uuid4(),
),
'customer_name': fields.String(
required=False,
title='Customer Name',
max_length=50,
description='Name of the customer the entry belongs to',
example=faker.company(),
),
}
time_entry_response_fields.update(common_fields)

Expand Down
6 changes: 4 additions & 2 deletions utils/extend_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ def add_customer_name_to_projects(projects, customers):
setattr(project, 'customer_name', customer.name)


def add_project_name_to_time_entries(time_entries, projects):
def add_project_info_to_time_entries(time_entries, projects):
"""
Add attribute project_name in time-entry model, based on project_id of the
Add project info in time-entry model, based on project_id of the
time_entry
:param (list) time_entries: time_entries retrieved from time-entry repository
:param (list) projects: projects retrieved from project repository
Expand All @@ -30,6 +30,8 @@ def add_project_name_to_time_entries(time_entries, projects):
if time_entry.project_id == project.id:
name = project.name + " (archived)" if project.is_deleted() else project.name
setattr(time_entry, 'project_name', name)
setattr(time_entry, 'customer_id', project.customer_id)
setattr(time_entry, 'customer_name', project.customer_name)


def add_activity_name_to_time_entries(time_entries, activities):
Expand Down