Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Change realted_name in stock product_variant field
IKarbowiaka0d902175e47
diff --git a/saleor/graphql/product/types/products.py b/saleor/graphql/product/types/products.pyindex b9d784e843..81d01226ae 100644--- a/saleor/graphql/product/types/products.py+++ b/saleor/graphql/product/types/products.py@@ -235,7 +235,7 @@ class ProductVariant(CountableDjangoObjectType):model_field="digital_content",)- stock = gql_optimizer.field(+ stocks = gql_optimizer.field(graphene.Field(graphene.List(Stock),description="Stocks for the product variant.",@@ -252,13 +252,13 @@ class ProductVariant(CountableDjangoObjectType):model = models.ProductVariant@staticmethod- def resolve_stock(root: models.ProductVariant, info, country=None):+ def resolve_stocks(root: models.ProductVariant, info, country=None):if country is None:return gql_optimizer.query(- root.stock.annotate_available_quantity().all(), info+ root.stocks.annotate_available_quantity().all(), info)return gql_optimizer.query(- root.stock.annotate_available_quantity().for_country(country).all(), info+ root.stocks.annotate_available_quantity().for_country(country).all(), info)@staticmethoddiff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 3e705bbbed..a8de327dd3 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -3549,7 +3549,7 @@ type ProductVariant implements Node, ObjectWithMetadata {images: [ProductImage]translation(languageCode: LanguageCodeEnum!): ProductVariantTranslationdigitalContent: DigitalContent- stock(country: String): [Stock]+ stocks(country: String): [Stock]}type ProductVariantBulkCreate {diff --git a/saleor/warehouse/migrations/0006_auto_20200228_0519.py b/saleor/warehouse/migrations/0006_auto_20200228_0519.pynew file mode 100644index 0000000000..0edc2ab0cf--- /dev/null+++ b/saleor/warehouse/migrations/0006_auto_20200228_0519.py@@ -0,0 +1,23 @@+# Generated by Django 2.2.10 on 2020-02-28 11:19++import django.db.models.deletion+from django.db import migrations, models+++class Migration(migrations.Migration):++ dependencies = [+ ("warehouse", "0005_auto_20200204_0722"),+ ]++ operations = [+ migrations.AlterField(+ model_name="stock",+ name="product_variant",+ field=models.ForeignKey(+ on_delete=django.db.models.deletion.CASCADE,+ related_name="stocks",+ to="product.ProductVariant",+ ),+ ),+ ]diff --git a/saleor/warehouse/models.py b/saleor/warehouse/models.pyindex 9b948f2f09..a42bcd21c7 100644--- a/saleor/warehouse/models.py+++ b/saleor/warehouse/models.py@@ -87,7 +87,7 @@ class StockQuerySet(models.QuerySet):class Stock(models.Model):warehouse = models.ForeignKey(Warehouse, null=False, on_delete=models.PROTECT)product_variant = models.ForeignKey(- ProductVariant, null=False, on_delete=models.CASCADE, related_name="stock"+ ProductVariant, null=False, on_delete=models.CASCADE, related_name="stocks")quantity = models.PositiveIntegerField(default=0)quantity_allocated = models.PositiveIntegerField(default=0)diff --git a/tests/api/test_product.py b/tests/api/test_product.pyindex d999a315df..bee78d6c54 100644--- a/tests/api/test_product.py+++ b/tests/api/test_product.py@@ -3720,7 +3720,7 @@ def test_update_product_without_variants_updates_stock(staff_api_client, product_with_default_variant, permission_manage_products):product_id = graphene.Node.to_global_id("Product", product_with_default_variant.pk)- stock = product_with_default_variant.variants.first().stock.first()+ stock = product_with_default_variant.variants.first().stocks.first()variables = {"productId": product_id, "quantity": 17}staff_api_client.post_graphql(MUTATION_UPDATE_PRODUCT_QUANTITY,diff --git a/tests/api/test_variant.py b/tests/api/test_variant.pyindex 3f107490ef..dd62195c10 100644--- a/tests/api/test_variant.py+++ b/tests/api/test_variant.py@@ -17,7 +17,7 @@ def test_fetch_variant(staff_api_client, product, permission_manage_products):query ProductVariantDetails($id: ID!) {productVariant(id: $id) {id- stock {+ stocks {id}attributes {@@ -64,7 +64,7 @@ def test_fetch_variant(staff_api_client, product, permission_manage_products):content = get_graphql_content(response)data = content["data"]["productVariant"]assert data["name"] == variant.name- assert len(data["stock"]) == variant.stock.count()+ assert len(data["stocks"]) == variant.stocks.count()def test_create_variant(@@ -1174,7 +1174,7 @@ MUTATION_UPDATE_VARIANT_QUANTITY = """def test_update_variant_and_set_quantity_creates_stock(staff_api_client, variant, permission_manage_products, warehouse):- assert variant.stock.count() == 0+ assert variant.stocks.count() == 0variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)variables = {"id": variant_id, "quantity": 70}staff_api_client.post_graphql(@@ -1182,7 +1182,7 @@ def test_update_variant_and_set_quantity_creates_stock(variables,permissions=[permission_manage_products],)- assert variant.stock.count() == 1+ assert variant.stocks.count() == 1def test_update_variant_fails_when_there_is_no_warehouse_available(@@ -1200,7 +1200,7 @@ def test_update_variant_fails_when_there_is_no_warehouse_available(content = get_graphql_content(response, ignore_errors=True)errors = content["errors"]assert len(errors) == 1- assert variant.stock.count() == 0+ assert variant.stocks.count() == 0def test_update_variant_sets_quantity_in_stock(diff --git a/tests/test_data_feeds.py b/tests/test_data_feeds.pyindex 4469d25de7..011087337c 100644--- a/tests/test_data_feeds.py+++ b/tests/test_data_feeds.py@@ -40,7 +40,7 @@ def test_saleor_feed_items(product, site_settings):def test_saleor_get_feed_items_having_no_stock_info(variant, site_settings):- variant.stock.all().delete()+ variant.stocks.all().delete()assert item_availability(variant) == "out of stock"