Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add manager parameter to add_variant_to_draft_order method
IKarbowiak2b00c8f83063
diff --git a/saleor/graphql/order/mutations/draft_orders.py b/saleor/graphql/order/mutations/draft_orders.pyindex 75ff66246b..62bb539e3f 100644--- a/saleor/graphql/order/mutations/draft_orders.py+++ b/saleor/graphql/order/mutations/draft_orders.py@@ -218,7 +218,9 @@ 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_draft_order(+ instance, variant, quantity, info.context.plugins+ )# New eventevents.draft_order_added_products_event(@@ -451,7 +453,9 @@ class DraftOrderLinesCreate(BaseMutation):# Add the linestry:lines = [- add_variant_to_draft_order(order, variant, quantity)+ add_variant_to_draft_order(+ order, variant, quantity, info.context.plugins+ )for quantity, variant in lines_to_add]except TaxError as tax_error:diff --git a/saleor/order/tests/test_emails.py b/saleor/order/tests/test_emails.pyindex a2f8c8d2f1..264a7a89b2 100644--- a/saleor/order/tests/test_emails.py+++ b/saleor/order/tests/test_emails.py@@ -7,6 +7,7 @@ from ...invoice import emails as invoice_emailsfrom ...invoice.models import Invoicefrom ...order import OrderEventsfrom ...order import emails as emails+from ...plugins.manager import get_plugins_managerfrom ..utils import add_variant_to_draft_order@@ -144,7 +145,10 @@ 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)+ manager = get_plugins_manager()+ add_variant_to_draft_order(+ order, digital_content.product_variant, quantity=1, manager=manager+ )order.shipping_address = Noneorder.shipping_method = Noneorder.billing_address = None@@ -178,7 +182,10 @@ 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)+ manager = get_plugins_manager()+ add_variant_to_draft_order(+ order, digital_content.product_variant, quantity=1, manager=manager+ )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 3773265b61..8939ac6602 100644--- a/saleor/order/tests/test_order.py+++ b/saleor/order/tests/test_order.py@@ -71,7 +71,8 @@ def test_add_variant_to_draft_order_adds_line_for_new_variant(variant = product.variants.get()lines_before = order.lines.count()settings.LANGUAGE_CODE = "fr"- add_variant_to_draft_order(order, variant, 1)+ manager = get_plugins_manager()+ add_variant_to_draft_order(order, variant, 1, manager)line = order.lines.last()assert order.lines.count() == lines_before + 1@@ -94,7 +95,8 @@ 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)+ manager = get_plugins_manager()+ add_variant_to_draft_order(order, variant, 1, manager)line = order.lines.last()assert order.lines.count() == lines_before + 1@@ -112,8 +114,9 @@ def test_add_variant_to_draft_order_not_allocates_stock_for_new_variant(stock = Stock.objects.get(product_variant=variant)stock_before = get_quantity_allocated_for_stock(stock)+ manager = get_plugins_manager()- add_variant_to_draft_order(order_with_lines, variant, 1)+ add_variant_to_draft_order(order_with_lines, variant, 1, manager)stock.refresh_from_db()assert get_quantity_allocated_for_stock(stock) == stock_before@@ -124,8 +127,9 @@ def test_add_variant_to_draft_order_edits_line_for_existing_variant(order_with_lvariant = existing_line.variantlines_before = order_with_lines.lines.count()line_quantity_before = existing_line.quantity+ manager = get_plugins_manager()- add_variant_to_draft_order(order_with_lines, variant, 1)+ add_variant_to_draft_order(order_with_lines, variant, 1, manager)existing_line.refresh_from_db()assert order_with_lines.lines.count() == lines_before@@ -142,8 +146,9 @@ def test_add_variant_to_draft_order_not_allocates_stock_for_existing_variant(stock_before = get_quantity_allocated_for_stock(stock)quantity_before = existing_line.quantityquantity_unfulfilled_before = existing_line.quantity_unfulfilled+ manager = get_plugins_manager()- add_variant_to_draft_order(order_with_lines, variant, 1)+ add_variant_to_draft_order(order_with_lines, variant, 1, manager)stock.refresh_from_db()existing_line.refresh_from_db()@@ -565,7 +570,8 @@ 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)+ manager = get_plugins_manager()+ add_variant_to_draft_order(order_with_lines, variant, 2, manager)order_with_lines.refresh_from_db()assert order_with_lines.weight == _calculate_order_weight_from_lines(order_with_lines@@ -574,7 +580,8 @@ 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)+ manager = get_plugins_manager()+ add_variant_to_draft_order(order_with_lines, variant, 2, manager)order_with_lines.refresh_from_db()assert order_with_lines.weight == _calculate_order_weight_from_lines(order_with_lines@@ -603,7 +610,8 @@ 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)+ manager = get_plugins_manager()+ add_variant_to_draft_order(order, variant, 1, manager)old_weight = order.get_total_weight()product.delete()diff --git a/saleor/order/utils.py b/saleor/order/utils.pyindex 6918ffe558..5f85b0e284 100644--- a/saleor/order/utils.py+++ b/saleor/order/utils.py@@ -16,7 +16,6 @@ from ..discount.models import NotApplicable, OrderDiscount, Voucher, VoucherTypefrom ..discount.utils import get_products_voucher_discount, validate_voucher_in_orderfrom ..order import FulfillmentStatus, OrderLineData, OrderStatusfrom ..order.models import Order, OrderLine-from ..plugins.manager import get_plugins_managerfrom ..product.utils.digital_products import get_default_digital_content_settingsfrom ..shipping.models import ShippingMethodfrom ..warehouse.management import deallocate_stock, increase_stock@@ -289,7 +288,7 @@ def update_order_status(order):@transaction.atomic-def add_variant_to_draft_order(order, variant, quantity, discounts=None):+def add_variant_to_draft_order(order, variant, quantity, manager, discounts=None):"""Add total_quantity of variant to order.Returns an order line the variant was added to.@@ -328,7 +327,6 @@ def add_variant_to_draft_order(order, variant, quantity, discounts=None):total_price=total_price,variant=variant,)- manager = get_plugins_manager()unit_price = manager.calculate_order_line_unit(order, line, variant, product)line.unit_price = unit_priceline.tax_rate = manager.get_order_line_tax_rate(