Skip to content

Commit

Permalink
add support for fyle fields (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
NileshPant1999 authored Nov 28, 2023
1 parent 6aa63cd commit fde05cb
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
39 changes: 39 additions & 0 deletions fyle_accounting_mappings/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,42 @@ class CategoryAttributeMappingSerializer(serializers.ModelSerializer):
class Meta:
model = ExpenseAttribute
fields = '__all__'


class FyleFieldsSerializer(serializers.Serializer):
"""
Fyle Fields Serializer
"""

attribute_type = serializers.CharField()
display_name = serializers.CharField()
is_dependant = serializers.BooleanField()

def format_fyle_fields(self, workspace_id):
"""
Get Fyle Fields
"""

attribute_types = [
'EMPLOYEE', 'CATEGORY', 'PROJECT', 'COST_CENTER',
'TAX_GROUP', 'CORPORATE_CARD', 'MERCHANT'
]

attributes = ExpenseAttribute.objects.filter(
~Q(attribute_type__in=attribute_types),
workspace_id=workspace_id
).values('attribute_type', 'display_name', 'detail__is_dependent').distinct()

attributes_list = [
{'attribute_type': 'COST_CENTER', 'display_name': 'Cost Center', 'is_dependant': False},
{'attribute_type': 'PROJECT', 'display_name': 'Project', 'is_dependant': False}
]

for attr in attributes:
attributes_list.append({
'attribute_type': attr['attribute_type'],
'display_name': attr['display_name'],
'is_dependant': attr['detail__is_dependent']
})

return attributes_list
4 changes: 3 additions & 1 deletion fyle_accounting_mappings/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
ExpenseAttributesMappingView,
EmployeeAttributesMappingView,
ExpenseFieldView,
DestinationAttributesView
DestinationAttributesView,
FyleFieldsView
)

urlpatterns = [
Expand All @@ -42,4 +43,5 @@
path('employee_attributes/', EmployeeAttributesMappingView.as_view()),
path('expense_fields/', ExpenseFieldView.as_view()),
path('destination_attributes/', DestinationAttributesView.as_view()),
path('fyle_fields/', FyleFieldsView.as_view()),
]
15 changes: 14 additions & 1 deletion fyle_accounting_mappings/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
CategoryMapping, ExpenseField
from .serializers import ExpenseAttributeMappingSerializer, MappingSettingSerializer, MappingSerializer, \
EmployeeMappingSerializer, CategoryMappingSerializer, DestinationAttributeSerializer, \
EmployeeAttributeMappingSerializer, ExpenseFieldSerializer, CategoryAttributeMappingSerializer
EmployeeAttributeMappingSerializer, ExpenseFieldSerializer, CategoryAttributeMappingSerializer, \
FyleFieldsSerializer

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -451,3 +452,15 @@ class DestinationAttributesView(LookupFieldMixin, ListAPIView):
filter_backends = (DjangoFilterBackend,)
filterset_fields = {'attribute_type': {'exact', 'in'}, 'display_name': {'exact', 'in'}, 'active': {'exact'}}
ordering_fields = ('value',)


class FyleFieldsView(ListAPIView):
"""
Fyle Fields view
"""

serializer_class = FyleFieldsSerializer
pagination_class = None

def get_queryset(self):
return FyleFieldsSerializer().format_fyle_fields(self.kwargs["workspace_id"])

0 comments on commit fde05cb

Please sign in to comment.