From 8fb14081b133af950d794a413f59035c57f2cae5 Mon Sep 17 00:00:00 2001 From: ruuushhh <66899387+ruuushhh@users.noreply.github.com> Date: Thu, 10 Oct 2024 13:26:40 +0530 Subject: [PATCH 1/3] fix: expense group creation (#653) Co-authored-by: GitHub Actions --- apps/fyle/tasks.py | 7 +++++-- apps/workspaces/tasks.py | 8 ++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/apps/fyle/tasks.py b/apps/fyle/tasks.py index b60c600d..b957be4d 100644 --- a/apps/fyle/tasks.py +++ b/apps/fyle/tasks.py @@ -45,8 +45,11 @@ def get_task_log_and_fund_source(workspace_id: int): ) configuration = Configuration.objects.get(workspace_id=workspace_id) - fund_source = ['PERSONAL'] - if configuration.corporate_credit_card_expenses_object is not None: + fund_source = [] + + if configuration.reimbursable_expenses_object: + fund_source.append('PERSONAL') + if configuration.corporate_credit_card_expenses_object: fund_source.append('CCC') return task_log, fund_source, configuration 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 ) From cf1a29068b9f05c868b0ec06c7587fd6f7b3440c Mon Sep 17 00:00:00 2001 From: Anish Kr Singh <116036738+anishfyle@users.noreply.github.com> Date: Thu, 10 Oct 2024 14:27:58 +0530 Subject: [PATCH 2/3] fix: default tax code (#654) --- apps/workspaces/apis/import_settings/serializers.py | 3 +++ 1 file changed, 3 insertions(+) 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) From 5e23d08cd1a093adbd3052027e10f65cb7730171 Mon Sep 17 00:00:00 2001 From: Ashutosh singh <55102089+Ashutosh619-sudo@users.noreply.github.com> Date: Fri, 11 Oct 2024 14:50:38 +0530 Subject: [PATCH 3/3] feat: Add middleware to log all post requests. (#651) * feat: Add middleware to log all post requests. * comment resolved --- fyle_netsuite_api/logging_middleware.py | 19 +++++++++++++++++++ fyle_netsuite_api/settings.py | 1 + 2 files changed, 20 insertions(+) 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',