Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add product SKU to order bulk create (#16802)
Krzysztof Waliczek6a8d0838c6fa
diff --git a/saleor/graphql/order/bulk_mutations/order_bulk_create.py b/saleor/graphql/order/bulk_mutations/order_bulk_create.pyindex f30a3d22a2..af71976b02 100644--- a/saleor/graphql/order/bulk_mutations/order_bulk_create.py+++ b/saleor/graphql/order/bulk_mutations/order_bulk_create.py@@ -449,6 +449,10 @@ class OrderBulkCreateOrderLineInput(BaseInputObjectType):)variant_name = graphene.String(description="The name of the product variant.")product_name = graphene.String(description="The name of the product.")+ product_sku = graphene.String(+ required=False,+ description="The SKU of the product." + ADDED_IN_318,+ )translated_variant_name = graphene.String(description="Translation of the product variant name.")@@ -1614,6 +1618,7 @@ class OrderBulkCreate(BaseMutation, I18nMixin):translated_variant_name=order_line_input.get("translated_variant_name")or "",product_variant_id=(variant.get_global_id() if variant else None),+ product_sku=order_line_input.get("product_sku"),created_at=order_line_input["created_at"],is_shipping_required=order_line_input["is_shipping_required"],is_gift_card=order_line_input["is_gift_card"],diff --git a/saleor/graphql/order/tests/mutations/test_order_bulk_create.py b/saleor/graphql/order/tests/mutations/test_order_bulk_create.pyindex 74db145b14..c357373221 100644--- a/saleor/graphql/order/tests/mutations/test_order_bulk_create.py+++ b/saleor/graphql/order/tests/mutations/test_order_bulk_create.py@@ -70,6 +70,7 @@ ORDER_BULK_CREATE = """id}productName+ productSkuvariantNametranslatedVariantNametranslatedProductName@@ -603,6 +604,7 @@ def test_order_bulk_create("ProductVariant", variant.id)assert order_line["productName"] == "Product Name"+ assert order_line["productSku"] is Noneassert order_line["variantName"] == "Variant Name"assert order_line["translatedProductName"] == "Nazwa Produktu"assert order_line["translatedVariantName"] == "Nazwa Wariantu"@@ -632,6 +634,7 @@ def test_order_bulk_create(db_order_line = OrderLine.objects.get()assert db_order_line.variant == variantassert db_order_line.product_name == "Product Name"+ assert db_order_line.product_sku is Noneassert db_order_line.variant_name == "Variant Name"assert db_order_line.translated_product_name == "Nazwa Produktu"assert db_order_line.translated_variant_name == "Nazwa Wariantu"@@ -822,6 +825,7 @@ def test_order_bulk_create_multiple_lines(line_2["variantId"] = graphene.Node.to_global_id("ProductVariant", variant_2.id)line_2["totalPrice"]["gross"] = 60line_2["totalPrice"]["net"] = 50+ line_2["productSku"] = "TEST-SKU"order["lines"].append(line_2)staff_api_client.user.user_permissions.add(@@ -845,17 +849,21 @@ def test_order_bulk_create_multiple_lines(line_1 = order["lines"][0]assert line_1["unitPrice"]["gross"]["amount"] == Decimal(120 / 5)assert line_1["unitPrice"]["net"]["amount"] == Decimal(100 / 5)+ assert line_1["productSku"] is Noneline_2 = order["lines"][1]assert line_2["unitPrice"]["gross"]["amount"] == Decimal(60 / 5)assert line_2["unitPrice"]["net"]["amount"] == Decimal(50 / 5)+ assert line_2["productSku"] == "TEST-SKU"db_lines = OrderLine.objects.all()db_line_1 = db_lines[0]assert db_line_1.unit_price.gross.amount == Decimal(120 / 5)assert db_line_1.unit_price.net.amount == Decimal(100 / 5)+ assert db_line_1.product_sku is Nonedb_line_2 = db_lines[1]assert db_line_2.unit_price.gross.amount == Decimal(60 / 5)assert db_line_2.unit_price.net.amount == Decimal(50 / 5)+ assert db_line_2.product_sku == "TEST-SKU"assert order["total"]["gross"]["amount"] == 180assert order["total"]["net"]["amount"] == 150diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 4f3f0407ab..fb43400937 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -24330,6 +24330,13 @@ input OrderBulkCreateOrderLineInput @doc(category: "Orders") {"""The name of the product."""productName: String+ """+ The SKU of the product.++ Added in Saleor 3.18.+ """+ productSku: String+"""Translation of the product variant name."""translatedVariantName: String