diff --git a/crm/views/customer_views.py b/crm/views/customer_views.py index 1ddb55b..07fa57b 100644 --- a/crm/views/customer_views.py +++ b/crm/views/customer_views.py @@ -27,12 +27,22 @@ def log_customer_action(admin, action, customer_id, details): @permission_classes([IsCRMAdmin]) def list_customers(request): customers = CustomerProfile.objects.all() + serializer = CustomerProfileSerializer(customers, many=True) + data = serializer.data + search = request.query_params.get('search') if search: - customers = customers.filter(name__icontains=search) | customers.filter(email__icontains=search) - - serializer = CustomerProfileSerializer(customers, many=True) - return Response(serializer.data) + search = search.lower() + data = [ + c for c in data + if (c['name'] and search in c['name'].lower()) or (c['email'] and search in c['email'].lower()) + ] + + status_filter = request.query_params.get('status') + if status_filter: + data = [c for c in data if c['status'] == status_filter] + + return Response(data) @api_view(['GET']) @permission_classes([IsCRMAdmin]) diff --git a/crm/views/product_views.py b/crm/views/product_views.py index 9d69b22..0fe9b6a 100644 --- a/crm/views/product_views.py +++ b/crm/views/product_views.py @@ -19,6 +19,15 @@ def log_product_action(admin, action, product_id, details): @permission_classes([IsCRMAdmin]) def list_products(request): products = Product.objects.all() + + product_status = request.query_params.get('status') + if product_status: + products = products.filter(status=product_status) + + seller_status = request.query_params.get('seller_status') + if seller_status: + products = products.filter(supplier__status=seller_status) + serializer = ProductSerializer(products, many=True) return Response(serializer.data)