Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Send fulfillment update email in FulfillmentUpdateTracking mutation
IKarbowiak927d6b9f90cb
diff --git a/saleor/graphql/order/mutations/fulfillments.py b/saleor/graphql/order/mutations/fulfillments.pyindex a1e7f84086..ba3d5ee84d 100644--- a/saleor/graphql/order/mutations/fulfillments.py+++ b/saleor/graphql/order/mutations/fulfillments.py@@ -10,6 +10,7 @@ from ....order.actions import (fulfillment_tracking_updated,order_fulfilled,)+from ....order.emails import send_fulfillment_updatefrom ....order.error_codes import OrderErrorCodefrom ...core.mutations import (BaseMutation,@@ -41,7 +42,8 @@ class FulfillmentCreateInput(graphene.InputObjectType):class FulfillmentUpdateTrackingInput(graphene.InputObjectType):tracking_number = graphene.String(description="Fulfillment tracking number.")notify_customer = graphene.Boolean(- description="If true, send an email notification to the customer."+ default_value=False,+ description="If true, send an email notification to the customer.",)@@ -210,6 +212,10 @@ class FulfillmentUpdateTracking(BaseMutation):fulfillment.save()order = fulfillment.orderfulfillment_tracking_updated(fulfillment, info.context.user, tracking_number)+ input_data = data.get("input")+ notify_customer = input_data.get("notify_customer") if input_data else None+ if notify_customer:+ send_fulfillment_update.delay(order.pk, fulfillment.pk)return FulfillmentUpdateTracking(fulfillment=fulfillment, order=order)diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 6fccce7884..7c61931ed4 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -1667,7 +1667,7 @@ type FulfillmentUpdateTracking {input FulfillmentUpdateTrackingInput {trackingNumber: String- notifyCustomer: Boolean+ notifyCustomer: Boolean = false}type GatewayConfigLine {diff --git a/tests/api/test_fulfillment.py b/tests/api/test_fulfillment.pyindex e2ec845d8e..7711821c67 100644--- a/tests/api/test_fulfillment.py+++ b/tests/api/test_fulfillment.py@@ -162,8 +162,12 @@ def test_create_fulfillment_with_invalid_input()+@patch("saleor.order.emails.send_fulfillment_update.delay")def test_fulfillment_update_tracking(- staff_api_client, fulfillment, permission_manage_orders+ send_fulfillment_update_mock,+ staff_api_client,+ fulfillment,+ permission_manage_orders,):query = """mutation updateFulfillment($id: ID!, $tracking: String) {@@ -184,6 +188,64 @@ def test_fulfillment_update_tracking(content = get_graphql_content(response)data = content["data"]["orderFulfillmentUpdateTracking"]["fulfillment"]assert data["trackingNumber"] == tracking+ send_fulfillment_update_mock.assert_not_called()+++FULFILLMENT_UPDATE_TRACKING_WITH_SEND_NOTIFICATION_QUERY = """+ mutation updateFulfillment($id: ID!, $tracking: String, $notifyCustomer: Boolean) {+ orderFulfillmentUpdateTracking(+ id: $id+ input: {trackingNumber: $tracking, notifyCustomer: $notifyCustomer}) {+ fulfillment {+ trackingNumber+ }+ }+ }+ """+++@patch("saleor.order.emails.send_fulfillment_update.delay")+def test_fulfillment_update_tracking_send_notification_true(+ send_fulfillment_update_mock,+ staff_api_client,+ fulfillment,+ permission_manage_orders,+):+ fulfillment_id = graphene.Node.to_global_id("Fulfillment", fulfillment.id)+ tracking = "stationary tracking"+ variables = {"id": fulfillment_id, "tracking": tracking, "notifyCustomer": True}+ response = staff_api_client.post_graphql(+ FULFILLMENT_UPDATE_TRACKING_WITH_SEND_NOTIFICATION_QUERY,+ variables,+ permissions=[permission_manage_orders],+ )+ content = get_graphql_content(response)+ data = content["data"]["orderFulfillmentUpdateTracking"]["fulfillment"]+ assert data["trackingNumber"] == tracking+ send_fulfillment_update_mock.assert_called_once_with(+ fulfillment.order.pk, fulfillment.pk+ )+++@patch("saleor.order.emails.send_fulfillment_update.delay")+def test_fulfillment_update_tracking_send_notification_false(+ send_fulfillment_update_mock,+ staff_api_client,+ fulfillment,+ permission_manage_orders,+):+ fulfillment_id = graphene.Node.to_global_id("Fulfillment", fulfillment.id)+ tracking = "stationary tracking"+ variables = {"id": fulfillment_id, "tracking": tracking, "notifyCustomer": False}+ response = staff_api_client.post_graphql(+ FULFILLMENT_UPDATE_TRACKING_WITH_SEND_NOTIFICATION_QUERY,+ variables,+ permissions=[permission_manage_orders],+ )+ content = get_graphql_content(response)+ data = content["data"]["orderFulfillmentUpdateTracking"]["fulfillment"]+ assert data["trackingNumber"] == tracking+ send_fulfillment_update_mock.assert_not_called()def test_cancel_fulfillment_restock_items(