Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Extend stock related webhooks with webhooks events info (#19158)
Iga Karbowiakfad44b00bebd
diff --git a/saleor/graphql/product/bulk_mutations/product_variant_stocks_create.py b/saleor/graphql/product/bulk_mutations/product_variant_stocks_create.pyindex dd7324a610..84d915363a 100644--- a/saleor/graphql/product/bulk_mutations/product_variant_stocks_create.py+++ b/saleor/graphql/product/bulk_mutations/product_variant_stocks_create.py@@ -20,6 +20,7 @@ from ...core.context import ChannelContextfrom ...core.doc_category import DOC_CATEGORY_PRODUCTSfrom ...core.mutations import BaseMutationfrom ...core.types import BulkStockError, NonNullList+from ...core.utils import WebhookEventInfofrom ...site.dataloaders import get_site_promisefrom ...utils import get_user_or_app_from_contextfrom ...warehouse.dataloaders import StocksByProductVariantIdLoader@@ -51,6 +52,34 @@ class ProductVariantStocksCreate(BaseMutation):permissions = (ProductPermissions.MANAGE_PRODUCTS,)error_type_class = BulkStockErrorerror_type_field = "bulk_stock_errors"+ webhook_events_info = [+ WebhookEventInfo(+ type=WebhookEventAsyncType.PRODUCT_VARIANT_BACK_IN_STOCK,+ description=("A product variant stock is created in a warehouse."),+ ),+ WebhookEventInfo(+ type=WebhookEventAsyncType.PRODUCT_VARIANT_BACK_IN_STOCK_IN_CHANNEL,+ description=(+ "A product variant is back in stock in a channel "+ "(non click-and-collect warehouses)."+ "\n\nNote: Triggered only when the "+ "`useLegacyShippingZoneStockAvailability` shop setting is "+ "disabled."+ ),+ ),+ WebhookEventInfo(+ type=(+ WebhookEventAsyncType.PRODUCT_VARIANT_BACK_IN_STOCK_FOR_CLICK_AND_COLLECT+ ),+ description=(+ "A product variant is back in stock in a channel "+ "(click-and-collect warehouses)."+ "\n\nNote: Triggered only when the "+ "`useLegacyShippingZoneStockAvailability` shop setting is "+ "disabled."+ ),+ ),+ ]@classmethod@traced_atomic_transaction()diff --git a/saleor/graphql/product/bulk_mutations/product_variant_stocks_delete.py b/saleor/graphql/product/bulk_mutations/product_variant_stocks_delete.pyindex 87e6d78259..c5493356d4 100644--- a/saleor/graphql/product/bulk_mutations/product_variant_stocks_delete.py+++ b/saleor/graphql/product/bulk_mutations/product_variant_stocks_delete.py@@ -20,6 +20,7 @@ from ...core.context import ChannelContextfrom ...core.doc_category import DOC_CATEGORY_PRODUCTSfrom ...core.mutations import BaseMutationfrom ...core.types import NonNullList, StockError+from ...core.utils import WebhookEventInfofrom ...core.validators import validate_one_of_args_is_in_mutationfrom ...site.dataloaders import get_site_promisefrom ...utils import get_user_or_app_from_context@@ -52,6 +53,34 @@ class ProductVariantStocksDelete(BaseMutation):permissions = (ProductPermissions.MANAGE_PRODUCTS,)error_type_class = StockErrorerror_type_field = "stock_errors"+ webhook_events_info = [+ WebhookEventInfo(+ type=WebhookEventAsyncType.PRODUCT_VARIANT_OUT_OF_STOCK,+ description=("A product variant stock is deleted from a warehouse."),+ ),+ WebhookEventInfo(+ type=WebhookEventAsyncType.PRODUCT_VARIANT_OUT_OF_STOCK_IN_CHANNEL,+ description=(+ "A product variant is out of stock in a channel "+ "(non click-and-collect warehouses)."+ "\n\nNote: Triggered only when the "+ "`useLegacyShippingZoneStockAvailability` shop setting is "+ "disabled."+ ),+ ),+ WebhookEventInfo(+ type=(+ WebhookEventAsyncType.PRODUCT_VARIANT_OUT_OF_STOCK_FOR_CLICK_AND_COLLECT+ ),+ description=(+ "A product variant is out of stock in a channel "+ "(click-and-collect warehouses)."+ "\n\nNote: Triggered only when the "+ "`useLegacyShippingZoneStockAvailability` shop setting is "+ "disabled."+ ),+ ),+ ]@classmethod@traced_atomic_transaction()diff --git a/saleor/graphql/product/bulk_mutations/product_variant_stocks_update.py b/saleor/graphql/product/bulk_mutations/product_variant_stocks_update.pyindex a7f3ad0d2b..8501f7014b 100644--- a/saleor/graphql/product/bulk_mutations/product_variant_stocks_update.py+++ b/saleor/graphql/product/bulk_mutations/product_variant_stocks_update.py@@ -24,6 +24,7 @@ from ...core import ResolveInfofrom ...core.context import ChannelContextfrom ...core.doc_category import DOC_CATEGORY_PRODUCTSfrom ...core.types import BulkStockError, NonNullList+from ...core.utils import WebhookEventInfofrom ...core.validators import validate_one_of_args_is_in_mutationfrom ...site.dataloaders import get_site_promisefrom ...utils import get_user_or_app_from_context@@ -41,6 +42,70 @@ class ProductVariantStocksUpdate(ProductVariantStocksCreate):permissions = (ProductPermissions.MANAGE_PRODUCTS,)error_type_class = BulkStockErrorerror_type_field = "bulk_stock_errors"+ webhook_events_info = [+ WebhookEventInfo(+ type=WebhookEventAsyncType.PRODUCT_VARIANT_STOCK_UPDATED,+ description="A product variant stock is updated.",+ ),+ WebhookEventInfo(+ type=WebhookEventAsyncType.PRODUCT_VARIANT_BACK_IN_STOCK,+ description=(+ "A product variant stock transitioned from no availability "+ "to available quantity."+ ),+ ),+ WebhookEventInfo(+ type=WebhookEventAsyncType.PRODUCT_VARIANT_OUT_OF_STOCK,+ description=(+ "A product variant stock transitioned from available "+ "quantity to no availability."+ ),+ ),+ WebhookEventInfo(+ type=WebhookEventAsyncType.PRODUCT_VARIANT_BACK_IN_STOCK_IN_CHANNEL,+ description=(+ "A product variant is back in stock in a channel "+ "(non click-and-collect warehouses)."+ "\n\nNote: Triggered only when the "+ "`useLegacyShippingZoneStockAvailability` shop setting is "+ "disabled."+ ),+ ),+ WebhookEventInfo(+ type=WebhookEventAsyncType.PRODUCT_VARIANT_OUT_OF_STOCK_IN_CHANNEL,+ description=(+ "A product variant is out of stock in a channel "+ "(non click-and-collect warehouses)."+ "\n\nNote: Triggered only when the "+ "`useLegacyShippingZoneStockAvailability` shop setting is "+ "disabled."+ ),+ ),+ WebhookEventInfo(+ type=(+ WebhookEventAsyncType.PRODUCT_VARIANT_BACK_IN_STOCK_FOR_CLICK_AND_COLLECT+ ),+ description=(+ "A product variant is back in stock in a channel "+ "(click-and-collect warehouses)."+ "\n\nNote: Triggered only when the "+ "`useLegacyShippingZoneStockAvailability` shop setting is "+ "disabled."+ ),+ ),+ WebhookEventInfo(+ type=(+ WebhookEventAsyncType.PRODUCT_VARIANT_OUT_OF_STOCK_FOR_CLICK_AND_COLLECT+ ),+ description=(+ "A product variant is out of stock in a channel "+ "(click-and-collect warehouses)."+ "\n\nNote: Triggered only when the "+ "`useLegacyShippingZoneStockAvailability` shop setting is "+ "disabled."+ ),+ ),+ ]class Arguments:variant_id = graphene.ID(diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex aec7f450a0..b56b6960ea 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -17538,11 +17538,21 @@ type Mutation {Deletes selected warehouse.Requires one of the following permissions: MANAGE_PRODUCTS.++ Triggers the following webhook events:+ - WAREHOUSE_DELETED (async): A warehouse is deleted.+ - PRODUCT_VARIANT_OUT_OF_STOCK (async): A product variant stock is removed together with the deleted warehouse.+ - PRODUCT_VARIANT_OUT_OF_STOCK_IN_CHANNEL (async): A product variant is out of stock in a channel (non click-and-collect warehouses).++ Note: Triggered only when the `useLegacyShippingZoneStockAvailability` shop setting is disabled.+ - PRODUCT_VARIANT_OUT_OF_STOCK_FOR_CLICK_AND_COLLECT (async): A product variant is out of stock in a channel (click-and-collect warehouses).++ Note: Triggered only when the `useLegacyShippingZoneStockAvailability` shop setting is disabled."""deleteWarehouse("""ID of a warehouse to delete."""id: ID!- ): WarehouseDelete @doc(category: "Products")+ ): WarehouseDelete @doc(category: "Products") @webhookEventsInfo(asyncEvents: [WAREHOUSE_DELETED, PRODUCT_VARIANT_OUT_OF_STOCK, PRODUCT_VARIANT_OUT_OF_STOCK_IN_CHANNEL, PRODUCT_VARIANT_OUT_OF_STOCK_FOR_CLICK_AND_COLLECT], syncEvents: [])"""Add shipping zone to given warehouse.@@ -18493,6 +18503,15 @@ type Mutation {Creates stocks for product variant.Requires one of the following permissions: MANAGE_PRODUCTS.++ Triggers the following webhook events:+ - PRODUCT_VARIANT_BACK_IN_STOCK (async): A product variant stock is created in a warehouse.+ - PRODUCT_VARIANT_BACK_IN_STOCK_IN_CHANNEL (async): A product variant is back in stock in a channel (non click-and-collect warehouses).++ Note: Triggered only when the `useLegacyShippingZoneStockAvailability` shop setting is disabled.+ - PRODUCT_VARIANT_BACK_IN_STOCK_FOR_CLICK_AND_COLLECT (async): A product variant is back in stock in a channel (click-and-collect warehouses).++ Note: Triggered only when the `useLegacyShippingZoneStockAvailability` shop setting is disabled."""productVariantStocksCreate("""Input list of stocks to create."""@@ -18500,12 +18519,21 @@ type Mutation {"""ID of a product variant for which stocks will be created."""variantId: ID!- ): ProductVariantStocksCreate @doc(category: "Products")+ ): ProductVariantStocksCreate @doc(category: "Products") @webhookEventsInfo(asyncEvents: [PRODUCT_VARIANT_BACK_IN_STOCK, PRODUCT_VARIANT_BACK_IN_STOCK_IN_CHANNEL, PRODUCT_VARIANT_BACK_IN_STOCK_FOR_CLICK_AND_COLLECT], syncEvents: [])"""Deletes stocks from product variant.Requires one of the following permissions: MANAGE_PRODUCTS.++ Triggers the following webhook events:+ - PRODUCT_VARIANT_OUT_OF_STOCK (async): A product variant stock is deleted from a warehouse.+ - PRODUCT_VARIANT_OUT_OF_STOCK_IN_CHANNEL (async): A product variant is out of stock in a channel (non click-and-collect warehouses).++ Note: Triggered only when the `useLegacyShippingZoneStockAvailability` shop setting is disabled.+ - PRODUCT_VARIANT_OUT_OF_STOCK_FOR_CLICK_AND_COLLECT (async): A product variant is out of stock in a channel (click-and-collect warehouses).++ Note: Triggered only when the `useLegacyShippingZoneStockAvailability` shop setting is disabled."""productVariantStocksDelete("""SKU of product variant for which stocks will be deleted."""@@ -18516,12 +18544,29 @@ type Mutation {"""Input list of warehouse IDs."""warehouseIds: [ID!]- ): ProductVariantStocksDelete @doc(category: "Products")+ ): ProductVariantStocksDelete @doc(category: "Products") @webhookEventsInfo(asyncEvents: [PRODUCT_VARIANT_OUT_OF_STOCK, PRODUCT_VARIANT_OUT_OF_STOCK_IN_CHANNEL, PRODUCT_VARIANT_OUT_OF_STOCK_FOR_CLICK_AND_COLLECT], syncEvents: [])"""Updates stocks for product variant.Requires one of the following permissions: MANAGE_PRODUCTS.++ Triggers the following webhook events:+ - PRODUCT_VARIANT_STOCK_UPDATED (async): A product variant stock is updated.+ - PRODUCT_VARIANT_BACK_IN_STOCK (async): A product variant stock transitioned from no availability to available quantity.+ - PRODUCT_VARIANT_OUT_OF_STOCK (async): A product variant stock transitioned from available quantity to no availability.+ - PRODUCT_VARIANT_BACK_IN_STOCK_IN_CHANNEL (async): A product variant is back in stock in a channel (non click-and-collect warehouses).++ Note: Triggered only when the `useLegacyShippingZoneStockAvailability` shop setting is disabled.+ - PRODUCT_VARIANT_OUT_OF_STOCK_IN_CHANNEL (async): A product variant is out of stock in a channel (non click-and-collect warehouses).++ Note: Triggered only when the `useLegacyShippingZoneStockAvailability` shop setting is disabled.+ - PRODUCT_VARIANT_BACK_IN_STOCK_FOR_CLICK_AND_COLLECT (async): A product variant is back in stock in a channel (click-and-collect warehouses).++ Note: Triggered only when the `useLegacyShippingZoneStockAvailability` shop setting is disabled.+ - PRODUCT_VARIANT_OUT_OF_STOCK_FOR_CLICK_AND_COLLECT (async): A product variant is out of stock in a channel (click-and-collect warehouses).++ Note: Triggered only when the `useLegacyShippingZoneStockAvailability` shop setting is disabled."""productVariantStocksUpdate("""SKU of product variant for which stocks will be updated."""@@ -18532,7 +18577,7 @@ type Mutation {"""ID of a product variant for which stocks will be updated."""variantId: ID- ): ProductVariantStocksUpdate @doc(category: "Products")+ ): ProductVariantStocksUpdate @doc(category: "Products") @webhookEventsInfo(asyncEvents: [PRODUCT_VARIANT_STOCK_UPDATED, PRODUCT_VARIANT_BACK_IN_STOCK, PRODUCT_VARIANT_OUT_OF_STOCK, PRODUCT_VARIANT_BACK_IN_STOCK_IN_CHANNEL, PRODUCT_VARIANT_OUT_OF_STOCK_IN_CHANNEL, PRODUCT_VARIANT_BACK_IN_STOCK_FOR_CLICK_AND_COLLECT, PRODUCT_VARIANT_OUT_OF_STOCK_FOR_CLICK_AND_COLLECT], syncEvents: [])"""Updates an existing variant for product.@@ -22429,8 +22474,18 @@ input WarehouseUpdateInput @doc(category: "Products") {Deletes selected warehouse.Requires one of the following permissions: MANAGE_PRODUCTS.++Triggers the following webhook events:+- WAREHOUSE_DELETED (async): A warehouse is deleted.+- PRODUCT_VARIANT_OUT_OF_STOCK (async): A product variant stock is removed together with the deleted warehouse.+- PRODUCT_VARIANT_OUT_OF_STOCK_IN_CHANNEL (async): A product variant is out of stock in a channel (non click-and-collect warehouses).++Note: Triggered only when the `useLegacyShippingZoneStockAvailability` shop setting is disabled.+- PRODUCT_VARIANT_OUT_OF_STOCK_FOR_CLICK_AND_COLLECT (async): A product variant is out of stock in a channel (click-and-collect warehouses).++Note: Triggered only when the `useLegacyShippingZoneStockAvailability` shop setting is disabled."""-type WarehouseDelete @doc(category: "Products") {+type WarehouseDelete @doc(category: "Products") @webhookEventsInfo(asyncEvents: [WAREHOUSE_DELETED, PRODUCT_VARIANT_OUT_OF_STOCK, PRODUCT_VARIANT_OUT_OF_STOCK_IN_CHANNEL, PRODUCT_VARIANT_OUT_OF_STOCK_FOR_CLICK_AND_COLLECT], syncEvents: []) {warehouseErrors: [WarehouseError!]! @deprecated(reason: "Use `errors` field instead.")errors: [WarehouseError!]!warehouse: Warehouse@@ -25398,8 +25453,17 @@ type ProductVariantBulkDelete @doc(category: "Products") {Creates stocks for product variant.Requires one of the following permissions: MANAGE_PRODUCTS.++Triggers the following webhook events:+- PRODUCT_VARIANT_BACK_IN_STOCK (async): A product variant stock is created in a warehouse.+- PRODUCT_VARIANT_BACK_IN_STOCK_IN_CHANNEL (async): A product variant is back in stock in a channel (non click-and-collect warehouses).++Note: Triggered only when the `useLegacyShippingZoneStockAvailability` shop setting is disabled.+- PRODUCT_VARIANT_BACK_IN_STOCK_FOR_CLICK_AND_COLLECT (async): A product variant is back in stock in a channel (click-and-collect warehouses).++Note: Triggered only when the `useLegacyShippingZoneStockAvailability` shop setting is disabled."""-type ProductVariantStocksCreate @doc(category: "Products") {+type ProductVariantStocksCreate @doc(category: "Products") @webhookEventsInfo(asyncEvents: [PRODUCT_VARIANT_BACK_IN_STOCK, PRODUCT_VARIANT_BACK_IN_STOCK_IN_CHANNEL, PRODUCT_VARIANT_BACK_IN_STOCK_FOR_CLICK_AND_COLLECT], syncEvents: []) {"""Updated product variant."""productVariant: ProductVariantbulkStockErrors: [BulkStockError!]! @deprecated(reason: "Use `errors` field instead.")@@ -25432,8 +25496,17 @@ type BulkStockError @doc(category: "Products") {Deletes stocks from product variant.Requires one of the following permissions: MANAGE_PRODUCTS.++Triggers the following webhook events:+- PRODUCT_VARIANT_OUT_OF_STOCK (async): A product variant stock is deleted from a warehouse.+- PRODUCT_VARIANT_OUT_OF_STOCK_IN_CHANNEL (async): A product variant is out of stock in a channel (non click-and-collect warehouses).++Note: Triggered only when the `useLegacyShippingZoneStockAvailability` shop setting is disabled.+- PRODUCT_VARIANT_OUT_OF_STOCK_FOR_CLICK_AND_COLLECT (async): A product variant is out of stock in a channel (click-and-collect warehouses).++Note: Triggered only when the `useLegacyShippingZoneStockAvailability` shop setting is disabled."""-type ProductVariantStocksDelete @doc(category: "Products") {+type ProductVariantStocksDelete @doc(category: "Products") @webhookEventsInfo(asyncEvents: [PRODUCT_VARIANT_OUT_OF_STOCK, PRODUCT_VARIANT_OUT_OF_STOCK_IN_CHANNEL, PRODUCT_VARIANT_OUT_OF_STOCK_FOR_CLICK_AND_COLLECT], syncEvents: []) {"""Updated product variant."""productVariant: ProductVariantstockErrors: [StockError!]! @deprecated(reason: "Use `errors` field instead.")@@ -25466,8 +25539,25 @@ enum StockErrorCode @doc(category: "Products") {Updates stocks for product variant.Requires one of the following permissions: MANAGE_PRODUCTS.++Triggers the following webhook events:+- PRODUCT_VARIANT_STOCK_UPDATED (async): A product variant stock is updated.+- PRODUCT_VARIANT_BACK_IN_STOCK (async): A product variant stock transitioned from no availability to available quantity.+- PRODUCT_VARIANT_OUT_OF_STOCK (async): A product variant stock transitioned from available quantity to no availability.+- PRODUCT_VARIANT_BACK_IN_STOCK_IN_CHANNEL (async): A product variant is back in stock in a channel (non click-and-collect warehouses).++Note: Triggered only when the `useLegacyShippingZoneStockAvailability` shop setting is disabled.+- PRODUCT_VARIANT_OUT_OF_STOCK_IN_CHANNEL (async): A product variant is out of stock in a channel (non click-and-collect warehouses).++Note: Triggered only when the `useLegacyShippingZoneStockAvailability` shop setting is disabled.+- PRODUCT_VARIANT_BACK_IN_STOCK_FOR_CLICK_AND_COLLECT (async): A product variant is back in stock in a channel (click-and-collect warehouses).++Note: Triggered only when the `useLegacyShippingZoneStockAvailability` shop setting is disabled.+- PRODUCT_VARIANT_OUT_OF_STOCK_FOR_CLICK_AND_COLLECT (async): A product variant is out of stock in a channel (click-and-collect warehouses).++Note: Triggered only when the `useLegacyShippingZoneStockAvailability` shop setting is disabled."""-type ProductVariantStocksUpdate @doc(category: "Products") {+type ProductVariantStocksUpdate @doc(category: "Products") @webhookEventsInfo(asyncEvents: [PRODUCT_VARIANT_STOCK_UPDATED, PRODUCT_VARIANT_BACK_IN_STOCK, PRODUCT_VARIANT_OUT_OF_STOCK, PRODUCT_VARIANT_BACK_IN_STOCK_IN_CHANNEL, PRODUCT_VARIANT_OUT_OF_STOCK_IN_CHANNEL, PRODUCT_VARIANT_BACK_IN_STOCK_FOR_CLICK_AND_COLLECT, PRODUCT_VARIANT_OUT_OF_STOCK_FOR_CLICK_AND_COLLECT], syncEvents: []) {"""Updated product variant."""productVariant: ProductVariantbulkStockErrors: [BulkStockError!]! @deprecated(reason: "Use `errors` field instead.")diff --git a/saleor/graphql/warehouse/mutations/warehouse_delete.py b/saleor/graphql/warehouse/mutations/warehouse_delete.pyindex 2e05a92b08..ba7f33fe03 100644--- a/saleor/graphql/warehouse/mutations/warehouse_delete.py+++ b/saleor/graphql/warehouse/mutations/warehouse_delete.py@@ -11,9 +11,11 @@ from ....warehouse.channel_stock_availability import (from ....warehouse.webhooks.stock_events import (trigger_product_variant_out_of_stock,)+from ....webhook.event_types import WebhookEventAsyncTypefrom ...core import ResolveInfofrom ...core.mutations import ModelDeleteMutationfrom ...core.types import WarehouseError+from ...core.utils import WebhookEventInfofrom ...plugins.dataloaders import get_plugin_manager_promisefrom ...site.dataloaders import get_site_promisefrom ...utils import get_user_or_app_from_context@@ -28,6 +30,41 @@ class WarehouseDelete(ModelDeleteMutation):description = "Deletes selected warehouse."error_type_class = WarehouseErrorerror_type_field = "warehouse_errors"+ webhook_events_info = [+ WebhookEventInfo(+ type=WebhookEventAsyncType.WAREHOUSE_DELETED,+ description="A warehouse is deleted.",+ ),+ WebhookEventInfo(+ type=WebhookEventAsyncType.PRODUCT_VARIANT_OUT_OF_STOCK,+ description=(+ "A product variant stock is removed together with the "+ "deleted warehouse."+ ),+ ),+ WebhookEventInfo(+ type=WebhookEventAsyncType.PRODUCT_VARIANT_OUT_OF_STOCK_IN_CHANNEL,+ description=(+ "A product variant is out of stock in a channel "+ "(non click-and-collect warehouses)."+ "\n\nNote: Triggered only when the "+ "`useLegacyShippingZoneStockAvailability` shop setting is "+ "disabled."+ ),+ ),+ WebhookEventInfo(+ type=(+ WebhookEventAsyncType.PRODUCT_VARIANT_OUT_OF_STOCK_FOR_CLICK_AND_COLLECT+ ),+ description=(+ "A product variant is out of stock in a channel "+ "(click-and-collect warehouses)."+ "\n\nNote: Triggered only when the "+ "`useLegacyShippingZoneStockAvailability` shop setting is "+ "disabled."+ ),+ ),+ ]class Arguments:id = graphene.ID(description="ID of a warehouse to delete.", required=True)