Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Move order_status_change function to signals file
Anna Siwik74f699419288
diff --git a/saleor/order/signals.py b/saleor/order/signals.pynew file mode 100644index 0000000000..f04c0a8f8b--- /dev/null+++ b/saleor/order/signals.py@@ -0,0 +1,26 @@+import logging+from django.dispatch import receiver+from payments.signals import status_changed++from ..core import analytics+from . import OrderStatus++logger = logging.getLogger(__name__)+++@receiver(status_changed)+def order_status_change(sender, instance, **kwargs):+ """Handles payment status change and sets suitable order status."""+ order = instance.order+ if order.is_fully_paid():+ order.status = OrderStatus.FULLY_PAID+ order.save()+ order.create_history_entry(+ status=OrderStatus.FULLY_PAID, comment=pgettext_lazy(+ 'Order status history entry', 'Order fully paid'))+ instance.send_confirmation_email()+ try:+ analytics.report_order(order.tracking_client_id, order)+ except Exception:+ # Analytics failing should not abort the checkout flow+ logger.exception('Recording order in analytics failed')diff --git a/saleor/order/utils.py b/saleor/order/utils.pyindex b9798fd5d5..7c127015d0 100644--- a/saleor/order/utils.py+++ b/saleor/order/utils.py@@ -1,25 +1,19 @@from __future__ import unicode_literals-import loggingfrom functools import wrapsfrom django.conf import settingsfrom django.db.models import F-from django.dispatch import receiverfrom django.shortcuts import get_object_or_404, redirectfrom django.utils.translation import pgettext_lazy-from payments.signals import status_changedfrom prices import Pricefrom satchless.item import InsufficientStock-from ..core import analyticsfrom ..product.models import Stockfrom ..userprofile.utils import store_user_addressfrom .models import Order, OrderLinefrom . import OrderStatus-logger = logging.getLogger(__name__)-def check_order_status(func):"""Preserves execution of function if order is fully paid by redirecting@@ -36,24 +30,6 @@ def check_order_status(func):return decorator-@receiver(status_changed)-def order_status_change(sender, instance, **kwargs):- """Handles payment status change and sets suitable order status."""- order = instance.order- if order.is_fully_paid():- order.status = OrderStatus.FULLY_PAID- order.save()- order.create_history_entry(- status=OrderStatus.FULLY_PAID, comment=pgettext_lazy(- 'Order status history entry', 'Order fully paid'))- instance.send_confirmation_email()- try:- analytics.report_order(order.tracking_client_id, order)- except Exception:- # Analytics failing should not abort the checkout flow- logger.exception('Recording order in analytics failed')--def cancel_order(order):"""Cancells order by cancelling all associated shipment groups."""for group in order.groups.all():