Skip to content

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

Enable changing quantity to 0

Marcin Gębala2fdc25b91fbf
diff --git a/saleor/dashboard/order/forms.py b/saleor/dashboard/order/forms.py
index 3c15df81b9..30b32e5049 100644
--- a/saleor/dashboard/order/forms.py
+++ b/saleor/dashboard/order/forms.py
@@ -50,7 +50,7 @@ class OrderLineForm(forms.Form):
def save(self, user=None):
new_quantity = self.cleaned_data['quantity']
- if new_quantity != self.item.quantity and new_quantity > 0:
+ if new_quantity != self.item.quantity:
self.item.change_quantity(new_quantity, user)
diff --git a/saleor/order/models.py b/saleor/order/models.py
index f5fe6bcdb4..83a43d3d65 100644
--- a/saleor/order/models.py
+++ b/saleor/order/models.py
@@ -238,18 +238,17 @@ class OrderedItem(models.Model, ItemLine):
def get_quantity(self):
return self.quantity
- def change_quantity(self, quantity, user=None):
+ def change_quantity(self, new_quantity, user=None):
order = self.delivery_group.order
- product = self.product
- if quantity > 0:
- self.quantity = quantity
- self.save()
- elif quantity == 0:
- self.delete()
+ old_quantity = self.quantity
+ self.quantity = new_quantity
+ self.save()
comment = pgettext_lazy(
'Order history',
- 'Changed quantity for product %(product)s: %(quantity)s' % {
- 'quantity': quantity, 'product': product})
+ 'Changed quantity for product %(product)s from %(old_quantity)s \
+ to %(new_quantity)s' % {'new_quantity': new_quantity,
+ 'old_quantity': old_quantity,
+ 'product': self.product})
order.history.create(status=order.status, comment=comment, user=user)