Skip to content

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

Shipping zone description (#6653)

Tomasz Szymański26a76cbdc384
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 142448556f..b6e841137d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -23,6 +23,7 @@ All notable, unreleased changes to this project will be documented in this file.
- Drop deprecated fields from the `ProductVariant` type: `quantity`, `quantityAllocated`, `stockQuantity`, `isAvailable` - #6436 by @maarcingebala
- Introduce file attributes - #6568 by @IKarbowiak
- Drop authorization keys API - #6631 by @maarcingebala
+- Shipping zone description - #6653 by @tomaszszymanski129
- Add metadata to menu and menu item - #6648 by @tomaszszymanski129
- Get tax rate from plugins - #6649 by @IKarbowiak
- Add order shipping tax rate - #6678 by @IKarbowiak
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index df3b87fb46..e74a44d247 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -4789,6 +4789,7 @@ type ShippingZone implements Node & ObjectWithMetadata {
countries: [CountryDisplay]
shippingMethods: [ShippingMethod]
warehouses: [Warehouse]
+ description: String
}
type ShippingZoneBulkDelete {
@@ -4816,6 +4817,7 @@ type ShippingZoneCreate {
input ShippingZoneCreateInput {
name: String
+ description: String
countries: [String]
default: Boolean
addWarehouses: [ID]
@@ -4835,6 +4837,7 @@ type ShippingZoneUpdate {
input ShippingZoneUpdateInput {
name: String
+ description: String
countries: [String]
default: Boolean
addWarehouses: [ID]
diff --git a/saleor/graphql/shipping/mutations/shippings.py b/saleor/graphql/shipping/mutations/shippings.py
index 22f4ccfcd4..f6fbefb2b6 100644
--- a/saleor/graphql/shipping/mutations/shippings.py
+++ b/saleor/graphql/shipping/mutations/shippings.py
@@ -46,6 +46,7 @@ class ShippingZoneCreateInput(graphene.InputObjectType):
name = graphene.String(
description="Shipping zone's name. Visible only to the staff."
)
+ description = graphene.String(description="Description of the shipping zone.")
countries = graphene.List(
graphene.String, description="List of countries in this shipping zone."
)
diff --git a/saleor/graphql/shipping/tests/test_shipping_method.py b/saleor/graphql/shipping/tests/test_shipping_method.py
index 00c719730d..0c95585753 100644
--- a/saleor/graphql/shipping/tests/test_shipping_method.py
+++ b/saleor/graphql/shipping/tests/test_shipping_method.py
@@ -260,19 +260,28 @@ def test_shipping_methods_query(
CREATE_SHIPPING_ZONE_QUERY = """
mutation createShipping(
- $name: String, $default: Boolean, $countries: [String], $addWarehouses: [ID] ){
+ $name: String
+ $description: String
+ $default: Boolean
+ $countries: [String]
+ $addWarehouses: [ID]
+ ) {
shippingZoneCreate(
input: {
- name: $name, countries: $countries,
- default: $default, addWarehouses: $addWarehouses
- })
- {
+ name: $name
+ description: $description
+ countries: $countries
+ default: $default
+ addWarehouses: $addWarehouses
+ }
+ ) {
shippingErrors {
field
code
}
shippingZone {
name
+ description
countries {
code
}
@@ -290,6 +299,7 @@ def test_create_shipping_zone(staff_api_client, warehouse, permission_manage_shi
warehouse_id = graphene.Node.to_global_id("Warehouse", warehouse.pk)
variables = {
"name": "test shipping",
+ "description": "test description",
"countries": ["PL"],
"addWarehouses": [warehouse_id],
}
@@ -300,6 +310,7 @@ def test_create_shipping_zone(staff_api_client, warehouse, permission_manage_shi
data = content["data"]["shippingZoneCreate"]
zone = data["shippingZone"]
assert zone["name"] == "test shipping"
+ assert zone["description"] == "test description"
assert zone["countries"] == [{"code": "PL"}]
assert zone["warehouses"][0]["name"] == warehouse.name
assert zone["default"] is False
@@ -513,6 +524,7 @@ UPDATE_SHIPPING_ZONE_QUERY = """
mutation updateShipping(
$id: ID!
$name: String
+ $description: String
$default: Boolean
$countries: [String]
$addWarehouses: [ID]
@@ -522,6 +534,7 @@ UPDATE_SHIPPING_ZONE_QUERY = """
id: $id
input: {
name: $name
+ description: $description
default: $default
countries: $countries
addWarehouses: $addWarehouses
@@ -530,6 +543,7 @@ UPDATE_SHIPPING_ZONE_QUERY = """
) {
shippingZone {
name
+ description
warehouses {
name
slug
@@ -549,8 +563,14 @@ def test_update_shipping_zone(
staff_api_client, shipping_zone, permission_manage_shipping
):
name = "Parabolic name"
+ description = "Description of a shipping zone."
shipping_id = graphene.Node.to_global_id("ShippingZone", shipping_zone.pk)
- variables = {"id": shipping_id, "name": name, "countries": []}
+ variables = {
+ "id": shipping_id,
+ "name": name,
+ "countries": [],
+ "description": description,
+ }
response = staff_api_client.post_graphql(
UPDATE_SHIPPING_ZONE_QUERY, variables, permissions=[permission_manage_shipping]
)
@@ -559,6 +579,7 @@ def test_update_shipping_zone(
assert not data["shippingErrors"]
data = content["data"]["shippingZoneUpdate"]["shippingZone"]
assert data["name"] == name
+ assert data["description"] == description
def test_update_shipping_zone_default_exists(
diff --git a/saleor/graphql/shipping/types.py b/saleor/graphql/shipping/types.py
index 0d543ca6c2..bb626bf999 100644
--- a/saleor/graphql/shipping/types.py
+++ b/saleor/graphql/shipping/types.py
@@ -208,6 +208,7 @@ class ShippingZone(ChannelContextTypeWithMetadata, CountableDjangoObjectType):
warehouses = graphene.List(
Warehouse, description="List of warehouses for shipping zone."
)
+ description = graphene.String(description="Description of a shipping zone.")
class Meta:
default_resolver = ChannelContextType.resolver_with_context
diff --git a/saleor/shipping/migrations/0026_shippingzone_description.py b/saleor/shipping/migrations/0026_shippingzone_description.py
new file mode 100644
index 0000000000..93c591401f
--- /dev/null
+++ b/saleor/shipping/migrations/0026_shippingzone_description.py
@@ -0,0 +1,18 @@
+# Generated by Django 3.1.4 on 2020-12-29 12:49
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("shipping", "0025_auto_20201130_1122"),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name="shippingzone",
+ name="description",
+ field=models.TextField(blank=True),
+ ),
+ ]
diff --git a/saleor/shipping/models.py b/saleor/shipping/models.py
index cc999c1b90..4f049227ee 100644
--- a/saleor/shipping/models.py
+++ b/saleor/shipping/models.py
@@ -76,6 +76,7 @@ class ShippingZone(ModelWithMetadata):
name = models.CharField(max_length=100)
countries = CountryField(multiple=True, default=[], blank=True)
default = models.BooleanField(default=False)
+ description = models.TextField(blank=True)
def __str__(self):
return self.name