def run_rejection(self, event: Event, subevent_id: int, user_id: int): user = User.objects.get(pk=user_id) subevent_count = OrderPosition.objects.filter( order=OuterRef('pk'), subevent_id=subevent_id, item__admission=True ).order_by().values('order').annotate(k=Count('id')).values('k') orders = list(event.orders.annotate( pcnt_subevent=Subquery(subevent_count, output_field=IntegerField()), ).filter( pcnt_subevent__gte=1, require_approval=True, status=Order.STATUS_PENDING, )) self.update_state( state='PROGRESS', meta={'value': 0} ) for i, order in enumerate(orders): deny_order( order, user=user, send_mail=True, ) if i % 50 == 0: self.update_state( state='PROGRESS', meta={'value': round(i / len(orders) * 100, 2)} ) return len(orders)
def deny(self, request, **kwargs): send_mail = request.data.get('send_email', True) comment = request.data.get('comment', '') order = self.get_object() try: deny_order( order, user=request.user if request.user.is_authenticated else None, auth=request.auth if isinstance(request.auth, (Device, TeamAPIToken, OAuthAccessToken)) else None, send_mail=send_mail, comment=comment, ) except OrderError as e: return Response({'detail': str(e)}, status=status.HTTP_400_BAD_REQUEST) return self.retrieve(request, [], **kwargs)
def test_deny(event): djmail.outbox = [] event.settings.invoice_generate = 'True' o1 = Order.objects.create( code='FOO', event=event, email='*****@*****.**', status=Order.STATUS_PENDING, datetime=now(), expires=now() - timedelta(days=10), total=10, require_approval=True, locale='en' ) generate_invoice(o1) deny_order(o1) o1.refresh_from_db() assert o1.expires < now() assert o1.status == Order.STATUS_CANCELED assert o1.require_approval assert o1.invoices.count() == 2 assert len(djmail.outbox) == 1 assert 'denied' in djmail.outbox[0].subject