Repository: saleor/saleor

Issue:
API should be able to finalize draft without pinning it to a customer
### What I'm trying to achieve
To finalize an order, when `user` and `user_email` are `None` in `Order` model.
Justification: sometimes the user wants to add order that had been placed physically, and has no data about the customer.


Discussion:

Resolving patch:
diff --git a/saleor/graphql/order/mutations/orders.py b/saleor/graphql/order/mutations/orders.py
--- a/saleor/graphql/order/mutations/orders.py
+++ b/saleor/graphql/order/mutations/orders.py
@@ -124,16 +124,6 @@ class Meta:
         description = 'Updates an order.'
         model = models.Order
 
-    @classmethod
-    def clean_input(cls, info, instance, input, errors):
-        cleaned_input = super().clean_input(info, instance, input, errors)
-        if not instance.user and not cleaned_input.get('user_email'):
-            cls.add_error(
-                errors, field='user_email',
-                message='User_email field is null while order was created by '
-                        'anonymous user')
-        return cleaned_input
-
     @classmethod
     def save(cls, info, instance, cleaned_input):
         super().save(info, instance, cleaned_input)
diff --git a/saleor/graphql/order/utils.py b/saleor/graphql/order/utils.py
--- a/saleor/graphql/order/utils.py
+++ b/saleor/graphql/order/utils.py
@@ -24,9 +24,4 @@ def can_finalize_draft_order(order, errors):
                     field='shipping',
                     message='Shipping method is not valid for chosen shipping '
                             'address'))
-    if not order.user and not order.user_email:
-        errors.append(
-            Error(
-                field=None,
-                message='Both user and user_email fields are null'))
     return errors


Test patch:
diff --git a/tests/api/test_order.py b/tests/api/test_order.py
--- a/tests/api/test_order.py
+++ b/tests/api/test_order.py
@@ -518,9 +518,8 @@ def test_draft_order_complete_anonymous_user_no_email(
     response = staff_api_client.post_graphql(
         query, variables, permissions=[permission_manage_orders])
     content = get_graphql_content(response)
-    assert 'errors' in content['data']['draftOrderComplete']
-    assert content['data']['draftOrderComplete']['errors'][0] == {
-        'field': None, 'message': 'Both user and user_email fields are null'}
+    data = content['data']['draftOrderComplete']['order']
+    assert data['status'] == OrderStatus.UNFULFILLED.upper()
 
 
 DRAFT_ORDER_LINE_CREATE_MUTATION = """
@@ -777,6 +776,7 @@ def test_order_update_anonymous_user_no_user_email(
                     }
                     order {
                         id
+                        status
                     }
                 }
             }
@@ -788,16 +788,12 @@ def test_order_update_anonymous_user_no_user_email(
     response = staff_api_client.post_graphql(
         query, variables, permissions=[permission_manage_orders])
     content = get_graphql_content(response)
-    assert 'errors' in content['data']['orderUpdate']
-    assert content['data']['orderUpdate']['errors'][0] == {
-        'field': 'userEmail',
-        'message': 'User_email field is null while order was created by '
-                   'anonymous user'}
-
     order.shipping_address.refresh_from_db()
     order.billing_address.refresh_from_db()
     assert order.shipping_address.first_name != first_name
     assert order.billing_address.last_name != last_name
+    data = content['data']['orderUpdate']['order']
+    assert data['status'] == OrderStatus.DRAFT.upper()
 
 
 def test_order_update_user_email_existing_user(