Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add warehouse to filfilment type
fowczrek04165e4c572c
diff --git a/saleor/graphql/order/types.py b/saleor/graphql/order/types.pyindex e065233350..f5840f2e05 100644--- a/saleor/graphql/order/types.py+++ b/saleor/graphql/order/types.py@@ -21,6 +21,7 @@ from ..meta.types import ObjectWithMetadatafrom ..payment.types import OrderAction, Payment, PaymentChargeStatusEnumfrom ..product.types import ProductVariantfrom ..shipping.types import ShippingMethod+from ..warehouse.types import Warehousefrom .enums import OrderEventsEmailsEnum, OrderEventsEnumfrom .utils import validate_draft_order@@ -169,6 +170,11 @@ class Fulfillment(CountableDjangoObjectType):FulfillmentLine, description="List of lines for the fulfillment.")status_display = graphene.String(description="User-friendly fulfillment status.")+ warehouse = graphene.Field(+ Warehouse,+ required=False,+ description=("Warehouse from fulfillment was fulfilled."),+ )class Meta:description = "Represents order fulfillment."@@ -190,6 +196,11 @@ class Fulfillment(CountableDjangoObjectType):def resolve_status_display(root: models.Fulfillment, _info):return root.get_status_display()+ @staticmethod+ def resolve_warehouse(root: models.Fulfillment, _info):+ line = root.lines.first()+ return line.stock.warehouse if line and line.stock else None+@staticmethod@permission_required(OrderPermissions.MANAGE_ORDERS)def resolve_private_meta(root: models.Fulfillment, _info):diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex e06cf937f0..4ffc2cac16 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -1751,6 +1751,7 @@ type Fulfillment implements Node & ObjectWithMetadata {meta: [MetaStore]! @deprecated(reason: "Use the `metadata` field. This field will be removed after 2020-07-31.")lines: [FulfillmentLine]statusDisplay: String+ warehouse: Warehouse}type FulfillmentCancel {diff --git a/tests/api/test_fulfillment.py b/tests/api/test_fulfillment.pyindex 381806eb3d..8b20de4940 100644--- a/tests/api/test_fulfillment.py+++ b/tests/api/test_fulfillment.py@@ -908,3 +908,59 @@ def test_fulfillment_clear_private_meta_user_has_permission(assert content.get("errors") is Nonefulfillment.refresh_from_db()assert not fulfillment.get_value_from_private_metadata(key="foo")+++QUERY_FULFILLMENT = """+query fulfillment($id: ID!){+ order(id: $id){+ fulfillments{+ id+ fulfillmentOrder+ status+ trackingNumber+ warehouse{+ id+ }+ lines{+ orderLine{+ id+ }+ quantity+ }+ }+ }+}+"""+++def test_fulfillment_query(+ staff_api_client, fulfilled_order, warehouse, permission_manage_orders,+):+ order = fulfilled_order+ order_line_1, order_line_2 = order.lines.all()+ order_id = graphene.Node.to_global_id("Order", order.pk)+ order_line_1_id = graphene.Node.to_global_id("OrderLine", order_line_1.pk)+ order_line_2_id = graphene.Node.to_global_id("OrderLine", order_line_2.pk)+ warehose_id = graphene.Node.to_global_id("Warehouse", warehouse.pk)+ variables = {"id": order_id}+ response = staff_api_client.post_graphql(+ QUERY_FULFILLMENT, variables, permissions=[permission_manage_orders]+ )+ content = get_graphql_content(response)+ data = content["data"]["order"]["fulfillments"]+ assert len(data) == 1+ fulfillment_data = data[0]++ assert fulfillment_data["fulfillmentOrder"] == 1+ assert fulfillment_data["status"] == FulfillmentStatus.FULFILLED.upper()+ assert fulfillment_data["trackingNumber"] == "123"+ assert fulfillment_data["warehouse"]["id"] == warehose_id+ assert len(fulfillment_data["lines"]) == 2+ assert {+ "orderLine": {"id": order_line_1_id},+ "quantity": order_line_1.quantity,+ } in fulfillment_data["lines"]+ assert {+ "orderLine": {"id": order_line_2_id},+ "quantity": order_line_2.quantity,+ } in fulfillment_data["lines"]diff --git a/tests/conftest.py b/tests/conftest.pyindex 8249203b3a..3f9c88c085 100644--- a/tests/conftest.py+++ b/tests/conftest.py@@ -1207,14 +1207,16 @@ def order_events(order):@pytest.fixturedef fulfilled_order(order_with_lines):order = order_with_lines- fulfillment = order.fulfillments.create()+ fulfillment = order.fulfillments.create(tracking_number="123")line_1 = order.lines.first()+ stock_1 = line_1.allocations.get().stock+ warehouse_1_pk = stock_1.warehouse.pkline_2 = order.lines.last()- fulfillment.lines.create(order_line=line_1, quantity=line_1.quantity)- warehouse_1_pk = line_1.allocations.get().stock.warehouse.pk+ stock_2 = line_2.allocations.get().stock+ warehouse_2_pk = stock_2.warehouse.pk+ fulfillment.lines.create(order_line=line_1, quantity=line_1.quantity, stock=stock_1)fulfill_order_line(line_1, line_1.quantity, warehouse_1_pk)- fulfillment.lines.create(order_line=line_2, quantity=line_2.quantity)- warehouse_2_pk = line_2.allocations.get().stock.warehouse.pk+ fulfillment.lines.create(order_line=line_2, quantity=line_2.quantity, stock=stock_2)fulfill_order_line(line_2, line_2.quantity, warehouse_2_pk)order.status = OrderStatus.FULFILLEDorder.save(update_fields=["status"])