Skip to content

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

Add comments to order.change_status

michalbce1eb5984e0
diff --git a/saleor/dashboard/order/forms.py b/saleor/dashboard/order/forms.py
index 60878ea148..5094dab8c0 100644
--- a/saleor/dashboard/order/forms.py
+++ b/saleor/dashboard/order/forms.py
@@ -3,7 +3,6 @@ from __future__ import unicode_literals
from django import forms
from django.conf import settings
from django.core.validators import MinValueValidator, MaxValueValidator
-from django.shortcuts import get_object_or_404
from django.utils.translation import npgettext_lazy, pgettext_lazy
from django_prices.forms import PriceField
from payments import PaymentError, PaymentStatus
@@ -14,7 +13,7 @@ from ...discount.models import Voucher
from ...order import OrderStatus
from ...order.models import DeliveryGroup, Order, OrderedItem, OrderNote
from ...order.utils import cancel_order, cancel_delivery_group
-from ...product.models import ProductVariant, Stock
+from ...product.models import Stock
class OrderNoteForm(forms.ModelForm):
@@ -237,7 +236,8 @@ 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)
+ order.change_status(OrderStatus.SHIPPED, pgettext_lazy(
+ 'Order status change', 'All items shipped'))
class CancelGroupForm(forms.Form):
diff --git a/saleor/order/models.py b/saleor/order/models.py
index 63d2cbcaba..6af39d0ef9 100644
--- a/saleor/order/models.py
+++ b/saleor/order/models.py
@@ -115,11 +115,11 @@ class Order(models.Model, ItemSet, index.Indexed):
self.token = str(uuid4())
return super(Order, self).save(*args, **kwargs)
- def change_status(self, status):
+ def change_status(self, status, comment=''):
if status != self.status:
self.status = status
self.save()
- self.history.create(status=status)
+ self.history.create(status=status, comment=comment)
def get_items(self):
return OrderedItem.objects.filter(delivery_group__order=self)
@@ -320,7 +320,8 @@ 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)
+ order.change_status(OrderStatus.CANCELLED, pgettext_lazy(
+ 'Order status change', 'Order CANCELLED. No items in order'))
@python_2_unicode_compatible
@@ -375,7 +376,8 @@ 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)
+ order.change_status(OrderStatus.CANCELLED, 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 b419a973be..3dc5d1e4a2 100644
--- a/saleor/order/utils.py
+++ b/saleor/order/utils.py
@@ -3,6 +3,7 @@ from functools import wraps
from django.dispatch import receiver
from django.shortcuts import get_object_or_404, redirect
+from django.utils.translation import pgettext_lazy
from payments.signals import status_changed
from ..core import analytics
@@ -31,7 +32,8 @@ 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)
+ order.change_status(OrderStatus.FULLY_PAID, 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 9929c4202e..f200a708c5 100644
--- a/saleor/order/views.py
+++ b/saleor/order/views.py
@@ -94,7 +94,8 @@ 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)
+ order.change_status(OrderStatus.PAYMENT_PENDING, 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)