Skip to content

Commit

Permalink
adding active flag to ExpenseAttributesMappingView and MappingStatsVi…
Browse files Browse the repository at this point in the history
…ew (#62)
  • Loading branch information
labhvam5 authored Aug 10, 2022
1 parent 1428629 commit 89b6f69
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
42 changes: 31 additions & 11 deletions fyle_accounting_mappings/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,16 @@ def get(self, request, *args, **kwargs):
assert_valid(source_type is not None, 'query param source_type not found')
assert_valid(destination_type is not None, 'query param destination_type not found')

total_attributes_count = ExpenseAttribute.objects.filter(
attribute_type=source_type, workspace_id=self.kwargs['workspace_id']
).count()
filters = {
'attribute_type' : source_type,
'workspace_id': self.kwargs['workspace_id']
}

if (source_type == 'PROJECT' and destination_type == 'CUSTOMER') or\
(source_type == 'CATEGORY'):
filters['active'] = True

total_attributes_count = ExpenseAttribute.objects.filter(**filters).count()

if source_type == 'EMPLOYEE':
filters = {}
Expand All @@ -198,9 +205,16 @@ def get(self, request, *args, **kwargs):
**filters, workspace_id=self.kwargs['workspace_id']
).count()
else:
mapped_attributes_count = Mapping.objects.filter(
source_type=source_type, destination_type=destination_type, workspace_id=self.kwargs['workspace_id']
).count()
filters = {
'source_type' : source_type,
'destination_type' : destination_type,
'workspace_id': self.kwargs['workspace_id']
}
if (source_type == 'PROJECT' and destination_type == 'CUSTOMER') or\
(source_type == 'CATEGORY'):
filters['source__active'] = True

mapped_attributes_count = Mapping.objects.filter(**filters).count()

return Response(
data={
Expand Down Expand Up @@ -240,21 +254,27 @@ def get_queryset(self):
else:
mapped = None

filters = {
'workspace_id' : self.kwargs['workspace_id'],
'attribute_type': source_type,
}

if (source_type == 'PROJECT' and destination_type == 'CUSTOMER') or\
(source_type == 'CATEGORY'):
filters['active'] = True

if mapped:
param = Q(mapping__destination_type=destination_type)
elif mapped is False:
param = ~Q(mapping__destination_type=destination_type)
else:
return ExpenseAttribute.objects.filter(
reduce(operator.or_, (Q(value__istartswith=x) for x in mapping_source_alphabets)),
workspace_id=self.kwargs['workspace_id'], attribute_type=source_type,
reduce(operator.or_, (Q(value__istartswith=x) for x in mapping_source_alphabets)), **filters
).order_by('value').all()

return ExpenseAttribute.objects.filter(
reduce(operator.or_, (Q(value__istartswith=x) for x in mapping_source_alphabets)),
param,
workspace_id=self.kwargs['workspace_id'], attribute_type=source_type,
).order_by('value').all()
param, **filters).order_by('value').all()


class EmployeeAttributesMappingView(ListAPIView):
Expand Down
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.17.0',
version='1.18.0',
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 89b6f69

Please sign in to comment.