feat: add status filtering to customer list and status-based filtering to product list
All checks were successful
Deploy Beta (NATIVE) / deploy (push) Successful in 22s
All checks were successful
Deploy Beta (NATIVE) / deploy (push) Successful in 22s
This commit is contained in:
parent
5cbc5d9da9
commit
e82dc2f555
2 changed files with 23 additions and 4 deletions
|
|
@ -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])
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue