Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix order fulfill mutation as app
fowczrek4e7c09d0f242
diff --git a/saleor/graphql/order/mutations/fulfillments.py b/saleor/graphql/order/mutations/fulfillments.pyindex 7bf8c2cd97..3da5113311 100644--- a/saleor/graphql/order/mutations/fulfillments.py+++ b/saleor/graphql/order/mutations/fulfillments.py@@ -19,7 +19,6 @@ from ...core.types.common import OrderErrorfrom ...core.utils import from_global_id_strict_type, get_duplicated_valuesfrom ...meta.deprecated.mutations import ClearMetaBaseMutation, UpdateMetaBaseMutationfrom ...order.types import Fulfillment, Order-from ...utils import get_user_or_app_from_contextfrom ...warehouse.types import Warehousefrom ..types import OrderLine@@ -236,13 +235,13 @@ class OrderFulfill(BaseMutation):cleaned_input = cls.clean_input(data)- requester = get_user_or_app_from_context(info.context)+ user = info.context.userlines_for_warehouses = cleaned_input["lines_for_warehouses"]notify_customer = cleaned_input.get("notify_customer", True)try:fulfillments = create_fulfillments(- requester, order, dict(lines_for_warehouses), notify_customer+ user, order, dict(lines_for_warehouses), notify_customer)except InsufficientStock as exc:order_line_global_id = graphene.Node.to_global_id(diff --git a/tests/api/test_fulfillment.py b/tests/api/test_fulfillment.pyindex e304bbb5ad..1a0c884edb 100644--- a/tests/api/test_fulfillment.py+++ b/tests/api/test_fulfillment.py@@ -2,6 +2,7 @@ from unittest.mock import patchimport grapheneimport pytest+from django.contrib.auth.models import AnonymousUserfrom saleor.core.exceptions import InsufficientStockfrom saleor.core.permissions import OrderPermissions@@ -82,6 +83,56 @@ def test_order_fulfill()+@patch("saleor.graphql.order.mutations.fulfillments.create_fulfillments")+def test_order_fulfill_as_app(+ mock_create_fulfillments,+ app_api_client,+ staff_user,+ order_with_lines,+ permission_manage_orders,+ warehouse,+):+ order = order_with_lines+ query = ORDER_FULFILL_QUERY+ order_id = graphene.Node.to_global_id("Order", order.id)+ order_line, order_line2 = order.lines.all()+ order_line_id = graphene.Node.to_global_id("OrderLine", order_line.id)+ order_line2_id = graphene.Node.to_global_id("OrderLine", order_line2.id)+ warehouse_id = graphene.Node.to_global_id("Warehouse", warehouse.pk)+ variables = {+ "order": order_id,+ "input": {+ "notifyCustomer": True,+ "lines": [+ {+ "orderLineId": order_line_id,+ "stocks": [{"quantity": 3, "warehouse": warehouse_id}],+ },+ {+ "orderLineId": order_line2_id,+ "stocks": [{"quantity": 2, "warehouse": warehouse_id}],+ },+ ],+ },+ }+ response = app_api_client.post_graphql(+ query, variables, permissions=[permission_manage_orders]+ )+ content = get_graphql_content(response)+ data = content["data"]["orderFulfill"]+ assert not data["orderErrors"]++ fulfillment_lines_for_warehouses = {+ str(warehouse.pk): [+ {"order_line": order_line, "quantity": 3},+ {"order_line": order_line2, "quantity": 2},+ ]+ }+ mock_create_fulfillments.assert_called_once_with(+ AnonymousUser(), order, fulfillment_lines_for_warehouses, True+ )++@patch("saleor.graphql.order.mutations.fulfillments.create_fulfillments")def test_order_fulfill_many_warehouses(mock_create_fulfillments,