Skip to content

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

Update order settings to include automatically_fulfill_non_shippable_gift_card option

Tomasz Szymanskia0ae3926f970
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index bee969b371..e2ac230c82 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -4453,6 +4453,7 @@ type OrderSettingsUpdate {
input OrderSettingsUpdateInput {
automaticallyConfirmAllNewOrders: Boolean!
+ automaticallyFulfillNonShippableGiftCard: Boolean!
}
enum OrderSortField {
diff --git a/saleor/graphql/shop/mutations.py b/saleor/graphql/shop/mutations.py
index 3e73e1a979..cba4cf1f53 100644
--- a/saleor/graphql/shop/mutations.py
+++ b/saleor/graphql/shop/mutations.py
@@ -307,6 +307,11 @@ class OrderSettingsUpdateInput(graphene.InputObjectType):
"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.",
+ )
class OrderSettingsUpdate(BaseMutation):
@@ -329,7 +334,15 @@ class OrderSettingsUpdate(BaseMutation):
instance.automatically_confirm_all_new_orders = data["input"][
"automatically_confirm_all_new_orders"
]
- instance.save(update_fields=["automatically_confirm_all_new_orders"])
+ instance.automatically_fulfill_non_shippable_gift_card = data["input"][
+ "automatically_fulfill_non_shippable_gift_card"
+ ]
+ instance.save(
+ update_fields=[
+ "automatically_confirm_all_new_orders",
+ "automatically_fulfill_non_shippable_gift_card",
+ ]
+ )
return OrderSettingsUpdate(order_settings=instance)
diff --git a/saleor/graphql/shop/tests/test_shop.py b/saleor/graphql/shop/tests/test_shop.py
index c9310fdad6..0e5ac2101d 100644
--- a/saleor/graphql/shop/tests/test_shop.py
+++ b/saleor/graphql/shop/tests/test_shop.py
@@ -1205,10 +1205,14 @@ def test_staff_notification_update_mutation_with_empty_email(
ORDER_SETTINGS_UPDATE_MUTATION = """
mutation orderSettings($confirmOrders: Boolean!) {
orderSettingsUpdate(
- input: { automaticallyConfirmAllNewOrders: $confirmOrders }
+ input: {
+ automaticallyConfirmAllNewOrders: $confirmOrders
+ automaticallyFulfillNonShippableGiftCard: $fulfillGiftCards
+ }
) {
orderSettings {
automaticallyConfirmAllNewOrders
+ automaticallyFulfillNonShippableGiftCard
}
}
}
@@ -1221,11 +1225,13 @@ def test_order_settings_update_by_staff(
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, {"confirmOrders": False}
+ ORDER_SETTINGS_UPDATE_MUTATION,
+ {"confirmOrders": False, "fulfillGiftCards": False},
)
content = get_graphql_content(response)
response_settings = content["data"]["orderSettingsUpdate"]["orderSettings"]
assert response_settings["automaticallyConfirmAllNewOrders"] is False
+ assert response_settings["automaticallyFulfillNonShippableGiftCard"] is False
site_settings.refresh_from_db()
assert site_settings.automatically_confirm_all_new_orders is False
@@ -1236,11 +1242,13 @@ def test_order_settings_update_by_app(
assert site_settings.automatically_confirm_all_new_orders is True
app_api_client.app.permissions.set([permission_manage_orders])
response = app_api_client.post_graphql(
- ORDER_SETTINGS_UPDATE_MUTATION, {"confirmOrders": False}
+ ORDER_SETTINGS_UPDATE_MUTATION,
+ {"confirmOrders": False, "fulfillGiftCards": False},
)
content = get_graphql_content(response)
response_settings = content["data"]["orderSettingsUpdate"]["orderSettings"]
assert response_settings["automaticallyConfirmAllNewOrders"] is False
+ assert response_settings["automaticallyFulfillNonShippableGiftCard"] is False
site_settings.refresh_from_db()
assert site_settings.automatically_confirm_all_new_orders is False
@@ -1261,6 +1269,7 @@ ORDER_SETTINGS_QUERY = """
query orderSettings {
orderSettings {
automaticallyConfirmAllNewOrders
+ automaticallyFulfillNonShippableGiftCard
}
}
"""
@@ -1270,15 +1279,28 @@ def test_order_settings_query_as_staff(
staff_api_client, permission_manage_orders, site_settings
):
assert site_settings.automatically_confirm_all_new_orders is True
+ assert site_settings.automatically_fulfill_non_shippable_gift_card is True
site_settings.automatically_confirm_all_new_orders = False
- site_settings.save(update_fields=["automatically_confirm_all_new_orders"])
+ site_settings.automatically_fulfill_non_shippable_gift_card = False
+ site_settings.save(
+ update_fields=[
+ "automatically_confirm_all_new_orders",
+ "automatically_fulfill_non_shippable_gift_card",
+ ]
+ )
staff_api_client.user.user_permissions.add(permission_manage_orders)
response = staff_api_client.post_graphql(ORDER_SETTINGS_QUERY)
content = get_graphql_content(response)
assert content["data"]["orderSettings"]["automaticallyConfirmAllNewOrders"] is False
+ assert (
+ content["data"]["orderSettings"][
+ "automatically_fulfill_non_shippable_gift_card"
+ ]
+ is False
+ )
def test_order_settings_query_as_user(user_api_client, site_settings):
diff --git a/saleor/site/migrations/0032_gift_card_settings.py b/saleor/site/migrations/0032_gift_card_settings.py
index 4020b4693c..b8edc5a5df 100644
--- a/saleor/site/migrations/0032_gift_card_settings.py
+++ b/saleor/site/migrations/0032_gift_card_settings.py
@@ -10,6 +10,11 @@ class Migration(migrations.Migration):
]
operations = [
+ migrations.AddField(
+ model_name="sitesettings",
+ name="automatically_fulfill_non_shippable_gift_card",
+ field=models.BooleanField(default=True),
+ ),
migrations.AddField(
model_name="sitesettings",
name="gift_card_expiry_period",
diff --git a/saleor/site/models.py b/saleor/site/models.py
index d826afa518..56c075ed9e 100644
--- a/saleor/site/models.py
+++ b/saleor/site/models.py
@@ -80,6 +80,7 @@ class SiteSettings(models.Model):
max_length=32, choices=TimePeriodType.CHOICES, null=True, blank=True
)
gift_card_expiry_period = models.PositiveIntegerField(null=True, blank=True)
+ automatically_fulfill_non_shippable_gift_card = models.BooleanField(default=True)
translated = TranslationProxy()