Skip to content

Commit

Permalink
Add tests direct export (#303)
Browse files Browse the repository at this point in the history
* Add tests direct export

* Add tests direct export

* Add direct export scripts (#304)

* Add scripts for direct export

* Fix comments

* URL fix

* Direct export lint fix (#305)
  • Loading branch information
ruuushhh authored Feb 14, 2024
1 parent f6804b8 commit fdf7a60
Show file tree
Hide file tree
Showing 35 changed files with 484 additions and 99 deletions.
16 changes: 7 additions & 9 deletions apps/fyle/actions.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@

from typing import List
import logging
from datetime import datetime, timezone
from typing import List

from django.db.models import Q
from django.conf import settings
from django.db.models import Q
from fyle.platform.exceptions import InternalServerError, RetryException
from fyle.platform.internals.decorators import retry
from fyle_accounting_mappings.models import ExpenseAttribute
from fyle_integrations_platform_connector import PlatformConnector

from apps.fyle.enums import FundSourceEnum, FyleAttributeEnum
from apps.fyle.helpers import get_batched_expenses, get_updated_accounting_export_summary
from apps.fyle.models import Expense, ExpenseGroup
from apps.workspaces.models import FyleCredential, Workspace, WorkspaceGeneralSettings

from apps.fyle.enums import FyleAttributeEnum, FundSourceEnum
from apps.fyle.models import ExpenseGroup, Expense
from fyle.platform.internals.decorators import retry
from fyle.platform.exceptions import InternalServerError, RetryException
from apps.fyle.helpers import get_updated_accounting_export_summary, get_batched_expenses


logger = logging.getLogger(__name__)
logger.level = logging.INFO

Expand Down
5 changes: 3 additions & 2 deletions apps/fyle/helpers.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import json
import traceback
import logging
import traceback
from typing import List, Union

import requests
from django.conf import settings
from apps.fyle.models import ExpenseGroupSettings, Expense

from apps.fyle.models import Expense, ExpenseGroupSettings
from apps.tasks.models import TaskLog
from apps.workspaces.models import WorkspaceGeneralSettings

Expand Down
4 changes: 1 addition & 3 deletions apps/fyle/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
from django.db.models import Count, JSONField
from fyle_accounting_mappings.models import ExpenseAttribute

from apps.fyle.enums import ExpenseStateEnum, FundSourceEnum, PlatformExpensesEnum
from apps.workspaces.models import Workspace

from .enums import FundSourceEnum, PlatformExpensesEnum, ExpenseStateEnum


logger = logging.getLogger(__name__)
logger.level = logging.INFO

Expand Down
18 changes: 8 additions & 10 deletions apps/fyle/tasks.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import logging
import traceback
from datetime import datetime
from typing import List, Dict
from typing import Dict, List

from django.db import transaction
from fyle.platform.exceptions import InvalidTokenError as FyleInvalidTokenError
from fyle_integrations_platform_connector import PlatformConnector

from apps.tasks.models import TaskLog
from apps.tasks.enums import TaskLogStatusEnum, TaskLogTypeEnum
from apps.workspaces.models import FyleCredential, Workspace, WorkspaceGeneralSettings

from apps.fyle.actions import create_generator_and_post_in_batches
from apps.fyle.enums import ExpenseStateEnum, FundSourceEnum, PlatformExpensesEnum
from apps.fyle.helpers import get_filter_credit_expenses, get_fund_source, get_source_account_type, handle_import_exception
from apps.fyle.models import Expense, ExpenseGroup, ExpenseGroupSettings
from apps.fyle.enums import FundSourceEnum, PlatformExpensesEnum, ExpenseStateEnum
from apps.fyle.helpers import get_filter_credit_expenses, get_source_account_type, get_fund_source, handle_import_exception
from apps.workspaces.actions import export_to_xero
from apps.fyle.queue import async_post_accounting_export_summary
from apps.fyle.actions import create_generator_and_post_in_batches

from apps.tasks.enums import TaskLogStatusEnum, TaskLogTypeEnum
from apps.tasks.models import TaskLog
from apps.workspaces.actions import export_to_xero
from apps.workspaces.models import FyleCredential, Workspace, WorkspaceGeneralSettings

logger = logging.getLogger(__name__)
logger.level = logging.INFO
Expand Down
2 changes: 1 addition & 1 deletion apps/fyle/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
ExpenseGroupSyncView,
ExpenseGroupView,
ExportableExpenseGroupsView,
ExportView,
RefreshFyleDimensionView,
SyncFyleDimensionView,
ExportView
)

urlpatterns = [
Expand Down
2 changes: 1 addition & 1 deletion apps/fyle/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
from apps.exceptions import handle_view_exceptions
from apps.fyle.actions import exportable_expense_group, get_expense_field, refresh_fyle_dimension, sync_fyle_dimension
from apps.fyle.models import ExpenseGroup, ExpenseGroupSettings
from apps.fyle.queue import async_import_and_export_expenses
from apps.fyle.serializers import ExpenseFieldSerializer, ExpenseGroupSerializer, ExpenseGroupSettingsSerializer
from apps.fyle.tasks import async_create_expense_groups, get_task_log_and_fund_source
from fyle_xero_api.utils import LookupFieldMixin
from apps.fyle.queue import async_import_and_export_expenses


class ExpenseGroupView(LookupFieldMixin, generics.ListCreateAPIView):
Expand Down
3 changes: 1 addition & 2 deletions apps/mappings/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
from django_q.models import Schedule
from fyle_accounting_mappings.models import MappingSetting

from apps.workspaces.models import WorkspaceGeneralSettings

from apps.fyle.enums import FyleAttributeEnum
from apps.workspaces.models import WorkspaceGeneralSettings


def schedule_or_delete_fyle_import_tasks(configuration: WorkspaceGeneralSettings):
Expand Down
2 changes: 1 addition & 1 deletion apps/mappings/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
from django_q.tasks import async_task
from fyle_accounting_mappings.models import Mapping, MappingSetting

from apps.fyle.enums import FyleAttributeEnum
from apps.mappings.helpers import schedule_or_delete_fyle_import_tasks
from apps.mappings.models import TenantMapping
from apps.mappings.queue import schedule_cost_centers_creation, schedule_fyle_attributes_creation
from apps.mappings.tasks import upload_attributes_to_fyle
from apps.tasks.models import Error
from apps.workspaces.models import WorkspaceGeneralSettings
from apps.fyle.enums import FyleAttributeEnum


@receiver(post_save, sender=Mapping)
Expand Down
3 changes: 1 addition & 2 deletions apps/mappings/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
from fyle_accounting_mappings.models import DestinationAttribute, ExpenseAttribute, Mapping, MappingSetting
from fyle_integrations_platform_connector import PlatformConnector

from apps.fyle.enums import FyleAttributeEnum
from apps.mappings.constants import FYLE_EXPENSE_SYSTEM_FIELDS
from apps.mappings.exceptions import handle_import_exceptions
from apps.tasks.models import Error
from apps.workspaces.models import FyleCredential, WorkspaceGeneralSettings, XeroCredentials
from apps.xero.utils import XeroConnector
from apps.fyle.enums import FyleAttributeEnum


logger = logging.getLogger(__name__)
logger.level = logging.INFO
Expand Down
3 changes: 1 addition & 2 deletions apps/tasks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
from fyle_accounting_mappings.models import ExpenseAttribute

from apps.fyle.models import ExpenseGroup
from apps.tasks.enums import ErrorTypeEnum
from apps.workspaces.models import Workspace
from apps.xero.models import BankTransaction, Bill, Payment

from .enums import ErrorTypeEnum


def get_default():
return dict
Expand Down
16 changes: 11 additions & 5 deletions apps/workspaces/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,22 @@
from fyle_rest_auth.models import AuthToken
from xerosdk import exceptions as xero_exc

from apps.fyle.enums import FundSourceEnum
from apps.fyle.helpers import get_cluster_domain
from apps.fyle.models import ExpenseGroupSettings
from apps.fyle.models import ExpenseGroup, ExpenseGroupSettings
from apps.mappings.models import TenantMapping
from apps.workspaces.models import FyleCredential, LastExportDetail, Workspace, XeroCredentials, WorkspaceGeneralSettings, WorkspaceSchedule
from apps.fyle.models import ExpenseGroup
from apps.workspaces.models import (
FyleCredential,
LastExportDetail,
Workspace,
WorkspaceGeneralSettings,
WorkspaceSchedule,
XeroCredentials,
)
from apps.workspaces.signals import post_delete_xero_connection
from apps.workspaces.utils import generate_xero_refresh_token
from apps.xero.utils import XeroConnector
from apps.fyle.enums import FundSourceEnum
from apps.xero.queue import schedule_bank_transaction_creation, schedule_bills_creation
from apps.xero.utils import XeroConnector

logger = logging.getLogger(__name__)

Expand Down
8 changes: 2 additions & 6 deletions apps/workspaces/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@
from django.template.loader import render_to_string
from fyle_accounting_mappings.models import ExpenseAttribute
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import (
Mail, From
)
from sendgrid.helpers.mail import From, Mail

from apps.mappings.models import TenantMapping

from apps.tasks.enums import TaskLogStatusEnum, TaskLogTypeEnum
from apps.tasks.models import Error, TaskLog
from apps.tasks.enums import TaskLogTypeEnum, TaskLogStatusEnum

from apps.workspaces.models import Workspace, WorkspaceSchedule


Expand Down
3 changes: 1 addition & 2 deletions apps/workspaces/signals.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from fyle_accounting_mappings.models import DestinationAttribute, Mapping

from apps.fyle.enums import FyleAttributeEnum
from apps.mappings.models import TenantMapping
from apps.workspaces.models import Workspace

from apps.fyle.enums import FyleAttributeEnum


def post_delete_xero_connection(workspace_id):
"""
Expand Down
17 changes: 6 additions & 11 deletions apps/workspaces/tasks.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
import logging
import json
import logging
from datetime import datetime
from django.conf import settings

from django.conf import settings
from fyle_integrations_platform_connector import PlatformConnector
from fyle_rest_auth.helpers import get_fyle_admin
from apps.fyle.helpers import post_request

from apps.fyle.tasks import async_create_expense_groups
from apps.fyle.enums import FundSourceEnum

from apps.fyle.helpers import post_request
from apps.fyle.tasks import async_create_expense_groups
from apps.mappings.models import TenantMapping

from apps.tasks.models import TaskLog
from apps.tasks.enums import TaskLogStatusEnum, TaskLogTypeEnum

from apps.tasks.models import TaskLog
from apps.users.models import User

from apps.workspaces.actions import export_to_xero
from apps.workspaces.email import get_admin_name, get_errors, get_failed_task_logs_count, send_failure_notification_email
from apps.workspaces.models import FyleCredential, Workspace, WorkspaceGeneralSettings, WorkspaceSchedule
from apps.workspaces.actions import export_to_xero


logger = logging.getLogger(__name__)
logger.level = logging.INFO
Expand Down
6 changes: 1 addition & 5 deletions apps/workspaces/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,11 @@
from fyle_accounting_mappings.models import MappingSetting
from xerosdk import InternalServerError, InvalidTokenError, XeroSDK

from apps.fyle.models import ExpenseGroupSettings
from apps.fyle.enums import FyleAttributeEnum

from apps.fyle.models import ExpenseGroupSettings
from apps.mappings.queue import schedule_auto_map_employees, schedule_tax_groups_creation

from apps.workspaces.models import Workspace, WorkspaceGeneralSettings

from apps.xero.queue import schedule_payment_creation, schedule_reimbursements_sync, schedule_xero_objects_status_sync

from fyle_xero_api.utils import assert_valid


Expand Down
6 changes: 2 additions & 4 deletions apps/workspaces/views.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
import logging

from django.contrib.auth import get_user_model
from django_q.tasks import async_task
from fyle_rest_auth.utils import AuthUtils
from rest_framework import generics
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.views import status

from django_q.tasks import async_task

from apps.exceptions import handle_view_exceptions
from apps.workspaces.actions import connect_xero, get_workspace_admin, post_workspace, revoke_connections
from apps.workspaces.actions import connect_xero, export_to_xero, get_workspace_admin, post_workspace, revoke_connections
from apps.workspaces.models import LastExportDetail, Workspace, WorkspaceGeneralSettings, XeroCredentials
from apps.workspaces.serializers import (
LastExportDetailSerializer,
WorkSpaceGeneralSettingsSerializer,
WorkspaceSerializer,
XeroCredentialSerializer,
)
from apps.workspaces.actions import export_to_xero
from apps.workspaces.utils import generate_xero_identity

logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion apps/xero/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from django_q.tasks import Chain
from fyle_accounting_mappings.models import MappingSetting

from apps.fyle.enums import FyleAttributeEnum
from apps.workspaces.models import Workspace, WorkspaceGeneralSettings, XeroCredentials
from apps.xero.utils import XeroConnector
from apps.fyle.enums import FyleAttributeEnum


def get_xero_connector(workspace_id):
Expand Down
10 changes: 3 additions & 7 deletions apps/xero/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@
XeroSDKError,
)

from fyle_xero_api.exceptions import BulkError

from apps.fyle.actions import update_failed_expenses
from apps.fyle.models import ExpenseGroup

from apps.tasks.enums import ErrorTypeEnum, TaskLogStatusEnum, TaskLogTypeEnum
from apps.tasks.models import Error, TaskLog
from apps.tasks.enums import TaskLogStatusEnum, TaskLogTypeEnum, ErrorTypeEnum

from apps.workspaces.models import FyleCredential, LastExportDetail, XeroCredentials
from apps.fyle.actions import update_failed_expenses

from fyle_xero_api.exceptions import BulkError

logger = logging.getLogger(__name__)
logger.level = logging.INFO
Expand Down
4 changes: 1 addition & 3 deletions apps/xero/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
from django.db.models import JSONField
from fyle_accounting_mappings.models import DestinationAttribute, ExpenseAttribute, Mapping, MappingSetting

from apps.fyle.models import Expense, ExpenseGroup
from apps.fyle.enums import FyleAttributeEnum

from apps.fyle.models import Expense, ExpenseGroup
from apps.mappings.models import GeneralMapping

from apps.workspaces.models import FyleCredential, Workspace


Expand Down
12 changes: 2 additions & 10 deletions apps/xero/queue.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
from datetime import datetime, timedelta

from django_q.models import Schedule
from typing import List

from django.db.models import Q

from django_q.models import Schedule
from django_q.tasks import Chain


from xerosdk.exceptions import UnsuccessfulAuthentication

from apps.fyle.models import Expense, ExpenseGroup

from apps.mappings.models import GeneralMapping

from apps.tasks.models import TaskLog
from apps.tasks.enums import TaskLogStatusEnum, TaskLogTypeEnum

from apps.tasks.models import TaskLog
from apps.workspaces.models import FyleCredential, XeroCredentials

from apps.xero.utils import XeroConnector


Expand Down
4 changes: 2 additions & 2 deletions scripts/python/create-admin-subscriptions.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Create admin subscriptions for existing workspaces

from apps.workspaces.tasks import async_create_admin_subcriptions
from apps.workspaces.models import Workspace
from fyle.platform.exceptions import InvalidTokenError as FyleInvalidTokenError

from apps.workspaces.models import Workspace
from apps.workspaces.tasks import async_create_admin_subcriptions

workspaces = Workspace.objects.all()

Expand Down
Loading

0 comments on commit fdf7a60

Please sign in to comment.