Skip to content

Commit

Permalink
Qbo fields api (#568)
Browse files Browse the repository at this point in the history
* Point to new app for failed/skipped/queued ones

* fix test

* Add support for QBO fields/ API

* add tests

* fix lint

* fix lint
  • Loading branch information
ashwin1111 authored Feb 16, 2024
1 parent 72c3e29 commit 17bb835
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions apps/quickbooks_online/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
SearchedDestinationAttributesView,
SyncQuickbooksDimensionView,
VendorView,
QBOFieldView
)

urlpatterns = [
Expand All @@ -35,4 +36,5 @@
path('destination_attributes/', DestinationAttributesView.as_view(), name='destination-attributes'),
path('mapping_options/', SearchedDestinationAttributesView.as_view(), name='searching-destination-attributes'),
path('qbo_attributes/', QBOAttributesView.as_view(), name='qbo-attributes'),
path('fields/', QBOFieldView.as_view())
]
18 changes: 18 additions & 0 deletions apps/quickbooks_online/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging

from django.db.models import Q
from django_filters.rest_framework import DjangoFilterBackend
from fyle_accounting_mappings.models import DestinationAttribute
from fyle_accounting_mappings.serializers import DestinationAttributeSerializer
Expand All @@ -11,6 +12,8 @@
from apps.quickbooks_online.actions import get_preferences, refresh_quickbooks_dimensions, sync_quickbooks_dimensions
from fyle_qbo_api.utils import LookupFieldMixin

from .serializers import QuickbooksFieldSerializer

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

Expand All @@ -27,6 +30,21 @@ class VendorView(LookupFieldMixin, generics.ListAPIView):
ordering_fields = ('value',)


class QBOFieldView(LookupFieldMixin, generics.ListAPIView):
"""
QBOField view
"""
queryset = DestinationAttribute.objects.filter(
~Q(attribute_type='EMPLOYEE') & ~Q(attribute_type='VENDOR') &
~Q(attribute_type='ACCOUNTS_PAYABLE') & ~Q(attribute_type='ACCOUNT') &
~Q(attribute_type='TAX_CODE') & ~Q(attribute_type='BANK_ACCOUNT') &
~Q(attribute_type='CREDIT_CARD_ACCOUNT')
).values('attribute_type', 'display_name').distinct()
serializer_class = QuickbooksFieldSerializer
filter_backends = (DjangoFilterBackend,)
pagination_class = None


class EmployeeView(LookupFieldMixin, generics.ListAPIView):
"""
Employee view
Expand Down
13 changes: 13 additions & 0 deletions tests/test_quickbooks_online/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,19 @@ def test_vendor_view(mocker, api_client, test_connection):
assert len(response['results']) == 10


def test_qbo_field_view(mocker, api_client, test_connection):
access_token = test_connection.access_token
url = '/api/workspaces/3/qbo/fields/'

api_client.credentials(HTTP_AUTHORIZATION='Bearer {}'.format(access_token))

response = api_client.get(url)
assert response.status_code == 200

response = json.loads(response.content)
assert len(response) == 1


def test_employee_view(mocker, api_client, test_connection):
mocker.patch('apps.quickbooks_online.utils.QBOConnector.sync_employees', return_value=None)

Expand Down

0 comments on commit 17bb835

Please sign in to comment.