diff --git a/apps/fyle/models.py b/apps/fyle/models.py index 3b0300f9..dba14c74 100644 --- a/apps/fyle/models.py +++ b/apps/fyle/models.py @@ -185,7 +185,6 @@ def create_expense_objects(expenses: List[Dict], workspace_id, skip_update: bool defaults.update(expense_data_to_append) - print('defaultsdefaultsdefaults',defaults) expense_object, _ = Expense.objects.update_or_create( expense_id=expense['id'], defaults=defaults diff --git a/apps/fyle/tasks.py b/apps/fyle/tasks.py index 789059b3..e6744f9f 100644 --- a/apps/fyle/tasks.py +++ b/apps/fyle/tasks.py @@ -47,9 +47,9 @@ def get_task_log_and_fund_source(workspace_id: int): configuration = Configuration.objects.get(workspace_id=workspace_id) fund_source = [] - if configuration.reimbursable_expenses_object is not None: + if configuration.reimbursable_expenses_object: fund_source.append('PERSONAL') - if configuration.corporate_credit_card_expenses_object is not None: + if configuration.corporate_credit_card_expenses_object: fund_source.append('CCC') return task_log, fund_source, configuration diff --git a/apps/workspaces/apis/import_settings/serializers.py b/apps/workspaces/apis/import_settings/serializers.py index be8a6956..81fd73b2 100644 --- a/apps/workspaces/apis/import_settings/serializers.py +++ b/apps/workspaces/apis/import_settings/serializers.py @@ -111,6 +111,7 @@ def get_workspace_id(self, instance): def update(self, instance, validated_data): configurations = validated_data.pop('configuration') + general_mappings = validated_data.pop('general_mappings') mapping_settings = validated_data.pop('mapping_settings') configurations_instance, _ = Configuration.objects.update_or_create( @@ -123,6 +124,8 @@ def update(self, instance, validated_data): 'import_netsuite_employees': configurations.get('import_netsuite_employees') }, ) + + GeneralMapping.objects.update_or_create(workspace=instance, defaults={'default_tax_code_name': general_mappings.get('default_tax_code').get('name'), 'default_tax_code_id': general_mappings.get('default_tax_code').get('id')}) trigger: ImportSettingsTrigger = ImportSettingsTrigger(configurations=configurations, mapping_settings=mapping_settings, workspace_id=instance.id) diff --git a/apps/workspaces/tasks.py b/apps/workspaces/tasks.py index 83f963cd..c891fea9 100644 --- a/apps/workspaces/tasks.py +++ b/apps/workspaces/tasks.py @@ -104,10 +104,14 @@ def run_sync_schedule(workspace_id): ) configuration = Configuration.objects.get(workspace_id=workspace_id) - fund_source = ['PERSONAL'] + fund_source = [] + + if configuration.reimbursable_expenses_object: + fund_source.append('PERSONAL') if configuration.corporate_credit_card_expenses_object: fund_source.append('CCC') - if configuration.reimbursable_expenses_object: + + if configuration.reimbursable_expenses_object or configuration.corporate_credit_card_expenses_object: create_expense_groups( workspace_id=workspace_id, configuration=configuration, fund_source=fund_source, task_log=task_log ) diff --git a/fyle_netsuite_api/logging_middleware.py b/fyle_netsuite_api/logging_middleware.py index b2944df8..29465253 100644 --- a/fyle_netsuite_api/logging_middleware.py +++ b/fyle_netsuite_api/logging_middleware.py @@ -1,4 +1,5 @@ import logging +import json import traceback import os import random @@ -56,3 +57,21 @@ def filter(self, record): worker_id = getattr(record, 'worker_id', '') record.worker_id = worker_id return True + +class LogPostRequestMiddleware: + def __init__(self, get_response): + self.get_response = get_response + + def __call__(self, request): + if request.method in ['POST', 'PUT'] : + try: + body_unicode = request.body.decode('utf-8') + request_body = json.loads(body_unicode) + logger.info("POST request to %s: %s", request.path, request_body) + except (json.JSONDecodeError, UnicodeDecodeError): + logger.warning("Failed to decode POST request body for %s", request.path) + except Exception as e: + logger.info('Something went wrong when logging post call - %s', e) + + response = self.get_response(request) + return response diff --git a/fyle_netsuite_api/settings.py b/fyle_netsuite_api/settings.py index 5b8043d8..7dece8b7 100644 --- a/fyle_netsuite_api/settings.py +++ b/fyle_netsuite_api/settings.py @@ -66,6 +66,7 @@ MIDDLEWARE = [ 'request_logging.middleware.LoggingMiddleware', + 'fyle_netsuite_api.logging_middleware.LogPostRequestMiddleware', 'fyle_netsuite_api.logging_middleware.ErrorHandlerMiddleware', 'corsheaders.middleware.CorsMiddleware', 'django.middleware.common.CommonMiddleware',