From 6ccacf7ad3cc2268d901b6bc77d32793be8b9c34 Mon Sep 17 00:00:00 2001 From: vickytechkey Date: Sun, 16 Aug 2026 11:24:43 +0530 Subject: [PATCH] Support activating/reinstating customer account from CRM --- crm/views/customer_views.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/crm/views/customer_views.py b/crm/views/customer_views.py index 348c550..1ddb55b 100644 --- a/crm/views/customer_views.py +++ b/crm/views/customer_views.py @@ -53,16 +53,22 @@ def suspend_customer(request, pk): except CustomerProfile.DoesNotExist: return Response({"detail": "Customer not found"}, status=404) - # Update is_active to False in customerwebsite database to block logins + # If status payload is active, reinstate the customer account + target_status = request.data.get('status', 'suspended') + is_active_val = True if target_status == 'active' else False + action_name = 'reinstate_customer' if is_active_val else 'suspend_customer' + message_val = 'Customer account reinstated' if is_active_val else 'Customer account suspended' + + # Update is_active in customerwebsite database to enable/disable logins from django.db import connections try: with connections['customer_db'].cursor() as cursor: - cursor.execute("UPDATE auth_user SET is_active = False WHERE id = %s", [customer.user_id]) + cursor.execute("UPDATE auth_user SET is_active = %s WHERE id = %s", [is_active_val, customer.user_id]) except Exception as e: return Response({"detail": f"Database update failed: {str(e)}"}, status=500) - log_customer_action(request.user, 'suspend_customer', customer.id, {"reason": request.data.get('reason')}) - return Response({"message": "Customer account suspended"}) + log_customer_action(request.user, action_name, customer.id, {"reason": request.data.get('reason')}) + return Response({"message": message_val}) @api_view(['POST']) @permission_classes([IsCRMAdmin])