Skip to content

Commit

Permalink
add support to search for code in mappings page (#113)
Browse files Browse the repository at this point in the history
* add support to search for code in mappings page

* add name to the url
  • Loading branch information
Hrishabh17 authored Jul 22, 2024
1 parent 27a021a commit da0326a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
20 changes: 20 additions & 0 deletions fyle_accounting_mappings/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,23 @@ def filter_mapping_source_alphabets(self, queryset, name, value):
class Meta:
model = ExpenseAttribute
fields = ['mapping_source_alphabets', 'value']


class DestinationAttributeFilter(django_filters.FilterSet):
value = django_filters.CharFilter(method='filter_value')

class Meta:
model = DestinationAttribute
fields = {
'attribute_type': ['exact', 'in'],
'display_name': ['exact', 'in'],
'value': ['icontains'],
'code': ['icontains'],
}

def filter_value(self, queryset, name, value):
if value:
return queryset.filter(
Q(value__icontains=value) | Q(code__icontains=value)
)
return queryset
2 changes: 1 addition & 1 deletion fyle_accounting_mappings/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@
path('expense_fields/', ExpenseFieldView.as_view()),
path('destination_attributes/', DestinationAttributesView.as_view()),
path('fyle_fields/', FyleFieldsView.as_view()),
path('paginated_destination_attributes/', PaginatedDestinationAttributesView.as_view()),
path('paginated_destination_attributes/', PaginatedDestinationAttributesView.as_view(), name='paginated_destination_attributes_view'),
]
6 changes: 4 additions & 2 deletions fyle_accounting_mappings/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
EmployeeAttributeMappingSerializer, ExpenseFieldSerializer, CategoryAttributeMappingSerializer, \
FyleFieldsSerializer

from .helpers import ExpenseAttributeFilter
from .helpers import ExpenseAttributeFilter, DestinationAttributeFilter

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -346,6 +346,7 @@ def get_queryset(self):
final_filter = final_filter & param
return ExpenseAttribute.objects.filter(final_filter).order_by('value')


class EmployeeAttributesMappingView(ListAPIView):

serializer_class = EmployeeAttributeMappingSerializer
Expand Down Expand Up @@ -428,11 +429,12 @@ class FyleFieldsView(ListAPIView):
def get_queryset(self):
return FyleFieldsSerializer().format_fyle_fields(self.kwargs["workspace_id"])


class PaginatedDestinationAttributesView(LookupFieldMixin, ListAPIView):
"""
Paginated Destination Attributes view
"""
queryset = DestinationAttribute.objects.filter(active=True).order_by('value')
serializer_class = DestinationAttributeSerializer
filter_backends = (DjangoFilterBackend,)
filterset_fields = {'attribute_type': {'exact', 'in'}, 'display_name': {'exact', 'in'}, 'value': {'icontains'}}
filterset_class = DestinationAttributeFilter
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setuptools.setup(
name='fyle-accounting-mappings',
version='1.34.0',
version='1.34.1',
author='Shwetabh Kumar',
author_email='[email protected]',
description='Django application to store the fyle accounting mappings in a generic manner',
Expand Down

0 comments on commit da0326a

Please sign in to comment.