Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Prevent performing actions on removed stock
Anna Siwikf192b354f8b0
diff --git a/saleor/dashboard/order/forms.py b/saleor/dashboard/order/forms.pyindex 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.orderself.line.quantity = 0remove_empty_groups(self.line)@@ -320,7 +321,8 @@ class ChangeStockForm(forms.ModelForm):stock = self.instance.stockself.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.pyindex 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