From 1f9e70e4232e58a178f1b3fed9c73c536fdd5207 Mon Sep 17 00:00:00 2001 From: Shwetabh Kumar Date: Wed, 29 Nov 2023 17:17:52 +0530 Subject: [PATCH 1/3] Fix: Replacing all strings with enums --- apps/fyle/enums.py | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 apps/fyle/enums.py diff --git a/apps/fyle/enums.py b/apps/fyle/enums.py new file mode 100644 index 00000000..ad3bb602 --- /dev/null +++ b/apps/fyle/enums.py @@ -0,0 +1,47 @@ +""" +This file contains all the enums used in the Fyle app +""" + +class FundSourceEnum: + """ + Enum for Fund Source + """ + PERSONAL = 'PERSONAL' + CCC = 'CCC' + + +class FyleAttributeEnum: + """ + Enum for Fyle Attributes + """ + CATEGORY = 'CATEGORY' + CATEGORY_DISPLAY = 'Category' + + PROJECT = 'PROJECT' + PROJECT_DISPLAY = 'Project' + + COST_CENTER = 'COST_CENTER' + COST_CENTER_DISPLAY = 'Cost Center' + + CORPORATE_CARD = 'CORPORATE_CARD' + CORPORATE_CARD_DISPLAY = 'Corporate Card' + + TAX_GROUP = 'TAX_GROUP' + TAX_GROUP_DISPLAY = 'Tax Group' + + +class ExpenseStateEnum: + """ + Enum for Expense State + """ + APPROVED = 'APPROVED' + PAYMENT_PROCESSING = 'PAYMENT_PROCESSING' + PAID = 'PAID' + + +class PlatformExpensesEnum: + """ + Enum for Platform Expenses + """ + PERSONAL_CASH_ACCOUNT = 'PERSONAL_CASH_ACCOUNT' + PERSONAL_CORPORATE_CREDIT_CARD_ACCOUNT = 'PERSONAL_CORPORATE_CREDIT_CARD_ACCOUNT' From a67bc1a469479d1d09ae7c17f6b6fd82ae33215a Mon Sep 17 00:00:00 2001 From: Shwetabh Kumar Date: Wed, 29 Nov 2023 17:52:18 +0530 Subject: [PATCH 2/3] Fixing lint issues --- apps/fyle/enums.py | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/fyle/enums.py b/apps/fyle/enums.py index ad3bb602..711dba52 100644 --- a/apps/fyle/enums.py +++ b/apps/fyle/enums.py @@ -2,6 +2,7 @@ This file contains all the enums used in the Fyle app """ + class FundSourceEnum: """ Enum for Fund Source From 1197458984e80065fb5dac6bdae28db5331d4710 Mon Sep 17 00:00:00 2001 From: Shwetabh Kumar Date: Wed, 29 Nov 2023 19:37:42 +0530 Subject: [PATCH 3/3] fix: Replacing enums in Fyle django app (#278) --- apps/fyle/actions.py | 24 +++++++++++++----------- apps/fyle/enums.py | 5 +++++ apps/fyle/models.py | 19 +++++++++++-------- apps/fyle/tasks.py | 32 ++++++++++++++++++-------------- 4 files changed, 47 insertions(+), 33 deletions(-) diff --git a/apps/fyle/actions.py b/apps/fyle/actions.py index ebf3d43d..d1e6dc89 100644 --- a/apps/fyle/actions.py +++ b/apps/fyle/actions.py @@ -4,18 +4,20 @@ from fyle_accounting_mappings.models import ExpenseAttribute from fyle_integrations_platform_connector import PlatformConnector -from apps.fyle.models import ExpenseGroup from apps.workspaces.models import FyleCredential, Workspace, WorkspaceGeneralSettings +from .enums import FyleAttributeEnum, FundSourceEnum +from .models import ExpenseGroup + def get_expense_field(workspace_id): default_attributes = [ - "EMPLOYEE", - "CATEGORY", - "PROJECT", - "COST_CENTER", - "CORPORATE_CARD", - "TAX_GROUP", + FyleAttributeEnum.EMPLOYEE, + FyleAttributeEnum.CATEGORY, + FyleAttributeEnum.PROJECT, + FyleAttributeEnum.COST_CENTER, + FyleAttributeEnum.CORPORATE_CARD, + FyleAttributeEnum.TAX_GROUP ] attributes = ( ExpenseAttribute.objects.filter( @@ -26,8 +28,8 @@ def get_expense_field(workspace_id): ) expense_fields = [ - {"attribute_type": "COST_CENTER", "display_name": "Cost Center"}, - {"attribute_type": "PROJECT", "display_name": "Project"}, + {"attribute_type": FyleAttributeEnum.COST_CENTER, "display_name": FyleAttributeEnum.COST_CENTER_DISPLAY}, + {"attribute_type": FyleAttributeEnum.PROJECT, "display_name": FyleAttributeEnum.PROJECT_DISPLAY} ] for attribute in attributes: @@ -67,9 +69,9 @@ def exportable_expense_group(workspace_id): fund_source = [] if configuration.reimbursable_expenses_object: - fund_source.append("PERSONAL") + fund_source.append(FundSourceEnum.PERSONAL) if configuration.corporate_credit_card_expenses_object: - fund_source.append("CCC") + fund_source.append(FundSourceEnum.CCC) expense_group_ids = ExpenseGroup.objects.filter( workspace_id=workspace_id, exported_at__isnull=True, fund_source__in=fund_source diff --git a/apps/fyle/enums.py b/apps/fyle/enums.py index 711dba52..7b678fe3 100644 --- a/apps/fyle/enums.py +++ b/apps/fyle/enums.py @@ -30,6 +30,9 @@ class FyleAttributeEnum: TAX_GROUP = 'TAX_GROUP' TAX_GROUP_DISPLAY = 'Tax Group' + EMPLOYEE = 'EMPLOYEE' + EMPLOYEE_DISPLAY = 'Employee' + class ExpenseStateEnum: """ @@ -46,3 +49,5 @@ class PlatformExpensesEnum: """ PERSONAL_CASH_ACCOUNT = 'PERSONAL_CASH_ACCOUNT' PERSONAL_CORPORATE_CREDIT_CARD_ACCOUNT = 'PERSONAL_CORPORATE_CREDIT_CARD_ACCOUNT' + REIMBURSEMENT_COMPLETE = 'COMPLETE' + REIMBURSEMENT_PENDING = 'PENDING' diff --git a/apps/fyle/models.py b/apps/fyle/models.py index aaa9cbcd..58ece9aa 100644 --- a/apps/fyle/models.py +++ b/apps/fyle/models.py @@ -15,6 +15,9 @@ from apps.workspaces.models import Workspace +from .enums import FundSourceEnum, PlatformExpensesEnum, ExpenseStateEnum + + logger = logging.getLogger(__name__) logger.level = logging.INFO @@ -57,8 +60,8 @@ } SOURCE_ACCOUNT_MAP = { - "PERSONAL_CASH_ACCOUNT": "PERSONAL", - "PERSONAL_CORPORATE_CREDIT_CARD_ACCOUNT": "CCC", + PlatformExpensesEnum.PERSONAL_CASH_ACCOUNT: FundSourceEnum.PERSONAL, + PlatformExpensesEnum.PERSONAL_CORPORATE_CREDIT_CARD_ACCOUNT: FundSourceEnum.CCC, } @@ -236,17 +239,17 @@ def get_default_ccc_expense_group_fields(): def get_default_expense_state(): - return "PAYMENT_PROCESSING" + return ExpenseStateEnum.PAYMENT_PROCESSING def get_default_ccc_expense_state(): - return "PAID" + return ExpenseStateEnum.PAID CCC_EXPENSE_STATE = ( - ("APPROVED", "APPROVED"), - ("PAID", "PAID"), - ("PAYMENT_PROCESSING", "PAYMENT_PROCESSING"), + (ExpenseStateEnum.APPROVED, ExpenseStateEnum.APPROVED), + (ExpenseStateEnum.PAYMENT_PROCESSING, ExpenseStateEnum.PAYMENT_PROCESSING), + (ExpenseStateEnum.PAID, ExpenseStateEnum.PAID) ) @@ -597,7 +600,7 @@ def create_or_update_reimbursement_objects( for reimbursement in reimbursements: reimbursement["state"] = ( - "COMPLETE" if reimbursement["is_paid"] else "PENDING" + PlatformExpensesEnum.REIMBURSEMENT_COMPLETE if reimbursement["is_paid"] else PlatformExpensesEnum.REIMBURSEMENT_PENDING ) if reimbursement["id"] not in existing_reimbursement_ids: attributes_to_be_created.append( diff --git a/apps/fyle/tasks.py b/apps/fyle/tasks.py index d3fc779e..95d04afd 100644 --- a/apps/fyle/tasks.py +++ b/apps/fyle/tasks.py @@ -7,16 +7,20 @@ from fyle.platform.exceptions import InvalidTokenError as FyleInvalidTokenError from fyle_integrations_platform_connector import PlatformConnector -from apps.fyle.models import Expense, ExpenseGroup, ExpenseGroupSettings from apps.tasks.models import TaskLog from apps.workspaces.models import FyleCredential, Workspace, WorkspaceGeneralSettings +from .models import Expense, ExpenseGroup, ExpenseGroupSettings +from .enums import FundSourceEnum, PlatformExpensesEnum, ExpenseStateEnum + + logger = logging.getLogger(__name__) logger.level = logging.INFO + SOURCE_ACCOUNT_MAP = { - "PERSONAL": "PERSONAL_CASH_ACCOUNT", - "CCC": "PERSONAL_CORPORATE_CREDIT_CARD_ACCOUNT", + FundSourceEnum.PERSONAL: PlatformExpensesEnum.PERSONAL_CASH_ACCOUNT, + FundSourceEnum.CCC: PlatformExpensesEnum.PERSONAL_CORPORATE_CREDIT_CARD_ACCOUNT } @@ -31,9 +35,9 @@ def get_task_log_and_fund_source(workspace_id: int): fund_source = [] if general_settings.reimbursable_expenses_object: - fund_source.append("PERSONAL") + fund_source.append(FundSourceEnum.PERSONAL) if general_settings.corporate_credit_card_expenses_object is not None: - fund_source.append("CCC") + fund_source.append(FundSourceEnum.CCC) return task_log, fund_source @@ -77,18 +81,18 @@ def async_create_expense_groups( expenses = [] reimbursable_expenses_count = 0 - if "PERSONAL" in fund_source: + if FundSourceEnum.PERSONAL in fund_source: expenses.extend( platform.expenses.get( - source_account_type=["PERSONAL_CASH_ACCOUNT"], + source_account_type=[SOURCE_ACCOUNT_MAP[FundSourceEnum.PERSONAL]], state=expense_group_settings.reimbursable_expense_state, settled_at=last_synced_at if expense_group_settings.reimbursable_expense_state - == "PAYMENT_PROCESSING" + == ExpenseStateEnum.PAYMENT_PROCESSING else None, filter_credit_expenses=True, last_paid_at=last_synced_at - if expense_group_settings.reimbursable_expense_state == "PAID" + if expense_group_settings.reimbursable_expense_state == ExpenseStateEnum.PAID else None, ) ) @@ -97,21 +101,21 @@ def async_create_expense_groups( workspace.last_synced_at = datetime.now() reimbursable_expenses_count += len(expenses) - if "CCC" in fund_source: + if FundSourceEnum.CCC in fund_source: expenses.extend( platform.expenses.get( - source_account_type=["PERSONAL_CORPORATE_CREDIT_CARD_ACCOUNT"], + source_account_type=[SOURCE_ACCOUNT_MAP[FundSourceEnum.CCC]], state=expense_group_settings.ccc_expense_state, settled_at=ccc_last_synced_at if expense_group_settings.ccc_expense_state - == "PAYMENT_PROCESSING" + == ExpenseStateEnum.PAYMENT_PROCESSING else None, approved_at=ccc_last_synced_at - if expense_group_settings.ccc_expense_state == "APPROVED" + if expense_group_settings.ccc_expense_state == ExpenseStateEnum.APPROVED else None, filter_credit_expenses=filter_credit_expenses, last_paid_at=ccc_last_synced_at - if expense_group_settings.ccc_expense_state == "PAID" + if expense_group_settings.ccc_expense_state == ExpenseStateEnum.PAID else None, ) )