Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwin1111 committed Oct 11, 2024
2 parents f6cddc4 + 5e23d08 commit 885678a
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 5 deletions.
1 change: 0 additions & 1 deletion apps/fyle/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions apps/fyle/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions apps/workspaces/apis/import_settings/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)

Expand Down
8 changes: 6 additions & 2 deletions apps/workspaces/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
19 changes: 19 additions & 0 deletions fyle_netsuite_api/logging_middleware.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import json
import traceback
import os
import random
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions fyle_netsuite_api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 885678a

Please sign in to comment.