Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Make settings fields optional
Tomasz Szymanskibd0c56fc787e
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 1d6f3a043f..dd5948bd67 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -4453,8 +4453,8 @@ type OrderSettingsUpdate {}input OrderSettingsUpdateInput {- automaticallyConfirmAllNewOrders: Boolean!- automaticallyFulfillNonShippableGiftCard: Boolean!+ automaticallyConfirmAllNewOrders: Boolean+ automaticallyFulfillNonShippableGiftCard: Boolean}enum OrderSortField {diff --git a/saleor/graphql/shop/mutations.py b/saleor/graphql/shop/mutations.pyindex cba4cf1f53..68e22888f5 100644--- a/saleor/graphql/shop/mutations.py+++ b/saleor/graphql/shop/mutations.py@@ -302,15 +302,15 @@ class StaffNotificationRecipientDelete(ModelDeleteMutation):class OrderSettingsUpdateInput(graphene.InputObjectType):automatically_confirm_all_new_orders = graphene.Boolean(- required=True,+ required=False,description="When disabled, all new orders from checkout ""will be marked as unconfirmed. When enabled orders from checkout will ""become unfulfilled immediately.",)automatically_fulfill_non_shippable_gift_card = graphene.Boolean(- required=True,- description="When disabled, all new non shippable gift cards "- "will require manual fulfillment.",+ required=False,+ description="When enabled, all non-shippable gift card orders "+ "will be fulfilled automatically.",)@@ -330,19 +330,21 @@ class OrderSettingsUpdate(BaseMutation):@classmethoddef perform_mutation(cls, _root, info, **data):- instance = info.context.site.settings- instance.automatically_confirm_all_new_orders = data["input"][- "automatically_confirm_all_new_orders"- ]- instance.automatically_fulfill_non_shippable_gift_card = data["input"][- "automatically_fulfill_non_shippable_gift_card"+ FIELDS = [+ "automatically_confirm_all_new_orders",+ "automatically_fulfill_non_shippable_gift_card",]- instance.save(- update_fields=[- "automatically_confirm_all_new_orders",- "automatically_fulfill_non_shippable_gift_card",- ]- )++ instance = info.context.site.settings+ update_fields = []+ for field in FIELDS:+ value = data["input"].get(field)+ if value is not None:+ setattr(instance, field, value)+ update_fields.append(field)++ if update_fields:+ instance.save(update_fields=update_fields)return OrderSettingsUpdate(order_settings=instance)diff --git a/saleor/graphql/shop/tests/test_shop.py b/saleor/graphql/shop/tests/test_shop.pyindex b471f8ff4a..25b1be688f 100644--- a/saleor/graphql/shop/tests/test_shop.py+++ b/saleor/graphql/shop/tests/test_shop.py@@ -1203,7 +1203,7 @@ def test_staff_notification_update_mutation_with_empty_email(ORDER_SETTINGS_UPDATE_MUTATION = """- mutation orderSettings($confirmOrders: Boolean!, $fulfillGiftCards: Boolean!) {+ mutation orderSettings($confirmOrders: Boolean, $fulfillGiftCards: Boolean) {orderSettingsUpdate(input: {automaticallyConfirmAllNewOrders: $confirmOrders@@ -1237,6 +1237,24 @@ def test_order_settings_update_by_staff(assert site_settings.automatically_fulfill_non_shippable_gift_card is False+def test_order_settings_update_by_staff_nothing_changed(+ staff_api_client, permission_manage_orders, site_settings+):+ assert site_settings.automatically_confirm_all_new_orders is True+ staff_api_client.user.user_permissions.add(permission_manage_orders)+ response = staff_api_client.post_graphql(+ ORDER_SETTINGS_UPDATE_MUTATION,+ {},+ )+ content = get_graphql_content(response)+ response_settings = content["data"]["orderSettingsUpdate"]["orderSettings"]+ assert response_settings["automaticallyConfirmAllNewOrders"] is True+ assert response_settings["automaticallyFulfillNonShippableGiftCard"] is True+ site_settings.refresh_from_db()+ assert site_settings.automatically_confirm_all_new_orders is True+ assert site_settings.automatically_fulfill_non_shippable_gift_card is True++def test_order_settings_update_by_app(app_api_client, permission_manage_orders, site_settings):