mirror of
https://github.com/pretix/pretix.git
synced 2026-05-26 18:43:59 +00:00
.
This commit is contained in:
@@ -22,12 +22,12 @@
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
from django.db.models import F, Max, Q
|
|
||||||
from django.utils.timezone import now
|
|
||||||
from django_scopes import scopes_disabled
|
from django_scopes import scopes_disabled
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
|
|
||||||
from pretix.base.models import Order
|
from pretix.base.models import (
|
||||||
|
Invoice, InvoiceAddress, Order, OrderPayment, OrderPosition, OrderRefund,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
@@ -45,17 +45,16 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
@scopes_disabled()
|
@scopes_disabled()
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
t = 0
|
querysets = [
|
||||||
qs = Order.objects.annotate(
|
Order.objects.all(),
|
||||||
last_transaction=Max('transactions__created')
|
OrderPosition.all.all(),
|
||||||
).filter(
|
OrderPayment.objects.all(),
|
||||||
Q(last_transaction__isnull=True) | Q(last_modified__gt=F('last_transaction')),
|
OrderRefund.objects.all(),
|
||||||
require_approval=False,
|
InvoiceAddress.objects.filter(order__isnull=False),
|
||||||
).prefetch_related(
|
Invoice.objects.all(),
|
||||||
'all_positions', 'all_fees'
|
]
|
||||||
).order_by(
|
|
||||||
'pk'
|
for qs in querysets:
|
||||||
)
|
|
||||||
last_pk = 0
|
last_pk = 0
|
||||||
with tqdm(total=qs.count()) as pbar:
|
with tqdm(total=qs.count()) as pbar:
|
||||||
while True:
|
while True:
|
||||||
@@ -64,32 +63,7 @@ class Command(BaseCommand):
|
|||||||
break
|
break
|
||||||
|
|
||||||
for o in batch:
|
for o in batch:
|
||||||
if o.last_transaction is None:
|
o._update_search_index()
|
||||||
tn = o.create_transactions(
|
|
||||||
positions=o.all_positions.all(),
|
|
||||||
fees=o.all_fees.all(),
|
|
||||||
dt_now=o.datetime,
|
|
||||||
migrated=True,
|
|
||||||
is_new=True,
|
|
||||||
_backfill_before_cancellation=True,
|
|
||||||
)
|
|
||||||
o.create_transactions(
|
|
||||||
positions=o.all_positions.all(),
|
|
||||||
fees=o.all_fees.all(),
|
|
||||||
dt_now=o.cancellation_date or (o.expires if o.status == Order.STATUS_EXPIRED else o.datetime),
|
|
||||||
migrated=True,
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
tn = o.create_transactions(
|
|
||||||
positions=o.all_positions.all(),
|
|
||||||
fees=o.all_fees.all(),
|
|
||||||
dt_now=now(),
|
|
||||||
migrated=True,
|
|
||||||
)
|
|
||||||
if tn:
|
|
||||||
t += 1
|
|
||||||
time.sleep(0)
|
time.sleep(0)
|
||||||
pbar.update(1)
|
pbar.update(1)
|
||||||
last_pk = batch[-1].pk
|
last_pk = batch[-1].pk
|
||||||
|
|
||||||
self.stderr.write(self.style.SUCCESS(f'Created transactions for {t} orders.'))
|
|
||||||
|
|||||||
@@ -149,7 +149,9 @@ class SearchIndexModelMixin:
|
|||||||
|
|
||||||
def get_search_index_content(self):
|
def get_search_index_content(self):
|
||||||
for f in self.search_index_fields:
|
for f in self.search_index_fields:
|
||||||
yield str(getattr(self, f))
|
val = getattr(self, f)
|
||||||
|
if val is not None:
|
||||||
|
yield str(val)
|
||||||
|
|
||||||
def _update_search_index(self):
|
def _update_search_index(self):
|
||||||
from .search import OrderSearchIndex
|
from .search import OrderSearchIndex
|
||||||
|
|||||||
@@ -111,6 +111,17 @@ class OrderSearchIndex(models.Model):
|
|||||||
order = obj
|
order = obj
|
||||||
else:
|
else:
|
||||||
order = obj.order
|
order = obj.order
|
||||||
|
|
||||||
|
kwargs = dict(
|
||||||
|
order=order,
|
||||||
|
orderpayment=obj if isinstance(obj, OrderPayment) else None,
|
||||||
|
orderrefund=obj if isinstance(obj, OrderRefund) else None,
|
||||||
|
orderposition=obj if isinstance(obj, OrderPosition) else None,
|
||||||
|
)
|
||||||
|
|
||||||
|
if not index_text.strip():
|
||||||
|
OrderSearchIndex.objects.filter(**kwargs).delete()
|
||||||
|
else:
|
||||||
OrderSearchIndex.objects.update_or_create(
|
OrderSearchIndex.objects.update_or_create(
|
||||||
order=order,
|
order=order,
|
||||||
orderpayment=obj if isinstance(obj, OrderPayment) else None,
|
orderpayment=obj if isinstance(obj, OrderPayment) else None,
|
||||||
|
|||||||
@@ -27,11 +27,11 @@ class PostgreSQLAndStateOnly(migrations.SeparateDatabaseAndState):
|
|||||||
super().__init__(database_operations=operations, state_operations=operations)
|
super().__init__(database_operations=operations, state_operations=operations)
|
||||||
|
|
||||||
def database_forwards(self, app_label, schema_editor, from_state, to_state):
|
def database_forwards(self, app_label, schema_editor, from_state, to_state):
|
||||||
if schema_editor.connection != "postgresql":
|
if schema_editor.connection.vendor != "postgresql":
|
||||||
return
|
return
|
||||||
super().database_forwards(app_label, schema_editor, from_state, to_state)
|
super().database_forwards(app_label, schema_editor, from_state, to_state)
|
||||||
|
|
||||||
def database_backwards(self, app_label, schema_editor, from_state, to_state):
|
def database_backwards(self, app_label, schema_editor, from_state, to_state):
|
||||||
if schema_editor.connection != "postgresql":
|
if schema_editor.connection.vendor != "postgresql":
|
||||||
return
|
return
|
||||||
super().database_forwards(app_label, schema_editor, from_state, to_state)
|
super().database_forwards(app_label, schema_editor, from_state, to_state)
|
||||||
|
|||||||
Reference in New Issue
Block a user