Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix review remarks
fowczrekcb12d9fe2e3f
diff --git a/saleor/graphql/order/mutations/fulfillments.py b/saleor/graphql/order/mutations/fulfillments.pyindex 929fb9d108..a8ad1e4eb0 100644--- a/saleor/graphql/order/mutations/fulfillments.py+++ b/saleor/graphql/order/mutations/fulfillments.py@@ -26,10 +26,10 @@ from ..types import OrderLineclass OrderFulfillStockInput(graphene.InputObjectType):quantity = graphene.Int(- description="The number of line item to be fulfilled from given warehouse."+ description="The number of line items to be fulfilled from given warehouse.")warehouse = graphene.ID(- description="ID of the warehouse from which item be fulfilled."+ description="ID of the warehouse from which the item will be fulfilled.")@@ -168,6 +168,19 @@ class OrderFulfill(BaseMutation):})+ @classmethod+ def check_total_quantity_of_items(cls, quantities_for_lines):+ flat_quantities = sum(quantities_for_lines, [])+ if sum(flat_quantities) <= 0:+ raise ValidationError(+ {+ "lines": ValidationError(+ "Total quantity must be larger than 0.",+ code=OrderErrorCode.ZERO_QUANTITY,+ )+ }+ )+@classmethoddef clean_input(cls, data):lines = data["lines"]@@ -189,15 +202,7 @@ class OrderFulfill(BaseMutation):cls.clean_lines(order_lines, quantities_for_lines)- if sum(sum(quantities_for_lines, [])) <= 0:- raise ValidationError(- {- "lines": ValidationError(- "Total quantity must be larger than 0.",- code=OrderErrorCode.ZERO_QUANTITY,- )- }- )+ cls.check_total_quantity_of_items(quantities_for_lines)lines_for_warehouses = defaultdict(list)for line, order_line in zip(lines, order_lines):diff --git a/saleor/order/actions.py b/saleor/order/actions.pyindex 623663b85c..4e6cb2d049 100644--- a/saleor/order/actions.py+++ b/saleor/order/actions.py@@ -5,7 +5,6 @@ from typing import TYPE_CHECKING, Dict, Listfrom django.db import transactionfrom ..core import analytics-from ..core.exceptions import InsufficientStockfrom ..payment import ChargeStatus, CustomPaymentChoices, PaymentErrorfrom ..plugins.manager import get_plugins_managerfrom ..warehouse.management import decrease_stock@@ -212,10 +211,7 @@ def clean_mark_order_as_paid(order: "Order"):def fulfill_order_line(order_line, quantity, warehouse_pk):"""Fulfill order line with given quantity."""if order_line.variant and order_line.variant.track_inventory:- try:- decrease_stock(order_line, quantity, warehouse_pk)- except InsufficientStock as exc:- raise exc+ decrease_stock(order_line, quantity, warehouse_pk)order_line.quantity_fulfilled += quantityorder_line.save(update_fields=["quantity_fulfilled"])@@ -253,7 +249,7 @@ def automatically_fulfill_digital_lines(order: "Order"):update_order_status(order)-def _create_fulfillment(+def _create_fulfillment_lines(fulfillment: Fulfillment, warehouse_pk: str, lines: List[Dict]) -> List[FulfillmentLine]:"""Modify stocks and allocations. Return list of unsaved FulfillmentLines.@@ -284,10 +280,7 @@ def _create_fulfillment(quantity = line["quantity"]order_line = line["order_line"]if quantity > 0:- try:- fulfill_order_line(order_line, quantity, warehouse_pk)- except InsufficientStock as exc:- raise exc+ fulfill_order_line(order_line, quantity, warehouse_pk)if order_line.is_digital:order_line.variant.digital_content.urls.create(line=order_line)fulfillment_lines.append(@@ -307,7 +300,7 @@ def create_fulfillments(order: "Order",fulfillment_lines_for_warehouses: Dict,notify_customer: bool = True,-):+) -> List[Fulfillment]:"""Fulfill order.Function create fulfillments with lines.@@ -330,25 +323,27 @@ def create_fulfillments(notify_customer (bool): If `True` system send email aboutfulfillments to customer.+ Return:+ List[Fulfillment]: Fulfillmet with lines created for this order+ based on information form `fulfillment_lines_for_warehouses`++Raise:InsufficientStock: If system hasn't containt enough item in stock for any line."""- fulfillments = []+ fulfillments: List[Fulfillment] = []fulfillment_lines: List[FulfillmentLine] = []for warehouse_pk in fulfillment_lines_for_warehouses:fulfillment = Fulfillment.objects.create(order=order)fulfillments.append(fulfillment)- try:- fulfillment_lines.extend(- _create_fulfillment(- fulfillment,- warehouse_pk,- fulfillment_lines_for_warehouses[warehouse_pk],- )+ fulfillment_lines.extend(+ _create_fulfillment_lines(+ fulfillment,+ warehouse_pk,+ fulfillment_lines_for_warehouses[warehouse_pk],)- except InsufficientStock as exc:- raise exc+ )FulfillmentLine.objects.bulk_create(fulfillment_lines)order_fulfilled(