Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Refactor add_variant_to_draft_order to add_variant_to_order
Tomasz Szymanski203e6d73f2f7
diff --git a/saleor/graphql/order/mutations/draft_orders.py b/saleor/graphql/order/mutations/draft_orders.pyindex ca0c7c0e73..beccf638bd 100644--- a/saleor/graphql/order/mutations/draft_orders.py+++ b/saleor/graphql/order/mutations/draft_orders.py@@ -12,7 +12,7 @@ from ....order import OrderStatus, events, modelsfrom ....order.actions import order_createdfrom ....order.error_codes import OrderErrorCodefrom ....order.utils import (- add_variant_to_draft_order,+ add_variant_to_order,get_order_country,recalculate_order,update_order_prices,@@ -215,7 +215,7 @@ class DraftOrderCreate(ModelMutation, I18nMixin):lines = []for variant, quantity in zip(variants, quantities):lines.append((quantity, variant))- add_variant_to_draft_order(instance, variant, quantity)+ add_variant_to_order(instance, variant, quantity)# New eventevents.draft_order_added_products_event(diff --git a/saleor/graphql/order/mutations/orders.py b/saleor/graphql/order/mutations/orders.pyindex 51107ca089..4ce256e15d 100644--- a/saleor/graphql/order/mutations/orders.py+++ b/saleor/graphql/order/mutations/orders.py@@ -18,7 +18,7 @@ from ....order.actions import ()from ....order.error_codes import OrderErrorCodefrom ....order.utils import (- add_variant_to_draft_order,+ add_variant_to_order,change_order_line_quantity,delete_order_line,get_valid_shipping_methods_for_order,@@ -625,7 +625,7 @@ class OrderLinesCreate(BaseMutation):# Add the linestry:lines = [- add_variant_to_draft_order(order, variant, quantity)+ add_variant_to_order(order, variant, quantity)for quantity, variant in lines_to_add]except TaxError as tax_error:diff --git a/saleor/graphql/order/tests/test_order.py b/saleor/graphql/order/tests/test_order.pyindex c715aeecb0..9ec91db14f 100644--- a/saleor/graphql/order/tests/test_order.py+++ b/saleor/graphql/order/tests/test_order.py@@ -1196,9 +1196,9 @@ def test_draft_order_create_variant_with_0_price(assert created_draft_event.parameters == {}-@patch("saleor.graphql.order.mutations.draft_orders.add_variant_to_draft_order")+@patch("saleor.graphql.order.mutations.draft_orders.add_variant_to_order")def test_draft_order_create_tax_error(- add_variant_to_draft_order_mock,+ add_variant_to_order_mock,staff_api_client,permission_manage_orders,staff_user,@@ -1212,7 +1212,7 @@ def test_draft_order_create_tax_error():variant_0 = varianterr_msg = "Test error"- add_variant_to_draft_order_mock.side_effect = TaxError(err_msg)+ add_variant_to_order_mock.side_effect = TaxError(err_msg)query = DRAFT_ORDER_CREATE_MUTATION# Ensure no events were created yetassert not OrderEvent.objects.exists()diff --git a/saleor/order/tests/test_emails.py b/saleor/order/tests/test_emails.pyindex a2f8c8d2f1..5a745f8743 100644--- a/saleor/order/tests/test_emails.py+++ b/saleor/order/tests/test_emails.py@@ -7,7 +7,7 @@ from ...invoice import emails as invoice_emailsfrom ...invoice.models import Invoicefrom ...order import OrderEventsfrom ...order import emails as emails-from ..utils import add_variant_to_draft_order+from ..utils import add_variant_to_orderdef test_collect_data_for_order_confirmation_email(order):@@ -144,7 +144,7 @@ def test_send_confirmation_emails_without_addresses_for_payment(assert not order.lines.count()template = emails.CONFIRM_PAYMENT_TEMPLATE- add_variant_to_draft_order(order, digital_content.product_variant, quantity=1)+ add_variant_to_order(order, digital_content.product_variant, quantity=1)order.shipping_address = Noneorder.shipping_method = Noneorder.billing_address = None@@ -178,7 +178,7 @@ def test_send_confirmation_emails_without_addresses_for_order(assert not order.lines.count()template = emails.CONFIRM_ORDER_TEMPLATE- add_variant_to_draft_order(order, digital_content.product_variant, quantity=1)+ add_variant_to_order(order, digital_content.product_variant, quantity=1)order.shipping_address = Noneorder.shipping_method = Noneorder.billing_address = Nonediff --git a/saleor/order/tests/test_order.py b/saleor/order/tests/test_order.pyindex fb1a145fdd..e90ef27c92 100644--- a/saleor/order/tests/test_order.py+++ b/saleor/order/tests/test_order.py@@ -24,7 +24,7 @@ from ..events import OrderEvent, OrderEventsEmails, email_sent_eventfrom ..models import Orderfrom ..templatetags.order_lines import display_translated_order_line_namefrom ..utils import (- add_variant_to_draft_order,+ add_variant_to_order,change_order_line_quantity,delete_order_line,get_voucher_discount_for_order,@@ -57,14 +57,14 @@ def test_order_get_subtotal(order_with_lines):assert order_with_lines.get_subtotal() == target_subtotal-def test_add_variant_to_draft_order_adds_line_for_new_variant(+def test_add_variant_to_order_adds_line_for_new_variant(order_with_lines, product, product_translation_fr, settings):order = order_with_linesvariant = product.variants.get()lines_before = order.lines.count()settings.LANGUAGE_CODE = "fr"- add_variant_to_draft_order(order, variant, 1)+ add_variant_to_order(order, variant, 1)line = order.lines.last()assert order.lines.count() == lines_before + 1@@ -76,7 +76,7 @@ def test_add_variant_to_draft_order_adds_line_for_new_variant(assert line.product_name == str(variant.product)-def test_add_variant_to_draft_order_adds_line_for_variant_with_price_0(+def test_add_variant_to_order_adds_line_for_variant_with_price_0(order_with_lines, product, product_translation_fr, settings):order = order_with_lines@@ -87,7 +87,7 @@ def test_add_variant_to_draft_order_adds_line_for_variant_with_price_0(lines_before = order.lines.count()settings.LANGUAGE_CODE = "fr"- add_variant_to_draft_order(order, variant, 1)+ add_variant_to_order(order, variant, 1)line = order.lines.last()assert order.lines.count() == lines_before + 1@@ -98,7 +98,7 @@ def test_add_variant_to_draft_order_adds_line_for_variant_with_price_0(assert line.product_name == variant.product.name-def test_add_variant_to_draft_order_not_allocates_stock_for_new_variant(+def test_add_variant_to_order_not_allocates_stock_for_new_variant(order_with_lines, product):variant = product.variants.get()@@ -106,19 +106,19 @@ def test_add_variant_to_draft_order_not_allocates_stock_for_new_variant(stock_before = get_quantity_allocated_for_stock(stock)- add_variant_to_draft_order(order_with_lines, variant, 1)+ add_variant_to_order(order_with_lines, variant, 1)stock.refresh_from_db()assert get_quantity_allocated_for_stock(stock) == stock_before-def test_add_variant_to_draft_order_edits_line_for_existing_variant(order_with_lines):+def test_add_variant_to_order_edits_line_for_existing_variant(order_with_lines):existing_line = order_with_lines.lines.first()variant = existing_line.variantlines_before = order_with_lines.lines.count()line_quantity_before = existing_line.quantity- add_variant_to_draft_order(order_with_lines, variant, 1)+ add_variant_to_order(order_with_lines, variant, 1)existing_line.refresh_from_db()assert order_with_lines.lines.count() == lines_before@@ -126,7 +126,7 @@ def test_add_variant_to_draft_order_edits_line_for_existing_variant(order_with_lassert existing_line.quantity == line_quantity_before + 1-def test_add_variant_to_draft_order_not_allocates_stock_for_existing_variant(+def test_add_variant_to_order_not_allocates_stock_for_existing_variant(order_with_lines,):existing_line = order_with_lines.lines.first()@@ -136,7 +136,7 @@ def test_add_variant_to_draft_order_not_allocates_stock_for_existing_variant(quantity_before = existing_line.quantityquantity_unfulfilled_before = existing_line.quantity_unfulfilled- add_variant_to_draft_order(order_with_lines, variant, 1)+ add_variant_to_order(order_with_lines, variant, 1)stock.refresh_from_db()existing_line.refresh_from_db()@@ -478,7 +478,7 @@ def test_calculate_order_weight(order_with_lines):def test_order_weight_add_more_variant(order_with_lines):variant = order_with_lines.lines.first().variant- add_variant_to_draft_order(order_with_lines, variant, 2)+ add_variant_to_order(order_with_lines, variant, 2)order_with_lines.refresh_from_db()assert order_with_lines.weight == _calculate_order_weight_from_lines(order_with_lines@@ -487,7 +487,7 @@ def test_order_weight_add_more_variant(order_with_lines):def test_order_weight_add_new_variant(order_with_lines, product):variant = product.variants.first()- add_variant_to_draft_order(order_with_lines, variant, 2)+ add_variant_to_order(order_with_lines, variant, 2)order_with_lines.refresh_from_db()assert order_with_lines.weight == _calculate_order_weight_from_lines(order_with_lines@@ -516,7 +516,7 @@ def test_get_order_weight_non_existing_product(order_with_lines, product):# Removing product should not affect order's weightorder = order_with_linesvariant = product.variants.first()- add_variant_to_draft_order(order, variant, 1)+ add_variant_to_order(order, variant, 1)old_weight = order.get_total_weight()product.delete()diff --git a/saleor/order/utils.py b/saleor/order/utils.pyindex 676216f0da..237ab14577 100644--- a/saleor/order/utils.py+++ b/saleor/order/utils.py@@ -177,7 +177,7 @@ def update_order_status(order):@transaction.atomic-def add_variant_to_draft_order(order, variant, quantity, discounts=None):+def add_variant_to_order(order, variant, quantity, discounts=None):"""Add total_quantity of variant to order.Returns an order line the variant was added to.