Skip to content

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

Prevent performing actions on removed stock

Anna Siwikf192b354f8b0
diff --git a/saleor/dashboard/order/forms.py b/saleor/dashboard/order/forms.py
index 03d9477376..260ff058a2 100644
--- a/saleor/dashboard/order/forms.py
+++ b/saleor/dashboard/order/forms.py
@@ -141,7 +141,8 @@ class CancelOrderLineForm(forms.Form):
super().__init__(*args, **kwargs)
def cancel_line(self):
- deallocate_stock(self.line.stock, self.line.quantity)
+ if self.line.stock:
+ deallocate_stock(self.line.stock, self.line.quantity)
order = self.line.delivery_group.order
self.line.quantity = 0
remove_empty_groups(self.line)
@@ -320,7 +321,8 @@ class ChangeStockForm(forms.ModelForm):
stock = self.instance.stock
self.instance.stock_location = (
stock.location.name if stock.location else '')
- deallocate_stock(self.old_stock, quantity)
+ if self.old_stock:
+ deallocate_stock(self.old_stock, quantity)
allocate_stock(stock, quantity)
super().save(commit)
merge_duplicates_into_order_line(self.instance)
diff --git a/saleor/order/transitions.py b/saleor/order/transitions.py
index d3bbd096d3..837a3a3e8c 100644
--- a/saleor/order/transitions.py
+++ b/saleor/order/transitions.py
@@ -16,14 +16,17 @@ def cancel_delivery_group(group):
"""Cancels delivery group by returning products to stocks."""
if group.status == GroupStatus.NEW:
for line in group:
- deallocate_stock(line.stock, line.quantity)
+ if line.stock:
+ deallocate_stock(line.stock, line.quantity)
elif group.status == GroupStatus.SHIPPED:
for line in group:
- increase_stock(line.stock, line.quantity)
+ if line.stock:
+ increase_stock(line.stock, line.quantity)
def ship_delivery_group(group, tracking_number=''):
"""Ships delivery group by decreasing products in stocks."""
for line in group.lines.all():
- decrease_stock(line.stock, line.quantity)
+ if line.stock:
+ decrease_stock(line.stock, line.quantity)
group.tracking_number = tracking_number