Skip to content

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

Delete creating history entries by order.status_change

michalc266143a9625
diff --git a/saleor/dashboard/order/forms.py b/saleor/dashboard/order/forms.py
index 5094dab8c0..535f3631c2 100644
--- a/saleor/dashboard/order/forms.py
+++ b/saleor/dashboard/order/forms.py
@@ -236,8 +236,7 @@ class ShipGroupForm(forms.ModelForm):
self.instance.change_status(OrderStatus.SHIPPED)
statuses = [g.status for g in order.groups.all()]
if OrderStatus.SHIPPED in statuses and OrderStatus.NEW not in statuses:
- order.change_status(OrderStatus.SHIPPED, pgettext_lazy(
- 'Order status change', 'All items shipped'))
+ order.change_status(OrderStatus.SHIPPED)
class CancelGroupForm(forms.Form):
diff --git a/saleor/order/models.py b/saleor/order/models.py
index 6af39d0ef9..45ebdba581 100644
--- a/saleor/order/models.py
+++ b/saleor/order/models.py
@@ -115,11 +115,10 @@ class Order(models.Model, ItemSet, index.Indexed):
self.token = str(uuid4())
return super(Order, self).save(*args, **kwargs)
- def change_status(self, status, comment=''):
+ def change_status(self, status):
if status != self.status:
self.status = status
self.save()
- self.history.create(status=status, comment=comment)
def get_items(self):
return OrderedItem.objects.filter(delivery_group__order=self)
@@ -320,8 +319,11 @@ class OrderedItemManager(models.Manager):
if not source_group.get_total_quantity() or force:
source_group.delete()
if not order.get_items():
- order.change_status(OrderStatus.CANCELLED, pgettext_lazy(
- 'Order status change', 'Order CANCELLED. No items in order'))
+ order.change_status(OrderStatus.CANCELLED)
+ order.create_history_entry(
+ status=OrderStatus.CANCELLED, comment=pgettext_lazy(
+ 'Order status change',
+ 'Shipment canceled. No items in shipment'))
@python_2_unicode_compatible
@@ -376,8 +378,11 @@ class OrderedItem(models.Model, ItemLine):
if not self.delivery_group.get_total_quantity():
self.delivery_group.delete()
if not order.get_items():
- order.change_status(OrderStatus.CANCELLED, pgettext_lazy(
- 'Order status change', 'Order CANCELLED. No items in order'))
+ order.change_status(OrderStatus.CANCELLED)
+ order.create_history_entry(
+ status=OrderStatus.CANCELLED, comment=pgettext_lazy(
+ 'Order status change',
+ 'Order cancelled. No items in order'))
class PaymentManager(models.Manager):
diff --git a/saleor/order/utils.py b/saleor/order/utils.py
index a8294d2468..11bab68ed0 100644
--- a/saleor/order/utils.py
+++ b/saleor/order/utils.py
@@ -32,8 +32,11 @@ def check_order_status(func):
def order_status_change(sender, instance, **kwargs):
order = instance.order
if order.is_fully_paid():
- order.change_status(OrderStatus.FULLY_PAID, pgettext_lazy(
- 'Order status change', 'Order fully paid'))
+ order.change_status(OrderStatus.FULLY_PAID)
+ order.create_history_entry(
+ status=OrderStatus.FULLY_PAID, comment=pgettext_lazy(
+ 'Order status change',
+ 'Order fully paid'))
instance.send_confirmation_email()
try:
analytics.report_order(order.tracking_client_id, order)
diff --git a/saleor/order/views.py b/saleor/order/views.py
index 852a81ad66..89e41210c5 100644
--- a/saleor/order/views.py
+++ b/saleor/order/views.py
@@ -94,8 +94,10 @@ def start_payment(request, order, variant):
if variant not in [code for code, dummy_name in variant_choices]:
raise Http404('%r is not a valid payment variant' % (variant,))
with transaction.atomic():
- order.change_status(OrderStatus.PAYMENT_PENDING, pgettext_lazy(
- 'Order status change', 'Order is waiting for payment'))
+ order.change_status(OrderStatus.PAYMENT_PENDING)
+ order.create_history_entry(
+ status=OrderStatus.PAYMENT_PENDING, comment=pgettext_lazy(
+ 'Order status change', 'Order is waiting for payment'))
payment, dummy_created = Payment.objects.get_or_create(
variant=variant, status=PaymentStatus.WAITING, order=order,
defaults=defaults)