Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Handle Fulfillment metadata through graphql

Mira Szewczyk05df23fb7e7e
diff --git a/saleor/graphql/order/mutations/fulfillments.py b/saleor/graphql/order/mutations/fulfillments.py
index 830ce7cc9c..e9fdafd875 100644
--- a/saleor/graphql/order/mutations/fulfillments.py
+++ b/saleor/graphql/order/mutations/fulfillments.py
@@ -10,7 +10,11 @@ from ....order.actions import (
order_fulfilled,
)
from ....order.error_codes import OrderErrorCode
-from ...core.mutations import BaseMutation
+from ...core.mutations import (
+ BaseMutation,
+ ClearMetaBaseMutation,
+ UpdateMetaBaseMutation,
+)
from ...core.types.common import OrderError
from ...order.types import Fulfillment, Order
from ..types import OrderLine
@@ -44,6 +48,38 @@ class FulfillmentCancelInput(graphene.InputObjectType):
restock = graphene.Boolean(description="Whether item lines are restocked.")
+class FulfillmentClearMeta(ClearMetaBaseMutation):
+ class Meta:
+ description = "Clears meta for fulfillment"
+ model = models.Fulfillment
+ permission = "orders.manage_orders"
+ public = True
+
+
+class FulfillmentUpdateMeta(UpdateMetaBaseMutation):
+ class Meta:
+ description = "Updates meta for fulfillment"
+ model = models.Fulfillment
+ permission = "orders.manage_orders"
+ public = True
+
+
+class FulfillmentClearPrivateMeta(ClearMetaBaseMutation):
+ class Meta:
+ description = "Clears private meta for fulfillment"
+ model = models.Fulfillment
+ permission = "orders.manage_orders"
+ public = False
+
+
+class FulfillmentUpdatePrivateMeta(UpdateMetaBaseMutation):
+ class Meta:
+ description = "Updates meta for fulfillment"
+ model = models.Fulfillment
+ permission = "orders.manage_orders"
+ public = False
+
+
class FulfillmentCreate(BaseMutation):
fulfillment = graphene.Field(Fulfillment, description="A created fulfillment.")
order = graphene.Field(Order, description="Fulfilled order.")
diff --git a/saleor/graphql/order/schema.py b/saleor/graphql/order/schema.py
index b0c7420f95..f3ed22f056 100644
--- a/saleor/graphql/order/schema.py
+++ b/saleor/graphql/order/schema.py
@@ -21,7 +21,11 @@ from .mutations.draft_orders import (
)
from .mutations.fulfillments import (
FulfillmentCancel,
+ FulfillmentClearMeta,
+ FulfillmentClearPrivateMeta,
FulfillmentCreate,
+ FulfillmentUpdateMeta,
+ FulfillmentUpdatePrivateMeta,
FulfillmentUpdateTracking,
)
from .mutations.orders import (
@@ -149,6 +153,10 @@ class OrderMutations(graphene.ObjectType):
order_fulfillment_cancel = FulfillmentCancel.Field()
order_fulfillment_create = FulfillmentCreate.Field()
order_fulfillment_update_tracking = FulfillmentUpdateTracking.Field()
+ order_fulfillment_clear_meta = FulfillmentClearMeta.Field()
+ order_fulfillment_clear_private_meta = FulfillmentClearPrivateMeta.Field()
+ order_fulfillment_update_meta = FulfillmentUpdateMeta.Field()
+ order_fulfillment_update_private_meta = FulfillmentUpdatePrivateMeta.Field()
order_mark_as_paid = OrderMarkAsPaid.Field()
order_refund = OrderRefund.Field()
order_update = OrderUpdate.Field()
diff --git a/saleor/graphql/order/types.py b/saleor/graphql/order/types.py
index a23cc6bcef..aff71408eb 100644
--- a/saleor/graphql/order/types.py
+++ b/saleor/graphql/order/types.py
@@ -157,7 +157,7 @@ class FulfillmentLine(CountableDjangoObjectType):
return root.order_line
-class Fulfillment(CountableDjangoObjectType):
+class Fulfillment(MetadataObjectType, CountableDjangoObjectType):
lines = gql_optimizer.field(
graphene.List(
FulfillmentLine, description="List of lines for the fulfillment."
@@ -186,6 +186,15 @@ class Fulfillment(CountableDjangoObjectType):
def resolve_status_display(root: models.Fulfillment, _info):
return root.get_status_display()
+ @staticmethod
+ @permission_required("orders.manage_orders")
+ def resolve_private_meta(root: models.Fulfillment, _info):
+ return resolve_private_meta(root, _info)
+
+ @staticmethod
+ def resolve_meta(root: models.Fulfillment, _info):
+ return resolve_meta(root, _info)
+
class OrderLine(CountableDjangoObjectType):
thumbnail = graphene.Field(
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index a2c53e4fc9..27cddebc82 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -1553,6 +1553,8 @@ type Fulfillment implements Node {
status: FulfillmentStatus!
trackingNumber: String!
shippingDate: DateTime!
+ privateMeta: [MetaStore]!
+ meta: [MetaStore]!
lines: [FulfillmentLine]
statusDisplay: String
}
@@ -1568,6 +1570,16 @@ input FulfillmentCancelInput {
restock: Boolean
}
+type FulfillmentClearMeta {
+ errors: [Error!]
+ fulfillment: Fulfillment
+}
+
+type FulfillmentClearPrivateMeta {
+ errors: [Error!]
+ fulfillment: Fulfillment
+}
+
type FulfillmentCreate {
errors: [Error!]
fulfillment: Fulfillment
@@ -1597,6 +1609,16 @@ enum FulfillmentStatus {
CANCELED
}
+type FulfillmentUpdateMeta {
+ errors: [Error!]
+ fulfillment: Fulfillment
+}
+
+type FulfillmentUpdatePrivateMeta {
+ errors: [Error!]
+ fulfillment: Fulfillment
+}
+
type FulfillmentUpdateTracking {
errors: [Error!]
fulfillment: Fulfillment
@@ -2116,6 +2138,10 @@ type Mutation {
orderFulfillmentCancel(id: ID!, input: FulfillmentCancelInput!): FulfillmentCancel
orderFulfillmentCreate(input: FulfillmentCreateInput!, order: ID): FulfillmentCreate
orderFulfillmentUpdateTracking(id: ID!, input: FulfillmentUpdateTrackingInput!): FulfillmentUpdateTracking
+ orderFulfillmentClearMeta(id: ID!, input: MetaPath!): FulfillmentClearMeta
+ orderFulfillmentClearPrivateMeta(id: ID!, input: MetaPath!): FulfillmentClearPrivateMeta
+ orderFulfillmentUpdateMeta(id: ID!, input: MetaInput!): FulfillmentUpdateMeta
+ orderFulfillmentUpdatePrivateMeta(id: ID!, input: MetaInput!): FulfillmentUpdatePrivateMeta
orderMarkAsPaid(id: ID!): OrderMarkAsPaid
orderRefund(amount: Decimal!, id: ID!): OrderRefund
orderUpdate(id: ID!, input: OrderUpdateInput!): OrderUpdate