Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Move removing staff memebers logic to function
Anna Siwik53f5cb07714f
diff --git a/saleor/dashboard/staff/utils.py b/saleor/dashboard/staff/utils.pynew file mode 100644index 0000000000..7c9f885ebd--- /dev/null+++ b/saleor/dashboard/staff/utils.py@@ -0,0 +1,8 @@+def remove_staff_member(staff):+ """Removes staff member account only if has no orders placed.+ Otherwise, switches is_staff status to False."""+ if staff.orders.exists():+ staff.is_staff = False+ staff.save()+ else:+ staff.delete()diff --git a/saleor/dashboard/staff/views.py b/saleor/dashboard/staff/views.pyindex 54ca997349..47022bc91a 100644--- a/saleor/dashboard/staff/views.py+++ b/saleor/dashboard/staff/views.py@@ -7,6 +7,7 @@ from django.utils.translation import pgettext_lazyfrom .filters import StaffFilterfrom .forms import StaffForm+from .utils import remove_staff_memberfrom ..emails import (send_promote_customer_to_staff_email, send_set_password_email)from ..views import staff_member_required@@ -76,12 +77,7 @@ def staff_delete(request, pk):queryset = User.objects.prefetch_related('orders')staff = get_object_or_404(queryset, pk=pk)if request.method == 'POST':- # do not remove staff with related orders if any- if staff.orders.exists():- staff.is_staff = False- staff.save()- else:- staff.delete()+ remove_staff_member(staff)msg = pgettext_lazy('Dashboard message', 'Removed staff member %s') % (staff,)messages.success(request, msg)