Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix order from draft confirmation (#15998)
Krzysztof Kwaśniak7f68c6c720f2
diff --git a/saleor/graphql/order/tests/mutations/test_draft_order_complete.py b/saleor/graphql/order/tests/mutations/test_draft_order_complete.pyindex 82267764ad..47d79288b0 100644--- a/saleor/graphql/order/tests/mutations/test_draft_order_complete.py+++ b/saleor/graphql/order/tests/mutations/test_draft_order_complete.py@@ -129,6 +129,49 @@ def test_draft_order_complete()+def test_draft_order_complete_no_automatically_confirm_all_new_orders(+ staff_api_client,+ permission_group_manage_orders,+ staff_user,+ draft_order,+ channel_USD,+):+ # given+ channel_USD.automatically_confirm_all_new_orders = False+ channel_USD.save()+ order = draft_order+ permission_group_manage_orders.user_set.add(staff_api_client.user)++ # Ensure no events were created+ assert not OrderEvent.objects.exists()++ # Ensure no allocation were created+ assert not Allocation.objects.filter(order_line__order=order).exists()++ order_id = graphene.Node.to_global_id("Order", order.id)+ variables = {"id": order_id}++ # when+ response = staff_api_client.post_graphql(DRAFT_ORDER_COMPLETE_MUTATION, variables)++ # then+ content = get_graphql_content(response)+ data = content["data"]["draftOrderComplete"]["order"]+ order.refresh_from_db()+ assert data["status"] == order.status.upper()+ assert data["origin"] == OrderOrigin.DRAFT.upper()+ assert order.search_vector++ for line in order.lines.all():+ allocation = line.allocations.get()+ assert allocation.quantity_allocated == line.quantity_unfulfilled++ # ensure there are only 1 event with correct type+ event = OrderEvent.objects.get(user=staff_user)+ assert event.type == order_events.OrderEvents.PLACED_FROM_DRAFT+ assert not OrderEvent.objects.exclude(user=staff_user).exists()++def test_draft_order_complete_by_user_no_channel_access(staff_api_client,permission_group_all_perms_channel_USD_only,diff --git a/saleor/order/actions.py b/saleor/order/actions.pyindex 0df69a4211..697be8f7c3 100644--- a/saleor/order/actions.py+++ b/saleor/order/actions.py@@ -120,7 +120,7 @@ def order_created()channel = order_info.channel- if channel.automatically_confirm_all_new_orders or from_draft:+ if channel.automatically_confirm_all_new_orders:order_confirmed(order, user, app, manager)diff --git a/saleor/order/tests/test_actions.py b/saleor/order/tests/test_actions.pynew file mode 100644index 0000000000..b70b087764--- /dev/null+++ b/saleor/order/tests/test_actions.py@@ -0,0 +1,61 @@+from unittest.mock import patch++import pytest++from .. import OrderStatus+from ..actions import order_created+from ..fetch import OrderInfo++parametrize_order_statuses = [(status,) for status, _ in OrderStatus.CHOICES]++[email protected]("order_status", parametrize_order_statuses)+@patch("saleor.order.actions.order_confirmed")+def test_order_created_order_confirmed_with_turned_flag_on(+ mock_order_confirmed, order_status, order, customer_user, plugins_manager+):+ # given+ order.status = order_status+ order.save(update_fields=["status"])+ order.channel.automatically_confirm_all_new_orders = True+ order.channel.save(update_fields=["automatically_confirm_all_new_orders"])+ order_info = OrderInfo(+ order=order,+ customer_email=order.get_customer_email(),+ channel=order.channel,+ payment=order.get_last_payment(),+ lines_data=[],+ )++ # when+ order_created(order_info, user=customer_user, app=None, manager=plugins_manager)++ # then+ mock_order_confirmed.assert_called_once_with(+ order, customer_user, None, plugins_manager+ )++[email protected]("order_status", parametrize_order_statuses)+@patch("saleor.order.actions.order_confirmed")+def test_order_created_order_confirmed_with_turned_flag_off(+ mock_order_confirmed, order_status, order, customer_user, plugins_manager+):+ # given+ order.status = order_status+ order.save(update_fields=["status"])+ order.channel.automatically_confirm_all_new_orders = False+ order.channel.save(update_fields=["automatically_confirm_all_new_orders"])+ order_info = OrderInfo(+ order=order,+ customer_email=order.get_customer_email(),+ channel=order.channel,+ payment=order.get_last_payment(),+ lines_data=[],+ )++ # when+ order_created(order_info, user=customer_user, app=None, manager=plugins_manager)++ # then+ mock_order_confirmed.assert_not_called()