Skip to content

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

Refactor OrderEvents

Pacu2231e43af0a3d
diff --git a/saleor/checkout/views/summary.py b/saleor/checkout/views/summary.py
index 59d5544442..48dbe7862d 100644
--- a/saleor/checkout/views/summary.py
+++ b/saleor/checkout/views/summary.py
@@ -1,12 +1,13 @@
from django.contrib import messages
from django.shortcuts import redirect
from django.template.response import TemplateResponse
-from django.utils.translation import pgettext, pgettext_lazy
+from django.utils.translation import pgettext
from ...account.models import Address
from ...core import analytics
from ...core.exceptions import InsufficientStock
from ...order.emails import send_order_confirmation
+from ...order.models import OrderHistoryEntry
from ..forms import CartNoteForm
from ..utils import (
create_order, get_cart_data_for_checkout, get_taxes_for_cart,
@@ -34,11 +35,12 @@ def handle_order_placement(request, cart):
messages.warning(request, msg)
return redirect('checkout:summary')
- user = cart.user
cart.delete()
- msg = pgettext_lazy('Order status history entry', 'Order was placed')
- order.history.create(user=user, content=msg)
+ order.history.create(event=OrderHistoryEntry.ORDER_PLACED)
send_order_confirmation.delay(order.pk)
+ order.history.create(
+ event=OrderHistoryEntry.EMAIL_ORDER_CONFIRMATION_SEND,
+ parameters={'email': order.get_user_current_email()})
return redirect('order:payment', token=order.token)
diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.py
index 9a11e8499c..05dba7ffc2 100644
--- a/saleor/dashboard/order/views.py
+++ b/saleor/dashboard/order/views.py
@@ -17,7 +17,7 @@ from ...core.exceptions import InsufficientStock
from ...core.utils import get_paginator_items
from ...core.utils.taxes import (
ZERO_MONEY, ZERO_TAXED_MONEY, get_taxes_for_address)
-from ...order import CustomPaymentChoices, OrderStatus
+from ...order import CustomPaymentChoices, OrderEvents, OrderStatus
from ...order.emails import (
send_fulfillment_confirmation, send_fulfillment_update,
send_order_confirmation)
@@ -79,15 +79,14 @@ def create_order_from_draft(request, order_pk):
msg = pgettext_lazy(
'Dashboard message related to an order',
'Order created from draft order')
- order.history.create(content=msg, user=request.user)
+ order.history.create(
+ change_author=request.user, event=OrderEvents.ORDER_DRAFT_PLACED)
messages.success(request, msg)
if form.cleaned_data.get('notify_customer'):
send_order_confirmation.delay(order.pk)
- send_mail_msg = pgettext_lazy(
- 'Dashboard message related to an order',
- 'Order confirmation email was sent to user'
- '(%(email)s)') % {'email': order.get_user_current_email()}
- order.history.create(content=send_mail_msg, user=request.user)
+ order.history.create(
+ parameters={'email': order.get_user_current_email()},
+ event=OrderEvents.EMAIL_ORDER_CONFIRMATION_SEND)
return redirect('dashboard:order-details', order_pk=order.pk)
elif form.errors:
status = 400
@@ -164,7 +163,8 @@ def order_add_note(request, order_pk):
'Added note')
messages.success(request, msg)
if not order.is_draft():
- order.history.create(content=msg, user=request.user)
+ order.history.create(
+ change_author=request.user, event=OrderEvents.NOTE_ADDED)
elif form.errors:
status = 400
ctx = {'order': order, 'form': form}
@@ -187,7 +187,9 @@ def capture_payment(request, order_pk, payment_pk):
msg = pgettext_lazy(
'Dashboard message related to a payment',
'Captured %(amount)s') % {'amount': prices_i18n.amount(amount)}
- order.history.create(content=msg, user=request.user)
+ order.history.create(
+ parameters={'amount': amount},
+ change_author=request.user, event=OrderEvents.PAYMENT_CAPTURED)
messages.success(request, msg)
return redirect('dashboard:order-details', order_pk=order.pk)
status = 400 if form.errors else 200
@@ -211,7 +213,9 @@ def refund_payment(request, order_pk, payment_pk):
msg = pgettext_lazy(
'Dashboard message related to a payment',
'Refunded %(amount)s') % {'amount': prices_i18n.amount(amount)}
- order.history.create(content=msg, user=request.user)
+ order.history.create(
+ parameters={'amount': amount},
+ change_author=request.user, event=OrderEvents.PAYMENT_REFUNDED)
messages.success(request, msg)
return redirect('dashboard:order-details', order_pk=order.pk)
status = 400 if form.errors else 200
@@ -230,7 +234,9 @@ def release_payment(request, order_pk, payment_pk):
form = ReleasePaymentForm(request.POST or None, payment=payment)
if form.is_valid() and form.release():
msg = pgettext_lazy('Dashboard message', 'Released payment')
- order.history.create(content=msg, user=request.user)
+ order.history.create(
+ change_author=request.user,
+ event=OrderEvents.PAYMENT_RELEASED)
messages.success(request, msg)
return redirect('dashboard:order-details', order_pk=order.pk)
status = 400 if form.errors else 200
@@ -349,7 +355,8 @@ def order_address(request, order_pk, address_type):
if update_prices:
update_order_prices(order, request.discounts)
if not order.is_draft():
- order.history.create(content=success_msg, user=request.user)
+ order.history.create(
+ change_author=request.user, event=OrderEvents.ORDER_UPDATED)
messages.success(request, success_msg)
return redirect('dashboard:order-details', order_pk=order_pk)
ctx = {'order': order, 'address_type': address_type, 'form': form}
@@ -487,13 +494,12 @@ def cancel_order(request, order_pk):
with transaction.atomic():
form.cancel_order()
if form.cleaned_data.get('restock'):
- restock_msg = npgettext_lazy(
- 'Dashboard message',
- 'Restocked %(quantity)d item',
- 'Restocked %(quantity)d items',
- 'quantity') % {'quantity': order.get_total_quantity()}
- order.history.create(content=restock_msg, user=request.user)
- order.history.create(content=msg, user=request.user)
+ order.history.create(
+ change_author=request.user,
+ event=OrderEvents.ORDER_UPDATED)
+ order.history.create(
+ change_author=request.user,
+ event=OrderEvents.ORDER_CANCELED)
messages.success(request, msg)
return redirect('dashboard:order-details', order_pk=order.pk)
# TODO: send status confirmation email
@@ -540,12 +546,14 @@ def mark_order_as_paid(request, order_pk):
status = 200
form = OrderMarkAsPaidForm(request.POST or None, order=order)
if form.is_valid():
+ with transaction.atomic():
+ form.save()
+ order.history.create(
+ change_author=request.user,
+ event=OrderEvents.ORDER_MARKED_AS_PAID)
msg = pgettext_lazy(
'Dashboard message',
'Order manually marked as paid')
- with transaction.atomic():
- form.save()
- order.history.create(content=msg, user=request.user)
messages.success(request, msg)
return redirect('dashboard:order-details', order_pk=order.pk)
elif form.errors:
@@ -614,14 +622,16 @@ def fulfill_order_lines(request, order_pk):
'Fulfilled %(quantity_fulfilled)d items',
'quantity_fulfilled') % {
'quantity_fulfilled': quantity_fulfilled}
- order.history.create(content=msg, user=request.user)
+ order.history.create(
+ parameters={'quantity': quantity_fulfilled},
+ change_author=request.user,
+ event=OrderEvents.FULFILLMENT_FULFILLED_ITEMS)
if form.cleaned_data.get('send_mail'):
send_fulfillment_confirmation.delay(order.pk, fulfillment.pk)
- send_mail_msg = pgettext_lazy(
- 'Dashboard message related to an order',
- 'Shipping confirmation email was sent to user'
- '(%(email)s)') % {'email': order.get_user_current_email()}
- order.history.create(content=send_mail_msg, user=request.user)
+ order.history.create(
+ parameters={'email': order.get_user_current_email()},
+ change_author=request.user,
+ event=OrderEvents.EMAIL_SHIPPING_CONFIRMATION_SEND)
else:
msg = pgettext_lazy(
'Dashboard message related to an order', 'No items fulfilled')
@@ -651,14 +661,13 @@ def cancel_fulfillment(request, order_pk, fulfillment_pk):
with transaction.atomic():
form.cancel_fulfillment()
if form.cleaned_data.get('restock'):
- restock_msg = npgettext_lazy(
- 'Dashboard message',
- 'Restocked %(quantity)d item',
- 'Restocked %(quantity)d items',
- 'quantity') % {
- 'quantity': fulfillment.get_total_quantity()}
- order.history.create(content=restock_msg, user=request.user)
- order.history.create(content=msg, user=request.user)
+ order.history.create(
+ parameters={'quantity': fulfillment.get_total_quantity()},
+ change_author=request.user,
+ event=OrderEvents.FULFILLMENT_RESTOCKED_ITEMS)
+ order.history.create(
+ change_author=request.user,
+ event=OrderEvents.FULFILLMENT_CANCELED)
messages.success(request, msg)
return redirect('dashboard:order-details', order_pk=order.pk)
elif form.errors:
@@ -680,26 +689,18 @@ def change_fulfillment_tracking(request, order_pk, fulfillment_pk):
request.POST or None, instance=fulfillment)
if form.is_valid():
form.save()
- if fulfillment.tracking_number:
- msg = pgettext_lazy(
- 'Dashboard message',
- 'Fulfillment #%(fulfillment)s tracking number changed to: '
- '#%(tracking_number)s') % {
- 'fulfillment': fulfillment.composed_id,
- 'tracking_number': fulfillment.tracking_number}
- else:
- msg = pgettext_lazy(
- 'Dashboard message',
- 'Fulfillment #%(fulfillment)s tracking number removed') % {
- 'fulfillment': fulfillment.composed_id}
- order.history.create(content=msg, user=request.user)
+ order.history.create(
+ change_author=request.user, event=OrderEvents.ORDER_UPDATED)
if form.cleaned_data.get('send_mail'):
send_fulfillment_update.delay(order.pk, fulfillment.pk)
- send_mail_msg = pgettext_lazy(
- 'Dashboard message related to an order',
- 'Shipping update email was sent to user (%(email)s)') % {
- 'email': order.get_user_current_email()}
- order.history.create(content=send_mail_msg, user=request.user)
+ order.history.create(
+ parameters={'email': order.get_user_current_email()},
+ change_author=request.user,
+ event=OrderEvents.EMAIL_SHIPPING_CONFIRMATION_SEND)
+ msg = pgettext_lazy(
+ 'Dashboard message',
+ 'Fulfillment #%(fulfillment)s tracking number updated') % {
+ 'fulfillment': fulfillment.composed_id}
messages.success(request, msg)
return redirect('dashboard:order-details', order_pk=order.pk)
elif form.errors:
diff --git a/saleor/graphql/order/mutations/draft_orders.py b/saleor/graphql/order/mutations/draft_orders.py
index f356a5d844..c1eb688e3d 100644
--- a/saleor/graphql/order/mutations/draft_orders.py
+++ b/saleor/graphql/order/mutations/draft_orders.py
@@ -6,7 +6,7 @@ from graphql_jwt.decorators import permission_required
from ....account.models import Address
from ....core.exceptions import InsufficientStock
from ....core.utils.taxes import ZERO_TAXED_MONEY
-from ....order import OrderStatus, models
+from ....order import OrderEvents, OrderStatus, models
from ....order.utils import add_variant_to_order, recalculate_order
from ...account.types import AddressInput
from ...core.mutations import BaseMutation, ModelDeleteMutation, ModelMutation
@@ -221,9 +221,7 @@ class DraftOrderComplete(BaseMutation):
if order.shipping_address:
order.shipping_address.delete()
order.save()
-
- msg = pgettext_lazy(
- 'Dashboard message related to an order',
- 'Order created from draft order')
- order.history.create(content=msg, user=info.context.user)
+ order.history.create(
+ event=OrderEvents.ORDER_DRAFT_PLACED,
+ change_author=info.context.user)
return DraftOrderComplete(order=order)
diff --git a/saleor/graphql/order/mutations/fulfillments.py b/saleor/graphql/order/mutations/fulfillments.py
index d49cee4d4f..cd84e4f4b1 100644
--- a/saleor/graphql/order/mutations/fulfillments.py
+++ b/saleor/graphql/order/mutations/fulfillments.py
@@ -3,7 +3,7 @@ from django.utils.translation import npgettext_lazy, pgettext_lazy
from graphql_jwt.decorators import permission_required
from ....dashboard.order.utils import fulfill_order_line
-from ....order import models
+from ....order import OrderEvents, models
from ....order.emails import send_fulfillment_confirmation
from ....order.utils import cancel_fulfillment, update_order_status
from ...core.mutations import BaseMutation, ModelMutation
@@ -116,22 +116,18 @@ class FulfillmentCreate(ModelMutation):
quantity=line[1]) for line in lines_to_fulfill]
models.FulfillmentLine.objects.bulk_create(fulfillment_lines)
update_order_status(order)
- msg = npgettext_lazy(
- 'Dashboard message related to an order',
- 'Fulfilled %(quantity_fulfilled)d item',
- 'Fulfilled %(quantity_fulfilled)d items',
- 'quantity_fulfilled') % {
- 'quantity_fulfilled': quantity_fulfilled}
- order.history.create(content=msg, user=info.context.user)
+ order.history.create(
+ parameters={'quantity': quantity_fulfilled},
+ event=OrderEvents.FULFILLMENT_FULFILLED_ITEMS,
+ change_author=info.context.user)
super().save(info, instance, cleaned_input)
if cleaned_input.get('notify_customer'):
send_fulfillment_confirmation.delay(order.pk, instance.pk)
- send_mail_msg = pgettext_lazy(
- 'Dashboard message related to an order',
- 'Shipping confirmation email was sent to user'
- '(%(email)s)') % {'email': order.get_user_current_email()}
- order.history.create(content=send_mail_msg, user=info.context.user)
+ order.history.create(
+ parameters={'email': order.get_user_current_email()},
+ event=OrderEvents.EMAIL_SHIPPING_CONFIRMATION_SEND,
+ change_author=info.context.user)
class FulfillmentUpdate(FulfillmentCreate):
@@ -182,15 +178,13 @@ class FulfillmentCancel(BaseMutation):
cancel_fulfillment(fulfillment, restock)
if restock:
- msg = npgettext_lazy(
- 'Dashboard message',
- 'Restocked %(quantity)d item',
- 'Restocked %(quantity)d items',
- 'quantity') % {'quantity': fulfillment.get_total_quantity()}
+ order.history.create(
+ parameters={'quantity': fulfillment.get_total_quantity()},
+ event=OrderEvents.FULFILLMENT_RESTOCKED_ITEMS,
+ change_author=info.context.user)
else:
- msg = pgettext_lazy(
- 'Dashboard message',
- 'Fulfillment #%(fulfillment)s canceled') % {
- 'fulfillment': fulfillment.composed_id}
- order.history.create(content=msg, user=info.context.user)
+ order.history.create(
+ parameters={'id': fulfillment.composed_id},
+ event=OrderEvents.FULFILLMENT_CANCELED,
+ change_author=info.context.user)
return FulfillmentCancel(fulfillment=fulfillment)
diff --git a/saleor/graphql/order/mutations/orders.py b/saleor/graphql/order/mutations/orders.py
index 90a9333e90..ee1fea8ba1 100644
--- a/saleor/graphql/order/mutations/orders.py
+++ b/saleor/graphql/order/mutations/orders.py
@@ -1,9 +1,9 @@
import graphene
-from django.utils.translation import npgettext_lazy, pgettext_lazy
+from django.utils.translation import pgettext_lazy
from graphql_jwt.decorators import permission_required
from payments import PaymentError, PaymentStatus
-from ....order import CustomPaymentChoices, models
+from ....order import CustomPaymentChoices, OrderEvents, models
from ....order.utils import cancel_order
from ...account.types import AddressInput
from ...core.mutations import BaseMutation, ModelMutation
@@ -86,9 +86,9 @@ class OrderAddNote(ModelMutation):
@classmethod
def save(cls, info, instance, cleaned_input):
super().save(info, instance, cleaned_input)
- msg = pgettext_lazy(
- 'Dashboard message related to an order', 'Added note')
- instance.order.history.create(content=msg, user=info.context.user)
+ instance.order.history.create(
+ event=OrderEvents.NOTE_ADDED,
+ change_author=info.context.user)
class OrderCancel(BaseMutation):
@@ -115,17 +115,14 @@ class OrderCancel(BaseMutation):
cancel_order(order=order, restock=restock)
if restock:
- restock_msg = npgettext_lazy(
- 'Dashboard message related to an order',
- 'Restocked %(quantity)d item',
- 'Restocked %(quantity)d items',
- 'quantity') % {'quantity': order.get_total_quantity()}
order.history.create(
- content=restock_msg, user=info.context.user)
+ event=OrderEvents.FULFILLMENT_RESTOCKED_ITEMS,
+ change_author=info.context.user,
+ parameters={'quantity': order.get_total_quantity()})
else:
- msg = pgettext_lazy(
- 'Dashboard message related to an order', 'Order canceled')
- order.history.create(content=msg, user=info.context.user)
+ order.history.create(
+ event=OrderEvents.ORDER_CANCELED,
+ change_author=info.context.user)
return OrderCancel(order=order)
@@ -166,10 +163,10 @@ class OrderMarkAsPaid(BaseMutation):
variant=CustomPaymentChoices.MANUAL,
status=PaymentStatus.CONFIRMED, order=order,
defaults=defaults)
- msg = pgettext_lazy(
- 'Dashboard message related to an order',
- 'Order manually marked as paid.')
- order.history.create(content=msg, user=info.context.user)
+
+ order.history.create(
+ event=OrderEvents.ORDER_MARKED_AS_PAID,
+ change_author=info.context.user)
return OrderMarkAsPaid(order=order)
@@ -198,10 +195,9 @@ class OrderCapture(BaseMutation):
if errors:
return OrderCapture(errors=errors)
- msg = pgettext_lazy(
- 'Dashboard message related to an order',
- 'Captured %(amount)s' % {'amount': amount})
- order.history.create(content=msg, user=info.context.user)
+ order.history.create(
+ parameters={'amount': amount}, event=OrderEvents.PAYMENT_CAPTURED,
+ change_author=info.context.user)
return OrderCapture(order=order)
@@ -228,10 +224,9 @@ class OrderRelease(BaseMutation):
if errors:
return OrderRelease(errors=errors)
- msg = pgettext_lazy(
- 'Dashboard message related to an order',
- 'Released payment')
- order.history.create(content=msg, user=info.context.user)
+ order.history.create(
+ event=OrderEvents.PAYMENT_RELEASED,
+ change_author=info.context.user)
return OrderRelease(order=order)
@@ -260,8 +255,8 @@ class OrderRefund(BaseMutation):
if errors:
return OrderRefund(errors=errors)
- msg = pgettext_lazy(
- 'Dashboard message related to an order',
- 'Refunded %(amount)s' % {'amount': amount})
- order.history.create(content=msg, user=info.context.user)
+ order.history.create(
+ event=OrderEvents.PAYMENT_REFUNDED,
+ change_author=info.context.user,
+ parameters={'amount': amount})
return OrderRefund(order=order)
diff --git a/saleor/order/__init__.py b/saleor/order/__init__.py
index fef3c2559f..4fbc392b7d 100644
--- a/saleor/order/__init__.py
+++ b/saleor/order/__init__.py
@@ -1,5 +1,6 @@
from django.apps import AppConfig
from django.utils.translation import pgettext_lazy
+from enum import Enum
class OrderAppConfig(AppConfig):
@@ -56,3 +57,25 @@ class CustomPaymentChoices:
CHOICES = [
(MANUAL, pgettext_lazy('Custom payment choice type', 'Manual'))]
+
+
+class OrderEvents(Enum):
+ ORDER_PLACED = 'placed'
+ ORDER_DRAFT_PLACED = 'draft_placed'
+ ORDER_MARKED_AS_PAID = 'marked_as_paid'
+ ORDER_CANCELED = 'canceled'
+ ORDER_FULLY_PAID = 'order_paid'
+ ORDER_UPDATED = 'order_updated'
+
+ EMAIL_ORDER_CONFIRMATION_SEND = 'order_confirmation_mail_send'
+ EMAIL_SHIPPING_CONFIRMATION_SEND = 'shipping_confirmation_mail_send'
+
+ PAYMENT_CAPTURED = 'captured'
+ PAYMENT_REFUNDED = 'refunded'
+ PAYMENT_RELEASED = 'released'
+
+ FULFILLMENT_CANCELED = 'fulfillment_canceled'
+ FULFILLMENT_RESTOCKED_ITEMS = 'restocked_items'
+ FULFILLMENT_FULFILLED_ITEMS = 'fulfilled_items'
+
+ NOTE_ADDED = 'note_added'
diff --git a/saleor/order/models.py b/saleor/order/models.py
index 223ab88743..4f7f9a49cc 100644
--- a/saleor/order/models.py
+++ b/saleor/order/models.py
@@ -11,12 +11,13 @@ from django.utils.timezone import now
from django.utils.translation import pgettext_lazy
from django_measurement.models import MeasurementField
from django_prices.models import MoneyField, TaxedMoneyField
+from jsonfield import JSONField
from measurement.measures import Weight
from payments import PaymentStatus, PurchasedItem
from payments.models import BasePayment
from prices import Money, TaxedMoney
-from . import FulfillmentStatus, OrderStatus
+from . import FulfillmentStatus, OrderEvents, OrderStatus
from ..account.models import Address
from ..core.models import BaseNote
from ..core.utils import build_absolute_uri
@@ -315,16 +316,19 @@ class Payment(BasePayment):
class OrderHistoryEntry(models.Model):
- date = models.DateTimeField(default=now, editable=False)
+ happened_at = models.DateTimeField(default=now, editable=False)
+ event = models.CharField(
+ max_length=255,
+ choices=((event, event.value) for event in OrderEvents))
order = models.ForeignKey(
Order, related_name='history', on_delete=models.CASCADE)
- content = models.TextField()
- user = models.ForeignKey(
+ parameters = JSONField(blank=True, default={})
+ change_author = models.ForeignKey(
settings.AUTH_USER_MODEL, blank=True, null=True,
- on_delete=models.SET_NULL)
+ on_delete=models.SET_NULL, related_name='+')
class Meta:
- ordering = ('date', )
+ ordering = ('happened_at', )
class OrderNote(BaseNote):
diff --git a/saleor/order/signals.py b/saleor/order/signals.py
index 231dffc332..da5a4b59f9 100644
--- a/saleor/order/signals.py
+++ b/saleor/order/signals.py
@@ -1,9 +1,8 @@
import logging
-from django.utils.translation import pgettext_lazy
-
from ..core import analytics
from .emails import send_payment_confirmation
+from . import OrderEvents
logger = logging.getLogger(__name__)
@@ -12,10 +11,12 @@ def order_status_change(sender, instance, **kwargs):
"""Handle payment status change and set suitable order status."""
order = instance.order
if order.is_fully_paid():
- msg = pgettext_lazy('Order status history entry', 'Order fully paid')
- order.history.create(content=msg)
+ order.history.create(event=OrderEvents.ORDER_FULLY_PAID)
if order.get_user_current_email():
send_payment_confirmation.delay(order.pk)
+ # TODO send payment confirmation
+ order.history.create(
+ event=OrderEvents.EMAIL_ORDER_CONFIRMATION_SEND)
try:
analytics.report_order(order.tracking_client_id, order)
except Exception:
diff --git a/saleor/order/utils.py b/saleor/order/utils.py
index 35db6eac29..ce1a8820c9 100644
--- a/saleor/order/utils.py
+++ b/saleor/order/utils.py
@@ -1,6 +1,7 @@
from functools import wraps
from django.shortcuts import get_object_or_404, redirect
+from django.utils.translation import pgettext_lazy, npgettext_lazy
from ..account.utils import store_user_address
from ..checkout import AddressType
@@ -8,9 +9,10 @@ from ..core.utils.taxes import (
ZERO_MONEY, get_tax_rate_by_name, get_taxes_for_address)
from ..dashboard.order.utils import get_voucher_discount_for_order
from ..discount.models import NotApplicable
-from ..order import FulfillmentStatus, OrderStatus
+from ..order import FulfillmentStatus, OrderEvents, OrderStatus
from ..order.models import OrderLine
from ..product.utils import allocate_stock, deallocate_stock, increase_stock
+from django_prices.templatetags import prices_i18n
def check_order_status(func):
@@ -207,3 +209,65 @@ def restock_fulfillment_lines(fulfillment):
if line.order_line.variant and line.order_line.variant.track_inventory:
increase_stock(
line.order_line.variant, line.quantity, allocate=True)
+
+
+def display_order_event(event_type, params):
+ """This function is to keep backwards compatibility with the old dashboard
+ and new type of order events (storing enums instead of messages)
+ """
+ if event_type == OrderEvents.ORDER_DRAFT_PLACED:
+ return pgettext_lazy(
+ 'Dashboard message related to an order',
+ 'Order created from draft order')
+ if event_type == OrderEvents.EMAIL_ORDER_CONFIRMATION_SEND:
+ return pgettext_lazy(
+ 'Dashboard message related to an order',
+ 'Order confirmation email was sent to user'
+ '(%(email)s)') % {'email': params['email']}
+ if event_type == OrderEvents.PAYMENT_RELEASED:
+ return pgettext_lazy(
+ 'Dashboard message related to an order', 'Released payment')
+ if event_type == OrderEvents.PAYMENT_REFUNDED:
+ return pgettext_lazy(
+ 'Dashboard message related to an order',
+ 'Refunded %(amount)s' % {
+ 'amount': prices_i18n.amount(params['amount'])})
+ if event_type == OrderEvents.PAYMENT_CAPTURED:
+ return pgettext_lazy(
+ 'Dashboard message related to an order',
+ 'Captured %(amount)s' % {
+ 'amount': prices_i18n.amount(params['amount'])})
+ if event_type == OrderEvents.ORDER_MARKED_AS_PAID:
+ return pgettext_lazy(
+ 'Dashboard message related to an order',
+ 'Order manually marked as paid.')
+ if event_type == OrderEvents.ORDER_CANCELED:
+ return pgettext_lazy(
+ 'Dashboard message related to an order', 'Order canceled')
+ if event_type == OrderEvents.FULFILLMENT_RESTOCKED_ITEMS:
+ return npgettext_lazy(
+ 'Dashboard message related to an order',
+ 'Restocked %(quantity)d item',
+ 'Restocked %(quantity)d items',
+ 'quantity') % {'quantity': params['quantity']}
+ if event_type == OrderEvents.NOTE_ADDED:
+ return pgettext_lazy(
+ 'Dashboard message related to an order',
+ 'Added note: %(note)s' % {'note': params['message']})
+ if event_type == OrderEvents.FULFILLMENT_CANCELED:
+ return pgettext_lazy(
+ 'Dashboard message',
+ 'Fulfillment #%(fulfillment)s canceled') % {
+ 'fulfillment': params['id']}
+ if event_type == OrderEvents.FULFILLMENT_FULFILLED_ITEMS:
+ return npgettext_lazy(
+ 'Dashboard message related to an order',
+ 'Fulfilled %(quantity_fulfilled)d item',
+ 'Fulfilled %(quantity_fulfilled)d items',
+ 'quantity_fulfilled') % {
+ 'quantity_fulfilled': params['quantity']}
+ if event_type == OrderEvents.EMAIL_SHIPPING_CONFIRMATION_SEND:
+ return pgettext_lazy(
+ 'Dashboard message related to an order',
+ 'Shipping confirmation email was sent to user'
+ '(%(email)s)') % {'email': params['email']}