Skip to content

Commit

Permalink
minor bug fixes and all
Browse files Browse the repository at this point in the history
  • Loading branch information
NileshPant1999 committed Nov 16, 2023
1 parent 6ce3a18 commit e0ef404
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 23 deletions.
4 changes: 1 addition & 3 deletions apps/accounting_exports/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,13 @@ def _group_expenses(expenses: List[Expense], export_setting: ExportSetting, fund
group_by_field = fund_source_data.get('group_by')
date_field = fund_source_data.get('date_field')

default_fields.extend([group_by_field, fund_source])
default_fields.extend(group_by_field)

if date_field:
default_fields.append(date_field)

# Extract expense IDs from the provided expenses
expense_ids = [expense.id for expense in expenses]

# Retrieve expenses from the database
expenses = Expense.objects.filter(id__in=expense_ids).all()

Expand Down Expand Up @@ -109,7 +108,6 @@ def create_accounting_export(expense_objects: List[Expense], fund_source: str, w
"""
Group expenses by report_id and fund_source, format date fields, and create AccountingExport objects.
"""

# Retrieve the ExportSetting for the workspace
export_setting = ExportSetting.objects.get(workspace_id=workspace_id)

Expand Down
22 changes: 11 additions & 11 deletions apps/fyle/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except FyleCredential.DoesNotExist:
logger.info('Fyle credentials not found %s', args[1]) # args[1] is workspace_id
args[2].detail = {'message': 'Fyle credentials do not exist in workspace'}
args[2].status = 'FAILED'
args[2].save()
logger.info('Fyle credentials not found %s', args[0]) # args[1] is workspace_id
args[1].detail = {'message': 'Fyle credentials do not exist in workspace'}
args[1].status = 'FAILED'
args[1].save()

except NoPrivilegeError:
logger.info('Invalid Fyle Credentials / Admin is disabled')
args[2].detail = {'message': 'Invalid Fyle Credentials / Admin is disabled'}
args[2].status = 'FAILED'
args[2].save()
args[1].detail = {'message': 'Invalid Fyle Credentials / Admin is disabled'}
args[1].status = 'FAILED'
args[1].save()

except Exception:
error = traceback.format_exc()
args[2].detail = {'error': error}
args[2].status = 'FATAL'
args[2].save()
logger.exception('Something unexpected happened workspace_id: %s %s', args[1], args[2].detail)
args[1].detail = {'error': error}
args[1].status = 'FATAL'
args[1].save()
logger.exception('Something unexpected happened workspace_id: %s %s', args[0], args[1].detail)

return wrapper
3 changes: 1 addition & 2 deletions apps/fyle/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ def create_expense_objects(expenses: List[Dict], workspace_id: int):

# Create an empty list to store expense objects
expense_objects = []

for expense in expenses:
# Iterate through custom property fields and handle empty values
for custom_property_field in expense['custom_properties']:
Expand Down Expand Up @@ -171,7 +170,7 @@ def create_expense_objects(expenses: List[Dict], workspace_id: int):
)

# Check if an AccountingExport related to the expense object already exists
if not Expense.objects.filter(accountingexport__isnull=False).distinct():
if not expense_object.accountingexport_set.exists():
expense_objects.append(expense_object)

return expense_objects
Expand Down
10 changes: 5 additions & 5 deletions apps/fyle/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ def import_expenses(workspace_id, accounting_export: AccountingExport, source_ac
}
export_settings = ExportSetting.objects.get(workspace_id=workspace_id)
workspace = Workspace.objects.get(pk=workspace_id)
last_synced_at = getattr(workspace, f"{fund_source_key.lower()}_last_synced_at", None)
last_synced_at = getattr(workspace, f"{fund_source_map.get(fund_source_key)}_last_synced_at", None)
fyle_credentials = FyleCredential.objects.get(workspace_id=workspace_id)

platform = PlatformConnector(fyle_credentials)

expenses = platform.expenses.get(
source_account_type=[source_account_type],
state=getattr(export_settings, f"{fund_source_key.lower()}_expense_state"),
state=getattr(export_settings, f"{fund_source_map.get(fund_source_key)}_expense_state"),
settled_at=last_synced_at if getattr(export_settings, f"{fund_source_map.get(fund_source_key)}_expense_state") == 'PAYMENT_PROCESSING' else None,
approved_at=last_synced_at if getattr(export_settings, f"{fund_source_map.get(fund_source_key)}_expense_state") == 'APPROVED' else None,
# approved_at=last_synced_at if getattr(export_settings, f"{fund_source_map.get(fund_source_key)}_expense_state") == 'APPROVED' else None,
filter_credit_expenses=(fund_source_key == 'CCC'),
last_paid_at=last_synced_at if getattr(export_settings, f"{fund_source_key.lower()}_expense_state") == 'PAID' else None
last_paid_at=last_synced_at if getattr(export_settings, f"{fund_source_map.get(fund_source_key)}_expense_state") == 'PAID' else None
)

if expenses:
Expand All @@ -59,7 +59,7 @@ def import_expenses(workspace_id, accounting_export: AccountingExport, source_ac

with transaction.atomic():
expenses_object = Expense.create_expense_objects(expenses, workspace_id)
AccountingExport.create_accounting_export_report_id(
AccountingExport.create_accounting_export(
expenses_object,
fund_source=fund_source_key,
workspace_id=workspace_id
Expand Down
4 changes: 2 additions & 2 deletions apps/workspaces/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class Workspace(models.Model):
name = StringNotNullField(help_text='Name of the workspace')
user = models.ManyToManyField(User, help_text='Reference to users table')
org_id = models.CharField(max_length=255, help_text='org id', unique=True)
last_synced_at = CustomDateTimeField(help_text='Datetime when expenses were pulled last')
ccc_last_synced_at = CustomDateTimeField(help_text='Datetime when ccc expenses were pulled last')
reimbursable_last_synced_at = CustomDateTimeField(help_text='Datetime when expenses were pulled last')
credit_card_last_synced_at = CustomDateTimeField(help_text='Datetime when ccc expenses were pulled last')
source_synced_at = CustomDateTimeField(help_text='Datetime when source dimensions were pulled')
destination_synced_at = CustomDateTimeField(help_text='Datetime when destination dimensions were pulled')
onboarding_state = StringOptionsField(
Expand Down

0 comments on commit e0ef404

Please sign in to comment.