Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add external reference to updateWarehouse (#13695)
Smit Parmar166279c3173d
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 461352d947..f624bcda23 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -14,6 +14,8 @@ in 3.17. Use `PaymentSettings.defaultTransactionFlowStrategy` instead.### GraphQL API- Add `storedPaymentMethodRequestDelete` mutation - #13660 by @korycins- Add `PaymentSettings` to `Channel` - #13677 by @korycins+- Add `externalReference` to `updateWarehouse`. It will allow update warehouse by+ external reference. - #13342 by @Smit-Parmar### Saleor Apps- Add `STORED_PAYMENT_METHOD_DELETE_REQUESTED` webhook event - #13660 by @korycins@@ -122,7 +124,6 @@ Shipping methods can be removed by the user after it has been assigned to a chec- Add `CheckoutLine.problems` field- Add `CheckoutSettingsInput` to `ChannelCreateInput` & `ChannelUpdateInput`- Add `checkoutSettings` field to `Channel`-### Saleor Apps- Introduce `Saleor-Schema-Version` HTTP header in app manifest fetching and app installation handshake requests. - #13075 by @przladadiff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 4109a1561a..69e78aa910 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -14159,8 +14159,15 @@ type Mutation {Requires one of the following permissions: MANAGE_PRODUCTS."""updateWarehouse(+ """+ External reference of a warehouse.++ Added in Saleor 3.16.+ """+ externalReference: String+"""ID of a warehouse to update."""- id: ID!+ id: ID"""Fields required to update warehouse."""input: WarehouseUpdateInput!diff --git a/saleor/graphql/warehouse/mutations/warehouse_update.py b/saleor/graphql/warehouse/mutations/warehouse_update.pyindex 7a23f8530c..e7aa20489e 100644--- a/saleor/graphql/warehouse/mutations/warehouse_update.py+++ b/saleor/graphql/warehouse/mutations/warehouse_update.py@@ -4,14 +4,15 @@ from ....permission.enums import ProductPermissionsfrom ....warehouse import modelsfrom ...account.i18n import I18nMixinfrom ...core import ResolveInfo-from ...core.mutations import ModelMutation+from ...core.descriptions import ADDED_IN_316+from ...core.mutations import ModelWithExtRefMutationfrom ...core.types import WarehouseErrorfrom ...plugins.dataloaders import get_plugin_manager_promisefrom ..types import Warehouse, WarehouseUpdateInputfrom .base import WarehouseMixin-class WarehouseUpdate(WarehouseMixin, ModelMutation, I18nMixin):+class WarehouseUpdate(WarehouseMixin, ModelWithExtRefMutation):class Meta:model = models.Warehouseobject_type = Warehouse@@ -21,10 +22,14 @@ class WarehouseUpdate(WarehouseMixin, ModelMutation, I18nMixin):error_type_field = "warehouse_errors"class Arguments:- id = graphene.ID(description="ID of a warehouse to update.", required=True)+ id = graphene.ID(description="ID of a warehouse to update.", required=False)input = WarehouseUpdateInput(required=True, description="Fields required to update warehouse.")+ external_reference = graphene.String(+ required=False,+ description="External reference of a warehouse." + ADDED_IN_316,+ )@classmethoddef prepare_address(cls, cleaned_data, instance):@@ -35,7 +40,7 @@ class WarehouseUpdate(WarehouseMixin, ModelMutation, I18nMixin):address = instance.addressif address_data is None:return address- address_form = cls.validate_address_form(address_data, instance=address)+ address_form = I18nMixin.validate_address_form(address_data, instance=address)if address_metadata:cls.update_metadata(address, address_metadata)return address_form.save()diff --git a/saleor/graphql/warehouse/tests/mutations/test_warehouse_update.py b/saleor/graphql/warehouse/tests/mutations/test_warehouse_update.pyindex e2ade96ff6..f261647999 100644--- a/saleor/graphql/warehouse/tests/mutations/test_warehouse_update.py+++ b/saleor/graphql/warehouse/tests/mutations/test_warehouse_update.py@@ -464,3 +464,109 @@ def test_update_click_and_collect_option_invalid_input(assert warehouse.is_private == warehouse_is_privateassert warehouse.click_and_collect_option == warehouse_click_and_collect+++MUTATION_UPDATE_WAREHOUSE_BY_EXTERNAL_REFERENCE = """+ mutation updateWarehouse($input: WarehouseUpdateInput!,+ $id: ID, $externalReference: String) {+ updateWarehouse(id: $id, input: $input, externalReference: $externalReference) {+ errors {+ message+ field+ code+ }+ warehouse {+ name+ slug+ externalReference+ }+ }+}+"""+++def test_mutation_update_warehouse_by_external_reference(+ staff_api_client, warehouse, permission_manage_products+):+ # given+ external_reference = "test-ext-ref"+ warehouse.external_reference = external_reference+ warehouse.save(update_fields=["external_reference"])+ variables = {+ "externalReference": external_reference,+ "input": {+ "name": "New name",+ "externalReference": external_reference,+ },+ }++ # when+ response = staff_api_client.post_graphql(+ MUTATION_UPDATE_WAREHOUSE_BY_EXTERNAL_REFERENCE,+ variables=variables,+ permissions=[permission_manage_products],+ )+ content = get_graphql_content(response)++ # then+ warehouse.refresh_from_db()+ data = content["data"]["updateWarehouse"]["warehouse"]+ assert data["name"] == "New name"+ assert warehouse.name == "New name"+ assert warehouse.external_reference == external_reference+++def test_update_warehouse_by_both_id_and_external_reference(+ staff_api_client, warehouse, permission_manage_products+):+ # given+ external_reference = "test-ext-ref"+ warehouse.external_reference = external_reference+ warehouse.save(update_fields=["external_reference"])+ variables = {+ "externalReference": external_reference,+ "id": warehouse.id,+ "input": {"name": "New name"},+ }++ # when+ response = staff_api_client.post_graphql(+ MUTATION_UPDATE_WAREHOUSE_BY_EXTERNAL_REFERENCE,+ variables=variables,+ permissions=[permission_manage_products],+ )+ content = get_graphql_content(response)+ data = content["data"]["updateWarehouse"]+ # then+ assert data["errors"]+ assert (+ data["errors"][0]["message"]+ == "Argument 'id' cannot be combined with 'external_reference'"+ )+++def test_update_product_external_reference_not_existing(+ staff_api_client, permission_manage_products+):+ # given+ external_reference = "non-existing-ext-ref"+ variables = {+ "externalReference": external_reference,+ "input": {},+ }++ # when+ response = staff_api_client.post_graphql(+ MUTATION_UPDATE_WAREHOUSE_BY_EXTERNAL_REFERENCE,+ variables=variables,+ permissions=[permission_manage_products],+ )+ content = get_graphql_content(response)+ data = content["data"]["updateWarehouse"]++ # then+ assert data["errors"]+ assert (+ data["errors"][0]["message"]+ == f"Couldn't resolve to a node: {external_reference}"+ )