Skip to content

Commit

Permalink
Fix: All the bug fixes listed (#170)
Browse files Browse the repository at this point in the history
* Fix: All the bug fixes listed

* credentials expired issue resolved

* pylint fix

* test fail resolved

* pylint resolved

* comment resolved

* small change

* pylint fix

* fix

* remove intacct name
  • Loading branch information
Ashutosh619-sudo committed Nov 14, 2024
1 parent ca76264 commit 6aebc44
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion apps/accounting_exports/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def create_accounting_export(expense_objects: List[Expense], fund_source: str, w
# Determine the date field based on fund_source
date_field = getattr(export_setting, f"{fund_source_map.get(fund_source)}_expense_date", None).lower()
if date_field and date_field != 'last_spent_at':
if date_field != 'current_date' and accounting_export[date_field]:
if date_field != 'current_date' and date_field in accounting_export and accounting_export[date_field]:
accounting_export[date_field] = accounting_export[date_field].strftime('%Y-%m-%d')
else:
accounting_export[date_field] = datetime.now().strftime('%Y-%m-%d')
Expand Down
1 change: 1 addition & 0 deletions apps/business_central/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def update_accounting_export_summary(workspace_id):
successful_exports = AccountingExport.objects.filter(
~Q(type__in=['FETCHING_REIMBURSABLE_EXPENSES', 'FETCHING_CREDIT_CARD_EXPENSES']),
workspace_id=workspace_id, status='COMPLETE',
updated_at__gte=accounting_export_summary.last_exported_at
).count()

accounting_export_summary.failed_accounting_export_count = failed_exports
Expand Down
4 changes: 2 additions & 2 deletions apps/business_central/exports/base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def get_expense_comment(workspace_id, lineitem: Expense, category: str, advance_
workspace.cluster_domain = cluster_domain
workspace.save()

expense_link = '{0}/app/main/#/enterprise/view_expense/{1}?org_id={2}'.format(
expense_link = '{0}/app/admin/#/enterprise/view_expense/{1}?org_id={2}'.format(
cluster_domain, lineitem.expense_id, org_id
)

Expand Down Expand Up @@ -169,7 +169,7 @@ def get_location_id(accounting_export: AccountingExport, lineitem: Expense):
elif location_setting.source_field == 'COST_CENTER':
source_value = lineitem.cost_center
else:
attribute = ExpenseAttribute.objects.filter(attribute_type=location_setting.source_field).first()
attribute = ExpenseAttribute.objects.filter(attribute_type=location_setting.source_field, workspace_id=accounting_export.workspace_id).first()
source_value = lineitem.custom_properties.get(attribute.display_name, None)

mapping: Mapping = Mapping.objects.filter(
Expand Down
2 changes: 1 addition & 1 deletion apps/mappings/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def async_auto_map_employees(workspace_id: int):
destination_attribute_type=destination_type,
)
except (BusinessCentralCredentials.DoesNotExist, InvalidTokenError):
logger.info('Invalid Token or Sage Intacct Credentials does not exist - %s', workspace_id)
logger.info('Invalid Token or Business Central Credentials does not exist - %s', workspace_id)

except FyleInvalidTokenError:
logger.info('Invalid Token for fyle')
Expand Down
14 changes: 11 additions & 3 deletions apps/workspaces/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from apps.business_central.exports.journal_entry.tasks import ExportJournalEntry
from apps.business_central.exports.purchase_invoice.tasks import ExportPurchaseInvoice
from apps.fyle.queue import queue_import_credit_card_expenses, queue_import_reimbursable_expenses
from apps.workspaces.models import AdvancedSetting, ExportSetting, FyleCredential
from apps.workspaces.models import AdvancedSetting, BusinessCentralCredentials, ExportSetting, FyleCredential

from fyle_integrations_platform_connector import PlatformConnector

Expand All @@ -31,6 +31,14 @@ def run_import_export(workspace_id: int, export_mode = None):
:param workspace_id: Workspace id
"""

business_central_creds = BusinessCentralCredentials.objects.filter(
workspace_id=workspace_id, is_expired=False, refresh_token__isnull=False
).first()

if not business_central_creds:
logger.info('Credentials have expired for workspace_id %s', workspace_id)
return

export_settings = ExportSetting.objects.get(workspace_id=workspace_id)
advance_settings = AdvancedSetting.objects.get(workspace_id=workspace_id)
accounting_summary, _ = AccountingExportSummary.objects.update_or_create(
Expand Down Expand Up @@ -58,7 +66,7 @@ def run_import_export(workspace_id: int, export_mode = None):

if accounting_export.status == 'COMPLETE':
accounting_export_ids = AccountingExport.objects.filter(
fund_source='PERSONAL', exported_at__isnull=True).values_list('id', flat=True)
fund_source='PERSONAL', exported_at__isnull=True, workspace_id=workspace_id).values_list('id', flat=True)

if len(accounting_export_ids):
is_expenses_exported = True
Expand All @@ -75,7 +83,7 @@ def run_import_export(workspace_id: int, export_mode = None):
)
if accounting_export.status == 'COMPLETE':
accounting_export_ids = AccountingExport.objects.filter(
fund_source='CCC', exported_at__isnull=True).values_list('id', flat=True)
fund_source='CCC', exported_at__isnull=True, workspace_id=workspace_id).values_list('id', flat=True)

if len(accounting_export_ids):
is_expenses_exported = True
Expand Down
10 changes: 9 additions & 1 deletion tests/test_workspaces/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
async_create_admin_subcriptions
)
from apps.accounting_exports.models import AccountingExport, AccountingExportSummary
from apps.workspaces.models import FyleCredential, AdvancedSetting, ExportSetting
from apps.workspaces.models import BusinessCentralCredentials, FyleCredential, AdvancedSetting, ExportSetting
from django_q.models import Schedule
from django.conf import settings
from django.urls import reverse
Expand Down Expand Up @@ -64,6 +64,10 @@ def test_run_import_export_with_reimbursable_expense(
'trigger_export'
)

BusinessCentralCredentials.objects.create(
workspace_id=workspace_id, is_expired=False, refresh_token='bsajkdbasjb'
)

run_import_export(workspace_id=workspace_id)

accounting_summary = AccountingExportSummary.objects.get(workspace_id=workspace_id)
Expand Down Expand Up @@ -114,6 +118,10 @@ def test_run_import_export_with_credit_card_expenses(
'trigger_export'
)

BusinessCentralCredentials.objects.create(
workspace_id=workspace_id, is_expired=False, refresh_token='bsajkdbasjb'
)

run_import_export(workspace_id=workspace_id, export_mode='AUTOMATIC')

accounting_summary = AccountingExportSummary.objects.get(workspace_id=workspace_id)
Expand Down

0 comments on commit 6aebc44

Please sign in to comment.