From 8ceb682b3ee3334d0c22fb37babf57a56c232ba2 Mon Sep 17 00:00:00 2001 From: Rene Enriquez Date: Mon, 20 Jul 2020 17:25:19 -0500 Subject: [PATCH 1/2] closes: #196 include customer information for time-entries --- .../time_entries/time_entries_model.py | 9 ++++++++- .../time_entries/time_entries_namespace.py | 14 ++++++++++++++ utils/extend_model.py | 2 ++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/time_tracker_api/time_entries/time_entries_model.py b/time_tracker_api/time_entries/time_entries_model.py index ff04afa8..02f18828 100644 --- a/time_tracker_api/time_entries/time_entries_model.py +++ b/time_tracker_api/time_entries/time_entries_model.py @@ -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, @@ -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() diff --git a/time_tracker_api/time_entries/time_entries_namespace.py b/time_tracker_api/time_entries/time_entries_namespace.py index c29b2f2e..0eade8bb 100644 --- a/time_tracker_api/time_entries/time_entries_namespace.py +++ b/time_tracker_api/time_entries/time_entries_namespace.py @@ -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) diff --git a/utils/extend_model.py b/utils/extend_model.py index 54d25975..e7065a24 100644 --- a/utils/extend_model.py +++ b/utils/extend_model.py @@ -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): From 2fa0bafc1534a8d80c028468a3d2e0421e9c544e Mon Sep 17 00:00:00 2001 From: roberto Date: Mon, 20 Jul 2020 23:25:24 -0500 Subject: [PATCH 2/2] feat: :ok_hand: #196 --- time_tracker_api/time_entries/time_entries_model.py | 12 +++--------- .../time_entries/time_entries_namespace.py | 2 +- utils/extend_model.py | 4 ++-- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/time_tracker_api/time_entries/time_entries_model.py b/time_tracker_api/time_entries/time_entries_model.py index 02f18828..aa66ff60 100644 --- a/time_tracker_api/time_entries/time_entries_model.py +++ b/time_tracker_api/time_entries/time_entries_model.py @@ -17,14 +17,13 @@ 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_project_info_to_time_entries, add_activity_name_to_time_entries, create_in_condition, create_custom_query_from_str, - add_user_email_to_time_entries, add_customer_name_to_projects, + add_user_email_to_time_entries, ) from utils.time import ( datetime_str, @@ -220,17 +219,12 @@ 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) + add_project_info_to_time_entries(time_entries, projects) activity_dao = activities_model.create_dao() activities = activity_dao.get_all( diff --git a/time_tracker_api/time_entries/time_entries_namespace.py b/time_tracker_api/time_entries/time_entries_namespace.py index 0eade8bb..84c48e6a 100644 --- a/time_tracker_api/time_entries/time_entries_namespace.py +++ b/time_tracker_api/time_entries/time_entries_namespace.py @@ -150,7 +150,7 @@ title='Customer Name', max_length=50, description='Name of the customer the entry belongs to', - example=faker.word(['development', 'QA']), + example=faker.company(), ), } time_entry_response_fields.update(common_fields) diff --git a/utils/extend_model.py b/utils/extend_model.py index e7065a24..6eecedcf 100644 --- a/utils/extend_model.py +++ b/utils/extend_model.py @@ -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