From 24614c4e987fc64b52d13ae2ddd65a2d191d31b8 Mon Sep 17 00:00:00 2001 From: Ashutosh619-sudo Date: Tue, 5 Nov 2024 20:09:53 +0530 Subject: [PATCH 01/10] Fix: All the bug fixes listed --- apps/accounting_exports/models.py | 4 ++-- apps/business_central/actions.py | 1 + apps/business_central/exports/base_model.py | 4 ++-- apps/workspaces/tasks.py | 4 ++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/apps/accounting_exports/models.py b/apps/accounting_exports/models.py index 651b670..cc902c1 100644 --- a/apps/accounting_exports/models.py +++ b/apps/accounting_exports/models.py @@ -123,8 +123,8 @@ def create_accounting_export(expense_objects: List[Expense], fund_source: str, w for accounting_export in accounting_exports: # 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 and date_field not in ['current_date', 'last_spent_at']: + if 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') diff --git a/apps/business_central/actions.py b/apps/business_central/actions.py index 90a6796..57a4713 100644 --- a/apps/business_central/actions.py +++ b/apps/business_central/actions.py @@ -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 diff --git a/apps/business_central/exports/base_model.py b/apps/business_central/exports/base_model.py index dd552a9..0b9bebd 100644 --- a/apps/business_central/exports/base_model.py +++ b/apps/business_central/exports/base_model.py @@ -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 ) @@ -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( diff --git a/apps/workspaces/tasks.py b/apps/workspaces/tasks.py index 934da22..fd4f5d4 100644 --- a/apps/workspaces/tasks.py +++ b/apps/workspaces/tasks.py @@ -58,7 +58,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 @@ -75,7 +75,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 From ed15855ccb0f6c14b57e0e3b12e8473a8c43a735 Mon Sep 17 00:00:00 2001 From: Ashutosh619-sudo Date: Mon, 11 Nov 2024 17:03:14 +0530 Subject: [PATCH 02/10] credentials expired issue resolved --- apps/workspaces/tasks.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/apps/workspaces/tasks.py b/apps/workspaces/tasks.py index fd4f5d4..5ab68fc 100644 --- a/apps/workspaces/tasks.py +++ b/apps/workspaces/tasks.py @@ -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 @@ -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( From c12f41370ce45f7b5037e1e8820932759693cd49 Mon Sep 17 00:00:00 2001 From: Ashutosh619-sudo Date: Mon, 11 Nov 2024 17:13:23 +0530 Subject: [PATCH 03/10] pylint fix --- apps/workspaces/tasks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/workspaces/tasks.py b/apps/workspaces/tasks.py index 5ab68fc..cbea42a 100644 --- a/apps/workspaces/tasks.py +++ b/apps/workspaces/tasks.py @@ -32,7 +32,7 @@ def run_import_export(workspace_id: int, export_mode = None): """ business_central_creds = BusinessCentralCredentials.objects.filter( - workspace_id=workspace_id, is_expired=False, refresh_token__isnull=False + workspace_id=workspace_id, is_expired=False, refresh_token__isnull=False ).first() if not business_central_creds: From 26edc761d3b1f397ae1d88aff2ccaf3aa3c54725 Mon Sep 17 00:00:00 2001 From: Ashutosh619-sudo Date: Mon, 11 Nov 2024 17:42:50 +0530 Subject: [PATCH 04/10] test fail resolved --- apps/workspaces/tasks.py | 16 +++++++++------- tests/test_workspaces/test_tasks.py | 10 +++++++++- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/apps/workspaces/tasks.py b/apps/workspaces/tasks.py index cbea42a..aec0fd2 100644 --- a/apps/workspaces/tasks.py +++ b/apps/workspaces/tasks.py @@ -31,13 +31,15 @@ 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 + if export_mode == 'AUTOMATIC': + 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) diff --git a/tests/test_workspaces/test_tasks.py b/tests/test_workspaces/test_tasks.py index da09a44..b5a7c4b 100644 --- a/tests/test_workspaces/test_tasks.py +++ b/tests/test_workspaces/test_tasks.py @@ -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 @@ -64,6 +64,10 @@ def test_run_import_export_with_reimbursable_expense( 'trigger_export' ) + business_central_creds = 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) @@ -114,6 +118,10 @@ def test_run_import_export_with_credit_card_expenses( 'trigger_export' ) + business_central_creds = 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) From 5efb93d30da38eb0452fd0957fd894effcae57e4 Mon Sep 17 00:00:00 2001 From: Ashutosh619-sudo Date: Mon, 11 Nov 2024 17:47:45 +0530 Subject: [PATCH 05/10] pylint resolved --- apps/workspaces/tasks.py | 1 - tests/test_workspaces/test_tasks.py | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/apps/workspaces/tasks.py b/apps/workspaces/tasks.py index aec0fd2..f4a32da 100644 --- a/apps/workspaces/tasks.py +++ b/apps/workspaces/tasks.py @@ -39,7 +39,6 @@ def run_import_export(workspace_id: int, export_mode = None): 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) diff --git a/tests/test_workspaces/test_tasks.py b/tests/test_workspaces/test_tasks.py index b5a7c4b..71815c2 100644 --- a/tests/test_workspaces/test_tasks.py +++ b/tests/test_workspaces/test_tasks.py @@ -64,7 +64,7 @@ def test_run_import_export_with_reimbursable_expense( 'trigger_export' ) - business_central_creds = BusinessCentralCredentials.objects.create( + BusinessCentralCredentials.objects.create( workspace_id=workspace_id, is_expired=False, refresh_token='bsajkdbasjb' ) @@ -118,7 +118,7 @@ def test_run_import_export_with_credit_card_expenses( 'trigger_export' ) - business_central_creds = BusinessCentralCredentials.objects.create( + BusinessCentralCredentials.objects.create( workspace_id=workspace_id, is_expired=False, refresh_token='bsajkdbasjb' ) From 3228379b62b9addf5edb9abdc39a728670b4e600 Mon Sep 17 00:00:00 2001 From: Ashutosh619-sudo Date: Mon, 11 Nov 2024 18:46:21 +0530 Subject: [PATCH 06/10] comment resolved --- apps/accounting_exports/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/accounting_exports/models.py b/apps/accounting_exports/models.py index cc902c1..19c1e99 100644 --- a/apps/accounting_exports/models.py +++ b/apps/accounting_exports/models.py @@ -123,8 +123,8 @@ def create_accounting_export(expense_objects: List[Expense], fund_source: str, w for accounting_export in accounting_exports: # 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 not in ['current_date', 'last_spent_at']: - if accounting_export[date_field]: + if date_field and date_field != 'last_spent_at': + 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') From f5dc2eb075943774719c5527f45b0ae9604b592d Mon Sep 17 00:00:00 2001 From: Ashutosh619-sudo Date: Tue, 12 Nov 2024 18:33:05 +0530 Subject: [PATCH 07/10] small change --- apps/workspaces/tasks.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/apps/workspaces/tasks.py b/apps/workspaces/tasks.py index f4a32da..e76109c 100644 --- a/apps/workspaces/tasks.py +++ b/apps/workspaces/tasks.py @@ -30,15 +30,14 @@ def run_import_export(workspace_id: int, export_mode = None): :param workspace_id: Workspace id """ - - if export_mode == 'AUTOMATIC': - 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 + + 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) From d419249aeaf2fb36f6bc72631987ccad11ec50d0 Mon Sep 17 00:00:00 2001 From: Ashutosh619-sudo Date: Tue, 12 Nov 2024 22:11:20 +0530 Subject: [PATCH 08/10] pylint fix --- apps/workspaces/tasks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/workspaces/tasks.py b/apps/workspaces/tasks.py index e76109c..d2a9ab7 100644 --- a/apps/workspaces/tasks.py +++ b/apps/workspaces/tasks.py @@ -30,7 +30,7 @@ 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() From 6029b23bb46b67fa402812f0b158023fdb8e65d8 Mon Sep 17 00:00:00 2001 From: Ashutosh619-sudo Date: Tue, 12 Nov 2024 22:13:18 +0530 Subject: [PATCH 09/10] fix --- apps/workspaces/tasks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/workspaces/tasks.py b/apps/workspaces/tasks.py index d2a9ab7..cbea42a 100644 --- a/apps/workspaces/tasks.py +++ b/apps/workspaces/tasks.py @@ -30,7 +30,7 @@ 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() From b82d962a359661487e49ec0e864ed6d16208f495 Mon Sep 17 00:00:00 2001 From: Ashutosh619-sudo Date: Tue, 12 Nov 2024 22:28:44 +0530 Subject: [PATCH 10/10] remove intacct name --- apps/mappings/tasks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/mappings/tasks.py b/apps/mappings/tasks.py index ffeb5d1..2a1425b 100644 --- a/apps/mappings/tasks.py +++ b/apps/mappings/tasks.py @@ -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')