From 9d5563018e3956fc386e35a24f51058648aba6eb Mon Sep 17 00:00:00 2001 From: luelista Date: Thu, 2 Oct 2025 09:36:02 +0200 Subject: [PATCH] Add "bulk" argument to order_placed signal (#5505) * datasync: add immediate parameter to enqueue_order * interactive argument for order_placed signal The ``interactive`` argument specifies whether the order was placed interactively, by a customer (as opposed to via a bulk import or the REST API). * use bulk=True instead of interactive=False to mark bulk imports --- src/pretix/api/views/order.py | 2 +- src/pretix/base/services/modelimport.py | 2 +- src/pretix/base/services/orders.py | 2 +- src/pretix/base/signals.py | 9 +++---- src/tests/plugins/autocheckin/test_checkin.py | 24 +++++++++---------- 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/pretix/api/views/order.py b/src/pretix/api/views/order.py index faded5becf..43f5cd93d2 100644 --- a/src/pretix/api/views/order.py +++ b/src/pretix/api/views/order.py @@ -743,7 +743,7 @@ class EventOrderViewSet(OrderViewSetMixin, viewsets.ModelViewSet): user=request.user if request.user.is_authenticated else None, auth=request.auth, ) - order_placed.send(self.request.event, order=order) + order_placed.send(self.request.event, order=order, bulk=False) if order.status == Order.STATUS_PAID: order_paid.send(self.request.event, order=order) order.log_action( diff --git a/src/pretix/base/services/modelimport.py b/src/pretix/base/services/modelimport.py index 4c37a6c99a..2d834ec2c6 100644 --- a/src/pretix/base/services/modelimport.py +++ b/src/pretix/base/services/modelimport.py @@ -221,7 +221,7 @@ def import_orders(event: Event, fileid: str, settings: dict, locale: str, user, for o in orders: with language(o.locale, event.settings.region): - order_placed.send(event, order=o) + order_placed.send(event, order=o, bulk=True) if o.status == Order.STATUS_PAID: order_paid.send(event, order=o) diff --git a/src/pretix/base/services/orders.py b/src/pretix/base/services/orders.py index 3190848160..229bebbc2d 100644 --- a/src/pretix/base/services/orders.py +++ b/src/pretix/base/services/orders.py @@ -1091,7 +1091,7 @@ def _create_order(event: Event, *, email: str, positions: List[CartPosition], no for msg in meta_info.get('confirm_messages', []): order.log_action('pretix.event.order.consent', data={'msg': msg}) - order_placed.send(event, order=order) + order_placed.send(event, order=order, bulk=False) return order, payments diff --git a/src/pretix/base/signals.py b/src/pretix/base/signals.py index d42188d6af..eb3cddff5a 100644 --- a/src/pretix/base/signals.py +++ b/src/pretix/base/signals.py @@ -665,12 +665,13 @@ As with all event-plugin signals, the ``sender`` keyword argument will contain t order_placed = EventPluginSignal() """ -Arguments: ``order`` +Arguments: ``order``, ``bulk`` This signal is sent out every time an order is placed. The order object is given -as the first argument. This signal is *not* sent out if an order is created through -splitting an existing order, so you can not expect to see all orders by listening -to this signal. +as the first argument. The ``bulk`` argument specifies whether the order was placed +as part of a bulk action, e.g. an import from a file. +This signal is *not* sent out if an order is created through splitting an existing order, +so you can not expect to see all orders by listening to this signal. As with all event-plugin signals, the ``sender`` keyword argument will contain the event. """ diff --git a/src/tests/plugins/autocheckin/test_checkin.py b/src/tests/plugins/autocheckin/test_checkin.py index 3c765877aa..9d67895936 100644 --- a/src/tests/plugins/autocheckin/test_checkin.py +++ b/src/tests/plugins/autocheckin/test_checkin.py @@ -54,7 +54,7 @@ def test_sales_channel_all(event, item, order, checkin_list): mode=AutoCheckinRule.MODE_PLACED, all_sales_channels=True, ) - order_placed.send(event, order=order) + order_placed.send(event, order=order, bulk=False) assert order.positions.first().checkins.exists() @@ -67,12 +67,12 @@ def test_sales_channel_limit(event, item, order, checkin_list): all_sales_channels=False, ) - order_placed.send(event, order=order) + order_placed.send(event, order=order, bulk=False) assert not order.positions.first().checkins.exists() acr.limit_sales_channels.add(order.sales_channel) - order_placed.send(event, order=order) + order_placed.send(event, order=order, bulk=False) assert order.positions.first().checkins.exists() @@ -84,7 +84,7 @@ def test_items_all(event, item, order, checkin_list): mode=AutoCheckinRule.MODE_PLACED, all_products=True, ) - order_placed.send(event, order=order) + order_placed.send(event, order=order, bulk=False) assert order.positions.first().checkins.exists() @@ -97,12 +97,12 @@ def test_items_limit(event, item, order, checkin_list): all_products=False, ) - order_placed.send(event, order=order) + order_placed.send(event, order=order, bulk=False) assert not order.positions.first().checkins.exists() acr.limit_products.add(item) - order_placed.send(event, order=order) + order_placed.send(event, order=order, bulk=False) assert order.positions.first().checkins.exists() @@ -124,7 +124,7 @@ def test_variations_limit_mixed_order(event, item, order, checkin_list): ) acr.limit_variations.add(var) - order_placed.send(event, order=order) + order_placed.send(event, order=order, bulk=False) assert order.positions.first().checkins.exists() assert not order.positions.last().checkins.exists() @@ -143,19 +143,19 @@ def test_variations_limit(event, item, order, checkin_list): all_products=False, ) - order_placed.send(event, order=order) + order_placed.send(event, order=order, bulk=False) assert not order.positions.first().checkins.exists() acr.limit_variations.add(var) - order_placed.send(event, order=order) + order_placed.send(event, order=order, bulk=False) assert order.positions.first().checkins.exists() order.positions.first().checkins.all().delete() acr.limit_products.add(item) acr.limit_variations.clear() - order_placed.send(event, order=order) + order_placed.send(event, order=order, bulk=False) assert order.positions.first().checkins.exists() @@ -170,7 +170,7 @@ def test_mode_placed(event, item, order, checkin_list): order_paid.send(event, order=order) assert not order.positions.first().checkins.exists() - order_placed.send(event, order=order) + order_placed.send(event, order=order, bulk=False) assert order.positions.first().checkins.exists() @@ -182,7 +182,7 @@ def test_mode_paid(event, item, order, checkin_list): mode=AutoCheckinRule.MODE_PAID, ) - order_placed.send(event, order=order) + order_placed.send(event, order=order, bulk=False) assert not order.positions.first().checkins.exists() order_paid.send(event, order=order)