Repository: saleor/saleor

Issue:
Add missing API for changes required in order details view
A related issue in Dashboard repo: https://github.com/mirumee/saleor-dashboard/issues/196.
We need to make sure that API supports the following:
- adding/updating discount on a draft order (fixed amount/percentage)
- adding/updating a customer note


Discussion:
Adding discounts to draft orders is supported at very basic level by specifying a discount amount which shuold be fine for now. We need to extend the `DraftOrderInput` type to support setting the `Order.customer_note` field. The input field description should say something like this: "A note from a customer. Visible by customers in the order summary."

Resolving patch:
diff --git a/saleor/graphql/order/mutations/draft_orders.py b/saleor/graphql/order/mutations/draft_orders.py
--- a/saleor/graphql/order/mutations/draft_orders.py
+++ b/saleor/graphql/order/mutations/draft_orders.py
@@ -52,6 +52,9 @@ class DraftOrderInput(InputObjectType):
     voucher = graphene.ID(
         description="ID of the voucher associated with the order.", name="voucher"
     )
+    customer_note = graphene.String(
+        description="A note from a customer. Visible by customers in the order summary."
+    )
 
 
 class DraftOrderCreateInput(DraftOrderInput):


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
@@ -525,11 +525,13 @@ def test_draft_order_create(
     query = """
     mutation draftCreate(
         $user: ID, $discount: Decimal, $lines: [OrderLineCreateInput],
-        $shippingAddress: AddressInput, $shippingMethod: ID, $voucher: ID) {
+        $shippingAddress: AddressInput, $shippingMethod: ID, $voucher: ID,
+        $customerNote: String) {
             draftOrderCreate(
                 input: {user: $user, discount: $discount,
                 lines: $lines, shippingAddress: $shippingAddress,
-                shippingMethod: $shippingMethod, voucher: $voucher}) {
+                shippingMethod: $shippingMethod, voucher: $voucher,
+                customerNote: $customerNote}) {
                     errors {
                         field
                         message
@@ -551,7 +553,7 @@ def test_draft_order_create(
                         voucher {
                             code
                         }
-
+                        customerNote
                     }
                 }
         }
@@ -567,6 +569,7 @@ def test_draft_order_create(
     variant_1.save()
     variant_1_id = graphene.Node.to_global_id("ProductVariant", variant_1.id)
     discount = "10"
+    customer_note = "Test note"
     variant_list = [
         {"variantId": variant_0_id, "quantity": 2},
         {"variantId": variant_1_id, "quantity": 1},
@@ -581,6 +584,7 @@ def test_draft_order_create(
         "shippingAddress": shipping_address,
         "shippingMethod": shipping_id,
         "voucher": voucher_id,
+        "customerNote": customer_note,
     }
     response = staff_api_client.post_graphql(
         query, variables, permissions=[permission_manage_orders]
@@ -590,6 +594,7 @@ def test_draft_order_create(
     data = content["data"]["draftOrderCreate"]["order"]
     assert data["status"] == OrderStatus.DRAFT.upper()
     assert data["voucher"]["code"] == voucher.code
+    assert data["customerNote"] == customer_note
 
     order = Order.objects.first()
     assert order.user == customer_user
@@ -615,9 +620,11 @@ def test_draft_order_update(
 ):
     order = order_with_lines
     assert not order.voucher
+    assert not order.customer_note
     query = """
-        mutation draftUpdate($id: ID!, $voucher: ID!) {
-            draftOrderUpdate(id: $id, input: {voucher: $voucher}) {
+        mutation draftUpdate($id: ID!, $voucher: ID!, $customerNote: String) {
+            draftOrderUpdate(id: $id,
+                             input: {voucher: $voucher, customerNote: $customerNote}) {
                 errors {
                     field
                     message
@@ -630,7 +637,8 @@ def test_draft_order_update(
         """
     order_id = graphene.Node.to_global_id("Order", order.id)
     voucher_id = graphene.Node.to_global_id("Voucher", voucher.id)
-    variables = {"id": order_id, "voucher": voucher_id}
+    customer_note = "Test customer note"
+    variables = {"id": order_id, "voucher": voucher_id, "customerNote": customer_note}
     response = staff_api_client.post_graphql(
         query, variables, permissions=[permission_manage_orders]
     )
@@ -639,6 +647,7 @@ def test_draft_order_update(
     assert not data["errors"]
     order.refresh_from_db()
     assert order.voucher
+    assert order.customer_note == customer_note
 
 
 def test_draft_order_update_doing_nothing_generates_no_events(