Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Pass correct list of order lines to order_added_products_event (#9286)
L3str4ngea8b4e4f7edd2
diff --git a/saleor/graphql/order/mutations/draft_orders.py b/saleor/graphql/order/mutations/draft_orders.pyindex c96b043c46..9cd4d50520 100644--- a/saleor/graphql/order/mutations/draft_orders.py+++ b/saleor/graphql/order/mutations/draft_orders.py@@ -1,3 +1,5 @@+from typing import List, Tuple+import graphenefrom django.core.exceptions import ValidationErrorfrom django.db import transaction@@ -34,7 +36,7 @@ from ...core.scalars import PositiveDecimalfrom ...core.types.common import OrderErrorfrom ...product.types import ProductVariantfrom ...shipping.utils import get_shipping_model_by_object_id-from ..types import Order+from ..types import Order, OrderLinefrom ..utils import (prepare_insufficient_stock_order_validation_errors,validate_draft_order,@@ -247,10 +249,9 @@ class DraftOrderCreate(ModelMutation, I18nMixin):@staticmethoddef _save_lines(info, instance, quantities, variants):if variants and quantities:- lines = []+ lines: List[Tuple[int, OrderLine]] = []for variant, quantity in zip(variants, quantities):- lines.append((quantity, variant))- add_variant_to_order(+ line = add_variant_to_order(instance,variant,quantity,@@ -259,6 +260,7 @@ class DraftOrderCreate(ModelMutation, I18nMixin):info.context.plugins,info.context.site.settings,)+ lines.append((quantity, line))# New eventevents.order_added_products_event(diff --git a/saleor/graphql/order/tests/test_order.py b/saleor/graphql/order/tests/test_order.pyindex 6e02e35c6b..2ca1fe8315 100644--- a/saleor/graphql/order/tests/test_order.py+++ b/saleor/graphql/order/tests/test_order.py@@ -1826,6 +1826,23 @@ def test_draft_order_create(assert created_draft_event.user == staff_userassert created_draft_event.parameters == {}+ # Ensure the order_added_products_event was created properly+ added_products_event = OrderEvent.objects.get(+ type=order_events.OrderEvents.ADDED_PRODUCTS+ )+ event_parameters = added_products_event.parameters+ assert event_parameters+ assert len(event_parameters["lines"]) == 2++ order_lines = list(order.lines.all())+ assert event_parameters["lines"][0]["item"] == str(order_lines[0])+ assert event_parameters["lines"][0]["line_pk"] == order_lines[0].pk+ assert event_parameters["lines"][0]["quantity"] == 2++ assert event_parameters["lines"][1]["item"] == str(order_lines[1])+ assert event_parameters["lines"][1]["line_pk"] == order_lines[1].pk+ assert event_parameters["lines"][1]["quantity"] == 1+def test_draft_order_create_with_inactive_channel(staff_api_client,