Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Update documentation and reorganize imports
NyanKiyoshi03ad80132b3b
diff --git a/docs/architecture/events.rst b/docs/architecture/events.rstindex 115e532b2e..7ec0934647 100644--- a/docs/architecture/events.rst+++ b/docs/architecture/events.rst@@ -72,21 +72,13 @@ Email Event TypesEvents Design--------------The ``OrderEventManager`` class contains a bunch of static methods suffixed by-``_event``. They take care of all the logic and required fields, then-returns an instance of ``OrderEventManager`` to allow the user to commit or-to add more events. This design has for objective to allow-delayed (or not) event creation in the database.+Each package representing an entity (order, account, etc.) that generate events+define both a model and a ``events.py`` file containing a set of functions+having ``_event`` for suffix.-The main power of this design comes when one wants to create multiple-order events in one go. Instead of generating multiple create query, one-can simply pass the objects to django's |QuerySet.bulk_create|_ method.+Those functions are taking care of any logic and required fields for+creating given events.-If one simply does not want to bulk create, delay the creation, one can-directly run ``save()`` for the creation.--.. |QuerySet.bulk_create| replace:: ``QuerySet.bulk_create``-.. _QuerySet.bulk_create: https://docs.djangoproject.com/en/1.10/ref/models/querysets/#django.db.models.query.QuerySet.bulk_createCreating Events---------------@@ -95,18 +87,21 @@ To send an event, simply do the following:.. code-block:: python- from saleor.order.events import note_added_event+ from saleor.order import events# returns an OrderEvent- note_added_event(+ events.note_added_event(order=order, user=user, message='hello world!')If now you want to send a 'sent email' event you would do the following:.. code-block:: python- email_sent_event(- order=order, user=user, email_type=OrderEventsEmails.TRACKING_UPDATED)+ from saleor.order import events++ events.email_sent_event(+ order=order, user=user,+ email_type=events.OrderEventsEmails.TRACKING_UPDATED)Notice how we are providing the email type.diff --git a/saleor/checkout/utils.py b/saleor/checkout/utils.pyindex cbee064966..1f0331d1ab 100644--- a/saleor/checkout/utils.py+++ b/saleor/checkout/utils.py@@ -23,7 +23,7 @@ from ..discount.models import NotApplicable, Voucherfrom ..discount.utils import (get_products_voucher_discount, get_shipping_voucher_discount,get_value_voucher_discount, increase_voucher_usage)-from ..order.events import order_created_event+from ..order import eventsfrom ..order.emails import send_order_confirmationfrom ..order.models import Orderfrom ..shipping.models import ShippingMethod@@ -880,7 +880,7 @@ def create_order(checkout.delete()# Create the order placed- order_created_event(order=order, user=user)+ events.order_created_event(order=order, user=user)# Send the order confirmation emailsend_order_confirmation.delay(order.pk, user.pk)diff --git a/saleor/dashboard/order/forms.py b/saleor/dashboard/order/forms.pyindex 17f1254db9..bc89e4076c 100644--- a/saleor/dashboard/order/forms.py+++ b/saleor/dashboard/order/forms.py@@ -12,9 +12,7 @@ from ...core.exceptions import InsufficientStockfrom ...core.utils.taxes import ZERO_TAXED_MONEYfrom ...discount.models import Voucherfrom ...discount.utils import decrease_voucher_usage, increase_voucher_usage-from ...order import OrderStatus-from ...order.events import (- draft_order_added_products_event, payment_failed_event)+from ...order import OrderStatus, eventsfrom ...order.models import Fulfillment, FulfillmentLine, Order, OrderLinefrom ...order.utils import (add_variant_to_order, cancel_fulfillment, cancel_order,@@ -278,7 +276,7 @@ class BasePaymentForm(forms.Form):except (PaymentError, ValueError) as e:message = str(e)self.payment_error(message)- payment_failed_event(+ events.payment_failed_event(order=self.payment.order, user=user,message=message, payment=self.payment)return False@@ -581,7 +579,7 @@ class AddVariantToOrderForm(forms.Form):quantity = self.cleaned_data.get('quantity')line = add_variant_to_order(self.order, variant, quantity, self.discounts, self.taxes)- draft_order_added_products_event(+ events.draft_order_added_products_event(order=self.order, user=user, order_lines=[(line.quantity, line)])recalculate_order(self.order)diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.pyindex c9065b716f..87b3941b63 100644--- a/saleor/dashboard/order/views.py+++ b/saleor/dashboard/order/views.py@@ -15,16 +15,10 @@ from django_prices.templatetags import prices_i18nfrom ...core.exceptions import InsufficientStockfrom ...core.utils import get_paginator_itemsfrom ...core.utils.taxes import get_taxes_for_address-from ...order import OrderStatus+from ...order import OrderStatus, eventsfrom ...order.emails import (send_fulfillment_confirmation_to_customer, send_fulfillment_update,send_order_confirmation)-from ...order.events import (- OrderEvents, OrderEventsEmails, draft_order_created_event,- email_sent_event, fulfillment_fulfilled_items_event,- fulfillment_tracking_updated_event, order_created_event,- order_note_added_event, order_updated_address_event,- payment_captured_event, payment_refunded_event, payment_voided_event)from ...order.models import Fulfillment, FulfillmentLine, Orderfrom ...order.utils import update_order_prices, update_order_statusfrom ...shipping.models import ShippingMethod@@ -69,7 +63,7 @@ def order_create(request):status=OrderStatus.DRAFT, display_gross_prices=display_gross_prices)# Create the draft creation event- draft_order_created_event(order=order, user=request.user)+ events.draft_order_created_event(order=order, user=request.user)# Send success message and redirect to the draft detailsmessages.success(request, msg)@@ -88,14 +82,11 @@ def create_order_from_draft(request, order_pk):'Dashboard message related to an order','Order created from draft order')- order_created_event(order=order, user=request.user, from_draft=True)+ events.order_created_event(order=order, user=request.user, from_draft=True)messages.success(request, msg)if form.cleaned_data.get('notify_customer'):send_order_confirmation.delay(order.pk, request.user.pk)- email_sent_event(- order=order, email_type=OrderEventsEmails.ORDER,- user=request.user)return redirect('dashboard:order-details', order_pk=order.pk)elif form.errors:status = 400@@ -131,7 +122,7 @@ def order_details(request, order_pk):payment = order.get_last_payment()ctx = {'order': order, 'all_payments': all_payments, 'payment': payment,- 'notes': order.events.filter(type=OrderEvents.NOTE_ADDED),+ 'notes': order.events.filter(type=events.OrderEvents.NOTE_ADDED),'events': order.events.order_by('-date').all(),'order_fulfillments': order.fulfillments.all()}return TemplateResponse(request, 'dashboard/order/detail.html', ctx)@@ -144,7 +135,7 @@ def order_add_note(request, order_pk):form = OrderNoteForm(request.POST or None)status = 200if form.is_valid():- order_note_added_event(+ events.order_note_added_event(order=order, user=request.user,message=form.cleaned_data['message'])msg = pgettext_lazy(@@ -174,7 +165,7 @@ 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)}- payment_captured_event(+ events.payment_captured_event(order=order, user=request.user,amount=amount.amount, payment=payment)messages.success(request, msg)@@ -204,7 +195,7 @@ def refund_payment(request, order_pk, payment_pk):'Dashboard message related to a payment','Refunded %(amount)s') % {'amount': prices_i18n.amount(payment.get_captured_amount())}- payment_refunded_event(+ events.payment_refunded_event(order=order, user=request.user, amount=amount, payment=payment)messages.success(request, msg)return redirect('dashboard:order-details', order_pk=order.pk)@@ -227,7 +218,7 @@ def void_payment(request, order_pk, payment_pk):form = VoidPaymentForm(request.POST or None, payment=payment)if form.is_valid() and form.void(request.user):msg = pgettext_lazy('Dashboard message', 'Voided payment')- payment_voided_event(+ events.payment_voided_event(order=order, user=request.user, payment=payment)messages.success(request, msg)return redirect('dashboard:order-details', order_pk=order.pk)@@ -347,7 +338,7 @@ def order_address(request, order_pk, address_type):if update_prices:update_order_prices(order, request.discounts)if not order.is_draft():- order_updated_address_event(+ events.order_updated_address_event(order=order, user=request.user, address=address)messages.success(request, success_msg)return redirect('dashboard:order-details', order_pk=order_pk)@@ -616,7 +607,7 @@ def fulfill_order_lines(request, order_pk):number='quantity_fulfilled') % {'quantity_fulfilled': quantity_fulfilled}- fulfillment_fulfilled_items_event(+ events.fulfillment_fulfilled_items_event(order=order, user=request.user,quantities=quantities, order_lines=order_lines)@@ -672,13 +663,14 @@ def change_fulfillment_tracking(request, order_pk, fulfillment_pk):request.POST or None, instance=fulfillment)if form.is_valid():form.save()- fulfillment_tracking_updated_event(+ events.fulfillment_tracking_updated_event(order=order, user=request.user,tracking_number=request.POST.get('tracking_number'),fulfillment=fulfillment)if form.cleaned_data.get('send_mail'):- email_sent_event(- order=order, email_type=OrderEventsEmails.TRACKING_UPDATED,+ events.email_sent_event(+ order=order,+ email_type=events.OrderEventsEmails.TRACKING_UPDATED,user=request.user)send_fulfillment_update.delay(order.pk, fulfillment.pk)diff --git a/saleor/dashboard/templatetags/orders.py b/saleor/dashboard/templatetags/orders.pyindex ea312a1cdc..3192404ae6 100644--- a/saleor/dashboard/templatetags/orders.py+++ b/saleor/dashboard/templatetags/orders.py@@ -4,19 +4,19 @@ from django.utils.translation import npgettext_lazy, pgettext_lazyfrom django_prices.templatetags import prices_i18nfrom prices import Money-from ...order.events import OrderEvents, OrderEventsEmails+from ...order import eventsfrom ...order.models import OrderEventregister = Library()EMAIL_CHOICES = {- OrderEventsEmails.PAYMENT: pgettext_lazy(+ events.OrderEventsEmails.PAYMENT: pgettext_lazy('Email type', 'Payment confirmation'),- OrderEventsEmails.SHIPPING: pgettext_lazy(+ events.OrderEventsEmails.SHIPPING: pgettext_lazy('Email type', 'Shipping confirmation'),- OrderEventsEmails.FULFILLMENT: pgettext_lazy(+ events.OrderEventsEmails.FULFILLMENT: pgettext_lazy('Email type', 'Fulfillment confirmation'),- OrderEventsEmails.ORDER: pgettext_lazy(+ events.OrderEventsEmails.ORDER: pgettext_lazy('Email type', 'Order confirmation')}@@ -41,73 +41,73 @@ def display_order_event(order_event: OrderEvent):"""event_type = order_event.typeparams = order_event.parameters- if event_type == OrderEvents.PLACED_FROM_DRAFT:+ if event_type == events.OrderEvents.PLACED_FROM_DRAFT:return pgettext_lazy('Dashboard message related to an order','Order placed from draft order')- if event_type == OrderEvents.PAYMENT_VOIDED:+ if event_type == events.OrderEvents.PAYMENT_VOIDED:return pgettext_lazy('Dashboard message related to an order','Payment was voided by %(user_name)s' % {'user_name': order_event.user})- if event_type == OrderEvents.PAYMENT_REFUNDED:+ if event_type == events.OrderEvents.PAYMENT_REFUNDED:amount = get_money_from_params(params['amount'])return pgettext_lazy('Dashboard message related to an order','Successfully refunded: %(amount)s' % {'amount': prices_i18n.amount(amount)})- if event_type == OrderEvents.PAYMENT_CAPTURED:+ if event_type == events.OrderEvents.PAYMENT_CAPTURED:amount = get_money_from_params(params['amount'])return pgettext_lazy('Dashboard message related to an order','Successfully captured: %(amount)s' % {'amount': prices_i18n.amount(amount)})- if event_type == OrderEvents.ORDER_MARKED_AS_PAID:+ if event_type == events.OrderEvents.ORDER_MARKED_AS_PAID:return pgettext_lazy('Dashboard message related to an order','Order manually marked as paid')- if event_type == OrderEvents.CANCELED:+ if event_type == events.OrderEvents.CANCELED:return pgettext_lazy('Dashboard message related to an order','Order was canceled')- if event_type == OrderEvents.FULFILLMENT_RESTOCKED_ITEMS:+ if event_type == events.OrderEvents.FULFILLMENT_RESTOCKED_ITEMS:return npgettext_lazy('Dashboard message related to an order','We restocked %(quantity)d item','We restocked %(quantity)d items',number='quantity') % {'quantity': params['quantity']}- if event_type == OrderEvents.NOTE_ADDED:+ if event_type == events.OrderEvents.NOTE_ADDED:return pgettext_lazy('Dashboard message related to an order','%(user_name)s added note: %(note)s' % {'note': params['message'],'user_name': order_event.user})- if event_type == OrderEvents.FULFILLMENT_CANCELED:+ if event_type == events.OrderEvents.FULFILLMENT_CANCELED:return pgettext_lazy('Dashboard message','Fulfillment #%(fulfillment)s canceled by %(user_name)s') % {'fulfillment': params['composed_id'],'user_name': order_event.user}- if event_type == OrderEvents.FULFILLMENT_FULFILLED_ITEMS:+ if event_type == events.OrderEvents.FULFILLMENT_FULFILLED_ITEMS:return pgettext_lazy('Dashboard message related to an order','Fulfilled some items')- if event_type == OrderEvents.PLACED:+ if event_type == events.OrderEvents.PLACED:return pgettext_lazy('Dashboard message related to an order','Order was placed')- if event_type == OrderEvents.ORDER_FULLY_PAID:+ if event_type == events.OrderEvents.ORDER_FULLY_PAID:return pgettext_lazy('Dashboard message related to an order','Order was fully paid')- if event_type == OrderEvents.EMAIL_SENT:+ if event_type == events.OrderEvents.EMAIL_SENT:return pgettext_lazy('Dashboard message related to an order','%(email_type)s email was sent to the customer ''(%(email)s)') % {'email_type': EMAIL_CHOICES[params['email_type']],'email': params['email']}- if event_type == OrderEvents.TRACKING_UPDATED:+ if event_type == events.OrderEvents.TRACKING_UPDATED:return pgettext_lazy('Dashboard message related to an order','Fulfillment #%(fulfillment)s tracking was updated to'@@ -115,37 +115,37 @@ def display_order_event(order_event: OrderEvent):'fulfillment': params['composed_id'],'tracking_number': params['tracking_number'],'user_name': order_event.user}- if event_type == OrderEvents.DRAFT_CREATED:+ if event_type == events.OrderEvents.DRAFT_CREATED:return pgettext_lazy('Dashboard message related to an order','The draft was created by %(user_name)s') % {'user_name': order_event.user}- if event_type == OrderEvents.DRAFT_ADDED_PRODUCTS:+ if event_type == events.OrderEvents.DRAFT_ADDED_PRODUCTS:return pgettext_lazy('Dashboard message related to an order','%(user_name)s added some products') % {'user_name': order_event.user}- if event_type == OrderEvents.DRAFT_REMOVED_PRODUCTS:+ if event_type == events.OrderEvents.DRAFT_REMOVED_PRODUCTS:return pgettext_lazy('Dashboard message related to an order','%(user_name)s removed some products') % {'user_name': order_event.user}- if event_type == OrderEvents.OVERSOLD_ITEMS:+ if event_type == events.OrderEvents.OVERSOLD_ITEMS:return pgettext_lazy('Dashboard message related to an order','%(user_name)s placed the order by bypassing oversold items') % {'user_name': order_event.user}- if event_type == OrderEvents.UPDATED_ADDRESS:+ if event_type == events.OrderEvents.UPDATED_ADDRESS:return pgettext_lazy('Dashboard message related to an order','The order address was updated by %(user_name)s') % {'user_name': order_event.user}- if event_type == OrderEvents.PAYMENT_FAILED:+ if event_type == events.OrderEvents.PAYMENT_FAILED:return pgettext_lazy('Dashboard message related to an order','The payment was failed by %(user_name)s') % {'user_name': order_event.user}- if event_type == OrderEvents.OTHER:+ if event_type == events.OrderEvents.OTHER:return order_event.parameters['message']raise ValueError('Not supported event type: %s' % (event_type))diff --git a/saleor/graphql/checkout/mutations.py b/saleor/graphql/checkout/mutations.pyindex d62bd4a6ad..32342cdaa2 100644--- a/saleor/graphql/checkout/mutations.py+++ b/saleor/graphql/checkout/mutations.py@@ -466,7 +466,6 @@ class CheckoutComplete(BaseMutation):payment = checkout.get_last_active_payment()try:- # FIXME: we shouldn't create the order, but only do checksorder = create_order(checkout=checkout,tracking_code=analytics.get_client_id(info.context),diff --git a/saleor/graphql/order/bulk_mutations/orders.py b/saleor/graphql/order/bulk_mutations/orders.pyindex 5c99500246..b0a1aaeb45 100644--- a/saleor/graphql/order/bulk_mutations/orders.py+++ b/saleor/graphql/order/bulk_mutations/orders.py@@ -1,8 +1,6 @@import graphene-from ....order import models-from ....order.events import (- fulfillment_restocked_items_event, order_canceled_event)+from ....order import events, modelsfrom ....order.utils import cancel_orderfrom ...core.mutations import BaseBulkMutationfrom ..mutations.orders import clean_order_cancel@@ -37,7 +35,7 @@ class OrderBulkCancel(BaseBulkMutation):for order in queryset:cancel_order(user=user, order=order, restock=restock)if restock:- fulfillment_restocked_items_event(+ events.fulfillment_restocked_items_event(order=order, user=user, fulfillment=order)- order_canceled_event(order=order, user=user)+ events.order_canceled_event(order=order, user=user)diff --git a/saleor/graphql/order/mutations/draft_orders.py b/saleor/graphql/order/mutations/draft_orders.pyindex f01eaa2543..ee6eb88a25 100644--- a/saleor/graphql/order/mutations/draft_orders.py+++ b/saleor/graphql/order/mutations/draft_orders.py@@ -5,11 +5,7 @@ from graphene.types import InputObjectTypefrom ....account.models import Userfrom ....core.exceptions import InsufficientStockfrom ....core.utils.taxes import ZERO_TAXED_MONEY-from ....order import OrderStatus, models-from ....order.events import (- draft_order_added_products_event, draft_order_created_event,- draft_order_oversold_items_event, draft_order_removed_products_event,- order_created_event)+from ....order import OrderStatus, events, modelsfrom ....order.utils import (add_variant_to_order, allocate_stock, change_order_line_quantity,delete_order_line, recalculate_order)@@ -127,7 +123,7 @@ class DraftOrderCreate(ModelMutation, I18nMixin):track_inventory=False)# New event- draft_order_added_products_event(+ events.draft_order_added_products_event(order=instance, user=info.context.user, order_lines=lines)@classmethod@@ -137,7 +133,8 @@ class DraftOrderCreate(ModelMutation, I18nMixin):# Create draft created event if the instance is from scratchif not created:- draft_order_created_event(order=instance, user=info.context.user)+ events.draft_order_created_event(+ order=instance, user=info.context.user)instance.save(update_fields=['billing_address', 'shipping_address'])@@ -229,11 +226,11 @@ class DraftOrderComplete(BaseMutation):allocate_stock(line.variant, line.variant.quantity_available)oversold_items.append(str(line))- order_created_event(+ events.order_created_event(order=order, user=info.context.user, from_draft=True)if oversold_items:- draft_order_oversold_items_event(+ events.draft_order_oversold_items_event(order=order, user=info.context.user,oversold_items=oversold_items)@@ -285,7 +282,7 @@ class DraftOrderLinesCreate(BaseMutation):for quantity, variant in lines_to_add]# Create the event- draft_order_added_products_event(+ events.draft_order_added_products_event(order=order, user=info.context.user, order_lines=lines_to_add)recalculate_order(order)@@ -317,7 +314,7 @@ class DraftOrderLineDelete(BaseMutation):line.id = db_id# Create the removal event- draft_order_removed_products_event(+ events.draft_order_removed_products_event(order=order, user=info.context.user,order_lines=[(line.quantity, line)])diff --git a/saleor/graphql/order/mutations/fulfillments.py b/saleor/graphql/order/mutations/fulfillments.pyindex ef1f573ba1..8546d20681 100644--- a/saleor/graphql/order/mutations/fulfillments.py+++ b/saleor/graphql/order/mutations/fulfillments.py@@ -2,10 +2,8 @@ import graphenefrom django.core.exceptions import ValidationErrorfrom django.utils.translation import npgettext_lazy, pgettext_lazy-from ....order import models+from ....order import events, modelsfrom ....order.emails import send_fulfillment_confirmation_to_customer-from ....order.events import (- fulfillment_fulfilled_items_event, fulfillment_tracking_updated_event)from ....order.utils import (cancel_fulfillment, fulfill_order_line, update_order_status)from ...core.mutations import BaseMutation@@ -106,7 +104,7 @@ class FulfillmentCreate(BaseMutation):fulfillment.lines.bulk_create(fulfillment_lines)update_order_status(order)- fulfillment_fulfilled_items_event(+ events.fulfillment_fulfilled_items_event(order=order, user=user,quantities=quantities, order_lines=order_lines)@@ -155,7 +153,7 @@ class FulfillmentUpdateTracking(BaseMutation):fulfillment.tracking_number = tracking_numberfulfillment.save()order = fulfillment.order- fulfillment_tracking_updated_event(+ events.fulfillment_tracking_updated_event(order=order, user=info.context.user,tracking_number=tracking_number, fulfillment=fulfillment)return FulfillmentUpdateTracking(fulfillment=fulfillment, order=order)diff --git a/saleor/graphql/order/mutations/orders.py b/saleor/graphql/order/mutations/orders.pyindex 1b70257e4b..c79ab8d6e8 100644--- a/saleor/graphql/order/mutations/orders.py+++ b/saleor/graphql/order/mutations/orders.py@@ -3,10 +3,7 @@ from django.core.exceptions import ValidationErrorfrom ....account.models import Userfrom ....core.utils.taxes import ZERO_TAXED_MONEY-from ....order import models-from ....order.events import (- order_note_added_event, payment_captured_event, payment_failed_event,- payment_refunded_event, payment_voided_event)+from ....order import events, modelsfrom ....order.utils import cancel_orderfrom ....payment import CustomPaymentChoices, PaymentErrorfrom ....payment.utils import (@@ -77,7 +74,7 @@ def try_payment_action(order, user, payment, func, *args, **kwargs):func(*args, **kwargs)except (PaymentError, ValueError) as e:message = str(e)- payment_failed_event(+ events.payment_failed_event(order=order, user=user, message=message, payment=payment)raise ValidationError({'payment': message})return True@@ -196,7 +193,7 @@ class OrderAddNote(BaseMutation):def perform_mutation(cls, _root, info, **data):order = cls.get_node_or_error(info, data.get('id'), only_type=Order)- event = order_note_added_event(+ event = events.order_note_added_event(order=order, user=info.context.user,message=data.get('input')['message'])return OrderAddNote(order=order, event=event)@@ -276,7 +273,7 @@ class OrderCapture(BaseMutation):order, info.context.user, payment,gateway_capture, payment, amount)- payment_captured_event(+ events.payment_captured_event(order=order, user=info.context.user,amount=amount, payment=payment)return OrderCapture(order=order)@@ -303,7 +300,7 @@ class OrderVoid(BaseMutation):try_payment_action(order, info.context.user, payment, gateway_void, payment)- payment_voided_event(+ events.payment_voided_event(order=order, user=info.context.user, payment=payment)return OrderVoid(order=order)@@ -335,7 +332,7 @@ class OrderRefund(BaseMutation):try_payment_action(order, info.context.user, payment, gateway_refund, payment, amount)- payment_refunded_event(+ events.payment_refunded_event(order=order, user=info.context.user,amount=amount, payment=payment)return OrderRefund(order=order)diff --git a/saleor/order/emails.py b/saleor/order/emails.pyindex 3aa15afb89..4d0a3fd9a4 100644--- a/saleor/order/emails.py+++ b/saleor/order/emails.py@@ -3,10 +3,10 @@ from django.conf import settingsfrom django.urls import reversefrom templated_email import send_templated_mail+from . import eventsfrom ..core.emails import get_email_base_contextfrom ..core.utils import build_absolute_urifrom ..seo.schema.email import get_order_confirmation_markup-from .events import OrderEventsEmails, email_sent_eventfrom .models import Fulfillment, OrderCONFIRM_ORDER_TEMPLATE = 'order/confirm_order'@@ -57,9 +57,9 @@ def send_order_confirmation(order_pk, user_pk=None):"""Sends order confirmation email."""email_data = collect_data_for_email(order_pk, CONFIRM_ORDER_TEMPLATE)send_templated_mail(**email_data)- email_sent_event(- order=email_data['context']['order'],- email_type=OrderEventsEmails.ORDER, user=None, user_pk=user_pk)+ events.email_sent_event(+ order=email_data['context']['order'], user=None, user_pk=user_pk,+ email_type=events.OrderEventsEmails.ORDER)@shared_task@@ -72,14 +72,16 @@ def send_fulfillment_confirmation(order_pk, fulfillment_pk):def send_fulfillment_confirmation_to_customer(order, fulfillment, user):send_fulfillment_confirmation.delay(order.pk, fulfillment.pk)- email_sent_event(- order=order, user=user, email_type=OrderEventsEmails.FULFILLMENT)+ events.email_sent_event(+ order=order, user=user,+ email_type=events.OrderEventsEmails.FULFILLMENT)# If digital lines were sent in the fulfillment email,# trigger the eventif any((line for line in order if line.variant.is_digital())):- email_sent_event(- order=order, user=user, email_type=OrderEventsEmails.DIGITAL_LINKS)+ events.email_sent_event(+ order=order, user=user,+ email_type=events.OrderEventsEmails.DIGITAL_LINKS)@shared_taskdiff --git a/saleor/order/models.py b/saleor/order/models.pyindex 77b2af6574..71189f5dbd 100644--- a/saleor/order/models.py+++ b/saleor/order/models.py@@ -411,8 +411,8 @@ class OrderEvent(models.Model):type = models.CharField(max_length=255,choices=[(- type_name.upper(), type_name)- for type_name, _ in OrderEvents.CHOICES])+ type_name.upper(), type_name+ ) for type_name, _ in OrderEvents.CHOICES])order = models.ForeignKey(Order, related_name='events', on_delete=models.CASCADE)parameters = JSONField(diff --git a/saleor/order/utils.py b/saleor/order/utils.pyindex 724c320b2c..1b1046ad5e 100644--- a/saleor/order/utils.py+++ b/saleor/order/utils.py@@ -5,9 +5,7 @@ from django.db import transactionfrom django.shortcuts import get_object_or_404, redirectfrom prices import Money, TaxedMoney-from .events import draft_order_added_products_event, \- draft_order_removed_products_event, fulfillment_restocked_items_event, \- fulfillment_canceled_event, order_canceled_event+from . import eventsfrom ..account.utils import store_user_addressfrom ..checkout import AddressTypefrom ..core.utils.taxes import (@@ -174,9 +172,9 @@ def cancel_order(user, order, restock):Return products to corresponding stocks if restock is set to True."""- order_canceled_event(order=order, user=user)+ events.order_canceled_event(order=order, user=user)if restock:- fulfillment_restocked_items_event(+ events.fulfillment_restocked_items_event(order=order, user=user, fulfillment=order)restock_order_lines(order)@@ -218,10 +216,10 @@ def cancel_fulfillment(user, fulfillment, restock):Return products to corresponding stocks if restock is set to True."""- fulfillment_canceled_event(+ events.fulfillment_canceled_event(order=fulfillment.order, user=user, fulfillment=fulfillment)if restock:- fulfillment_restocked_items_event(+ events.fulfillment_restocked_items_event(order=fulfillment.order, user=user, fulfillment=fulfillment)restock_fulfillment_lines(fulfillment)for line in fulfillment:@@ -297,11 +295,11 @@ def change_order_line_quantity(user, line, old_quantity, new_quantity):# Create the removal eventif quantity_diff > 0:- draft_order_removed_products_event(+ events.draft_order_removed_products_event(order=line.order, user=user,order_lines=[(quantity_diff, line)])elif quantity_diff < 0:- draft_order_added_products_event(+ events.draft_order_added_products_event(order=line.order, user=user,order_lines=[(quantity_diff * -1, line)])diff --git a/saleor/payment/utils.py b/saleor/payment/utils.pyindex 4ebf659125..fa4f514360 100644--- a/saleor/payment/utils.py+++ b/saleor/payment/utils.py@@ -12,10 +12,8 @@ from django.utils.translation import pgettext_lazyfrom ..account.models import Address, Userfrom ..checkout.models import Checkoutfrom ..core import analytics-from ..order import utils as order_utils+from ..order import events, utils as order_utilsfrom ..order.emails import send_payment_confirmation-from ..order.events import order_manually_marked_as_paid_event, \- order_fully_paid_event, email_sent_event, OrderEventsEmailsfrom ..order.models import Orderfrom . import (ChargeStatus, CustomPaymentChoices, GatewayError, OperationType,@@ -76,11 +74,12 @@ def create_payment_information(def handle_fully_paid_order(order):- order_fully_paid_event(order=order)+ events.order_fully_paid_event(order=order)if order.get_user_current_email():- email_sent_event(- order=order, email_type=OrderEventsEmails.PAYMENT, user=None)+ events.email_sent_event(+ order=order, user=None,+ email_type=events.OrderEventsEmails.PAYMENT)send_payment_confirmation.delay(order.pk)if order_utils.order_needs_automatic_fullfilment(order):@@ -174,7 +173,7 @@ def mark_order_as_paid(order: Order, request_user: User):payment.charge_status = ChargeStatus.FULLY_CHARGEDpayment.captured_amount = order.total.gross.amountpayment.save(update_fields=['captured_amount', 'charge_status'])- order_manually_marked_as_paid_event(order=order, user=request_user)+ events.order_manually_marked_as_paid_event(order=order, user=request_user)def create_transaction(diff --git a/tests/test_payment.py b/tests/test_payment.pyindex ad3dcd2466..d06a2a1727 100644--- a/tests/test_payment.py+++ b/tests/test_payment.py@@ -14,7 +14,7 @@ from saleor.payment import (from saleor.payment.interface import GatewayResponsefrom saleor.payment.models import Paymentfrom saleor.payment.utils import (- ALLOWED_GATEWAY_KINDS, REQUIRED_GATEWAY_KEYS, call_gateway,+ ALLOWED_GATEWAY_KINDS, call_gateway,clean_authorize, clean_capture, clean_charge, clean_mark_order_as_paid,create_payment, create_payment_information, create_transaction,gateway_authorize, gateway_capture, gateway_charge,