Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
closes: #196 include customer information for time-entries
  • Loading branch information
enriquezrene committed Jul 20, 2020
commit 8ceb682b3ee3334d0c22fb37babf57a56c232ba2
9 changes: 8 additions & 1 deletion time_tracker_api/time_entries/time_entries_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@

from commons.data_access_layer.database import EventContext
from time_tracker_api.activities import activities_model
from time_tracker_api.customers import customers_model

from utils.extend_model import (
add_project_name_to_time_entries,
add_activity_name_to_time_entries,
create_in_condition,
create_custom_query_from_str,
add_user_email_to_time_entries,
add_user_email_to_time_entries, add_customer_name_to_projects,
)
from utils.time import (
datetime_str,
Expand Down Expand Up @@ -219,10 +220,16 @@ def find_all(
time_entries, "activity_id"
)

customer_dao = customers_model.create_dao()
customers = customer_dao.get_all(visible_only=False)

project_dao = projects_model.create_dao()
projects = project_dao.get_all(
custom_sql_conditions=[custom_conditions], visible_only=False
)

add_customer_name_to_projects(projects, customers)

add_project_name_to_time_entries(time_entries, projects)

activity_dao = activities_model.create_dao()
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.word(['development', 'QA']),
),
}
time_entry_response_fields.update(common_fields)

Expand Down
2 changes: 2 additions & 0 deletions utils/extend_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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