Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Move fulfill_order_line function from dashboard.order.utils to order.utils
Maciej Korycinski59917ad8bec9
diff --git a/saleor/dashboard/order/forms.py b/saleor/dashboard/order/forms.pyindex f1bd639c1f..241c7d7587 100644--- a/saleor/dashboard/order/forms.py+++ b/saleor/dashboard/order/forms.py@@ -16,7 +16,8 @@ from ...order import OrderStatusfrom ...order.models import Fulfillment, FulfillmentLine, Order, OrderLinefrom ...order.utils import (add_variant_to_order, cancel_fulfillment, cancel_order,- change_order_line_quantity, delete_order_line, recalculate_order)+ change_order_line_quantity, delete_order_line, fulfill_order_line,+ recalculate_order)from ...payment import ChargeStatus, CustomPaymentChoices, PaymentErrorfrom ...payment.utils import (clean_mark_order_as_paid, gateway_capture, gateway_refund, gateway_void,@@ -26,9 +27,7 @@ from ...product.utils import allocate_stock, deallocate_stockfrom ...shipping.models import ShippingMethodfrom ..forms import AjaxSelect2ChoiceFieldfrom ..widgets import PhonePrefixWidget-from .utils import (- fulfill_order_line, remove_customer_from_order,- update_order_with_user_addresses)+from .utils import remove_customer_from_order, update_order_with_user_addressesclass CreateOrderFromDraftForm(forms.ModelForm):diff --git a/saleor/dashboard/order/utils.py b/saleor/dashboard/order/utils.pyindex 77cf6c3da0..1610230824 100644--- a/saleor/dashboard/order/utils.py+++ b/saleor/dashboard/order/utils.py@@ -50,14 +50,6 @@ def create_packing_slip_pdf(order, fulfillment, absolute_url):return pdf_file, order-def fulfill_order_line(order_line, quantity):- """Fulfill order line with given quantity."""- if order_line.variant and order_line.variant.track_inventory:- decrease_stock(order_line.variant, quantity)- order_line.quantity_fulfilled += quantity- order_line.save(update_fields=['quantity_fulfilled'])--def update_order_with_user_addresses(order):"""Update addresses in an order based on a user assigned to an order."""if order.shipping_address:diff --git a/saleor/graphql/order/mutations/fulfillments.py b/saleor/graphql/order/mutations/fulfillments.pyindex b738bb2d5e..e47185211a 100644--- a/saleor/graphql/order/mutations/fulfillments.py+++ b/saleor/graphql/order/mutations/fulfillments.py@@ -4,10 +4,10 @@ import graphenefrom django.utils.translation import npgettext_lazy, pgettext_lazyfrom graphql_jwt.decorators import permission_required-from ....dashboard.order.utils import fulfill_order_linefrom ....order import OrderEvents, OrderEventsEmails, modelsfrom ....order.emails import send_fulfillment_confirmation-from ....order.utils import cancel_fulfillment, update_order_status+from ....order.utils import (+ cancel_fulfillment, update_order_status, fulfill_order_line)from ...core.mutations import BaseMutationfrom ...order.types import Fulfillment, Orderfrom ..types import OrderLinediff --git a/saleor/order/utils.py b/saleor/order/utils.pyindex 9d3a690247..7f84b65513 100644--- a/saleor/order/utils.py+++ b/saleor/order/utils.py@@ -16,7 +16,16 @@ from ..order import FulfillmentStatus, OrderStatusfrom ..order.models import OrderLinefrom ..payment import ChargeStatusfrom ..payment.utils import gateway_refund, gateway_void-from ..product.utils import allocate_stock, deallocate_stock, increase_stock+from ..product.utils import (+ allocate_stock, deallocate_stock, increase_stock, decrease_stock)+++def fulfill_order_line(order_line, quantity):+ """Fulfill order line with given quantity."""+ if order_line.variant and order_line.variant.track_inventory:+ decrease_stock(order_line.variant, quantity)+ order_line.quantity_fulfilled += quantity+ order_line.save(update_fields=['quantity_fulfilled'])def check_order_status(func):diff --git a/tests/conftest.py b/tests/conftest.pyindex 9aff66b911..9aab57b3bb 100644--- a/tests/conftest.py+++ b/tests/conftest.py@@ -21,13 +21,12 @@ from saleor.checkout import utilsfrom saleor.checkout.models import Cartfrom saleor.checkout.utils import add_variant_to_cartfrom saleor.dashboard.menu.utils import update_menu-from saleor.dashboard.order.utils import fulfill_order_linefrom saleor.discount import VoucherTypefrom saleor.discount.models import Sale, Voucher, VoucherTranslationfrom saleor.menu.models import Menu, MenuItemfrom saleor.order import OrderEvents, OrderStatusfrom saleor.order.models import FulfillmentStatus, Order, OrderEvent-from saleor.order.utils import recalculate_order+from saleor.order.utils import recalculate_order, fulfill_order_linefrom saleor.page.models import Pagefrom saleor.payment import ChargeStatus, TransactionKindfrom saleor.payment.models import Paymentdiff --git a/tests/dashboard/test_order.py b/tests/dashboard/test_order.pyindex 29d736545c..a7eabb4fa7 100644--- a/tests/dashboard/test_order.py+++ b/tests/dashboard/test_order.py@@ -9,7 +9,7 @@ from saleor.checkout import AddressTypefrom saleor.core.utils.taxes import ZERO_MONEY, ZERO_TAXED_MONEYfrom saleor.dashboard.order.forms import ChangeQuantityFormfrom saleor.dashboard.order.utils import (- fulfill_order_line, remove_customer_from_order, save_address_in_order,+ remove_customer_from_order, save_address_in_order,update_order_with_user_addresses)from saleor.discount.utils import increase_voucher_usagefrom saleor.order import (@@ -483,47 +483,6 @@ def test_view_add_variant_to_order(admin_client, order_with_lines):assert line.quantity == line_quantity_before + added_quantity-def test_fulfill_order_line(order_with_lines):- order = order_with_lines- line = order.lines.first()- quantity_fulfilled_before = line.quantity_fulfilled- variant = line.variant- stock_quantity_after = variant.quantity - line.quantity-- fulfill_order_line(line, line.quantity)-- variant.refresh_from_db()- assert variant.quantity == stock_quantity_after- assert line.quantity_fulfilled == quantity_fulfilled_before + line.quantity---def test_fulfill_order_line_with_variant_deleted(order_with_lines):- line = order_with_lines.lines.first()- line.variant.delete()-- line.refresh_from_db()-- fulfill_order_line(line, line.quantity)---def test_fulfill_order_line_without_inventory_tracking(order_with_lines):- order = order_with_lines- line = order.lines.first()- quantity_fulfilled_before = line.quantity_fulfilled- variant = line.variant- variant.track_inventory = False- variant.save()-- # stock should not change- stock_quantity_after = variant.quantity-- fulfill_order_line(line, line.quantity)-- variant.refresh_from_db()- assert variant.quantity == stock_quantity_after- assert line.quantity_fulfilled == quantity_fulfilled_before + line.quantity--def test_view_change_fulfillment_tracking(admin_client, fulfilled_order):fulfillment = fulfilled_order.fulfillments.first()url = reverse(diff --git a/tests/test_order.py b/tests/test_order.pyindex eaaf9c6298..98d38c9aab 100644--- a/tests/test_order.py+++ b/tests/test_order.py@@ -16,7 +16,7 @@ from saleor.order.models import Orderfrom saleor.order.utils import (add_variant_to_order, cancel_fulfillment, cancel_order,change_order_line_quantity, delete_order_line, recalculate_order,- recalculate_order_weight, restock_fulfillment_lines, restock_order_lines,+ fulfill_order_line, restock_fulfillment_lines, restock_order_lines,update_order_prices, update_order_status)from saleor.payment import ChargeStatusfrom saleor.payment.models import Payment@@ -577,3 +577,45 @@ def test_get_order_weight_non_existing_product(order_with_lines, product):new_weight = order.get_total_weight()assert old_weight == new_weight++++def test_fulfill_order_line(order_with_lines):+ order = order_with_lines+ line = order.lines.first()+ quantity_fulfilled_before = line.quantity_fulfilled+ variant = line.variant+ stock_quantity_after = variant.quantity - line.quantity++ fulfill_order_line(line, line.quantity)++ variant.refresh_from_db()+ assert variant.quantity == stock_quantity_after+ assert line.quantity_fulfilled == quantity_fulfilled_before + line.quantity+++def test_fulfill_order_line_with_variant_deleted(order_with_lines):+ line = order_with_lines.lines.first()+ line.variant.delete()++ line.refresh_from_db()++ fulfill_order_line(line, line.quantity)+++def test_fulfill_order_line_without_inventory_tracking(order_with_lines):+ order = order_with_lines+ line = order.lines.first()+ quantity_fulfilled_before = line.quantity_fulfilled+ variant = line.variant+ variant.track_inventory = False+ variant.save()++ # stock should not change+ stock_quantity_after = variant.quantity++ fulfill_order_line(line, line.quantity)++ variant.refresh_from_db()+ assert variant.quantity == stock_quantity_after+ assert line.quantity_fulfilled == quantity_fulfilled_before + line.quantity