Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Code improvements

Anna Siwikf41c299b6e5e
diff --git a/saleor/core/utils/random_data.py b/saleor/core/utils/random_data.py
index 96af7b72d0..6cc497bf02 100644
--- a/saleor/core/utils/random_data.py
+++ b/saleor/core/utils/random_data.py
@@ -18,7 +18,7 @@ from ...account.utils import store_user_address
from ...discount import DiscountValueType, VoucherType
from ...discount.models import Sale, Voucher
from ...order import OrderStatus
-from ...order.models import Fulfillment, Order, OrderLine, Payment
+from ...order.models import Fulfillment, Order, Payment
from ...product.models import (
AttributeChoiceValue, Category, Collection, Product, ProductAttribute,
ProductImage, ProductType, ProductVariant, Stock, StockLocation)
@@ -392,8 +392,7 @@ def create_order_line(order):
stock.quantity += quantity
stock.quantity_allocated += quantity
stock.save()
- return OrderLine.objects.create(
- order=order,
+ return order.lines.create(
product=product,
product_name=product.name,
product_sku=variant.sku,
diff --git a/saleor/dashboard/order/forms.py b/saleor/dashboard/order/forms.py
index bb2e94bc8d..c78055670c 100644
--- a/saleor/dashboard/order/forms.py
+++ b/saleor/dashboard/order/forms.py
@@ -176,7 +176,7 @@ class ChangeQuantityForm(forms.ModelForm):
class CancelOrderForm(forms.Form):
"""Allow canceling an entire order.
- Deallocates corresponding stocks for each order line.
+ Deallocate or increase corresponding stocks for each order line.
"""
restock = forms.BooleanField(initial=True, required=False)
diff --git a/saleor/order/models.py b/saleor/order/models.py
index 7f914e5b6d..800065e108 100644
--- a/saleor/order/models.py
+++ b/saleor/order/models.py
@@ -154,7 +154,7 @@ class Order(models.Model):
return self.status in statuses
def can_cancel(self):
- return self.status == OrderStatus.UNFULFILLED
+ return self.status != OrderStatus.CANCELED
class OrderLine(models.Model):