forked from CGM_Public/pretix_original
Fix #571 -- Partial payments and refunds
This commit is contained in:
81
src/pretix/base/migrations/0096_auto_20180722_0801.py
Normal file
81
src/pretix/base/migrations/0096_auto_20180722_0801.py
Normal file
@@ -0,0 +1,81 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.13 on 2018-07-22 08:01
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('pretixbase', '0095_auto_20180604_1129'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='OrderPayment',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('local_id', models.PositiveIntegerField()),
|
||||
('state', models.CharField(choices=[('created', 'created'), ('pending', 'pending'), ('confirmed', 'confirmed'), ('canceled', 'canceled'), ('failed', 'failed'), ('refunded', 'refunded')], max_length=190)),
|
||||
('amount', models.DecimalField(decimal_places=2, max_digits=10, verbose_name='Amount')),
|
||||
('created', models.DateTimeField(auto_now_add=True)),
|
||||
('payment_date', models.DateTimeField(blank=True, null=True)),
|
||||
('provider', models.CharField(blank=True, max_length=255, null=True, verbose_name='Payment provider')),
|
||||
('info', models.TextField(blank=True, null=True, verbose_name='Payment information')),
|
||||
('migrated', models.BooleanField(default=False)),
|
||||
],
|
||||
options={
|
||||
'ordering': ('local_id',),
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='OrderRefund',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('local_id', models.PositiveIntegerField()),
|
||||
('state', models.CharField(choices=[('external', 'started externally'), ('created', 'created'), ('transit', 'in transit'), ('done', 'done'), ('failed', 'failed'), ('canceled', 'canceled')], max_length=190)),
|
||||
('source', models.CharField(choices=[('admin', 'Organizer'), ('buyer', 'Customer'), ('external', 'External')], max_length=190)),
|
||||
('amount', models.DecimalField(decimal_places=2, max_digits=10, verbose_name='Amount')),
|
||||
('created', models.DateTimeField(auto_now_add=True)),
|
||||
('execution_date', models.DateTimeField(blank=True, null=True)),
|
||||
('provider', models.CharField(blank=True, max_length=255, null=True, verbose_name='Payment provider')),
|
||||
('info', models.TextField(blank=True, null=True, verbose_name='Payment information')),
|
||||
('order', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='refunds', to='pretixbase.Order', verbose_name='Order')),
|
||||
('payment', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='refunds', to='pretixbase.OrderPayment')),
|
||||
],
|
||||
options={
|
||||
'ordering': ('local_id',),
|
||||
},
|
||||
),
|
||||
migrations.AlterModelOptions(
|
||||
name='quota',
|
||||
options={'ordering': ('name',), 'verbose_name': 'Quota', 'verbose_name_plural': 'Quotas'},
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='orderfee',
|
||||
name='fee_type',
|
||||
field=models.CharField(choices=[('payment', 'Payment fee'), ('shipping', 'Shipping fee'), ('service', 'Service fee'), ('other', 'Other fees'), ('giftcard', 'Gift card')], max_length=100),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='team',
|
||||
name='can_change_organizer_settings',
|
||||
field=models.BooleanField(default=False, help_text='Someone with this setting can get access to most data of all of your events, i.e. via privacy reports, so be careful who you add to this team!', verbose_name='Can change organizer settings'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='user',
|
||||
name='require_2fa',
|
||||
field=models.BooleanField(default=False, verbose_name='Two-factor authentication is required to log in'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='orderpayment',
|
||||
name='fee',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='payments', to='pretixbase.OrderFee'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='orderpayment',
|
||||
name='order',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='payments', to='pretixbase.Order', verbose_name='Order'),
|
||||
),
|
||||
]
|
||||
118
src/pretix/base/migrations/0097_auto_20180722_0804.py
Normal file
118
src/pretix/base/migrations/0097_auto_20180722_0804.py
Normal file
@@ -0,0 +1,118 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.13 on 2018-07-22 08:04
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def create_payments(apps, schema_editor):
|
||||
Order = apps.get_model('pretixbase', 'Order') # noqa
|
||||
OrderPayment = apps.get_model('pretixbase', 'OrderPayment') # noqa
|
||||
OrderRefund = apps.get_model('pretixbase', 'OrderRefund') # noqa
|
||||
payments = []
|
||||
refunds = []
|
||||
for o in Order.objects.filter(payments__isnull=True).iterator():
|
||||
if o.status == 'n' or o.status == 'e':
|
||||
payments.append(OrderPayment(
|
||||
local_id=1,
|
||||
state='created',
|
||||
amount=o.total,
|
||||
order=o,
|
||||
provider=o.payment_provider,
|
||||
info=o.payment_info,
|
||||
migrated=True,
|
||||
fee=o.fees.filter(fee_type="payment", internal_type=o.payment_provider).first(),
|
||||
))
|
||||
pass
|
||||
elif o.status == 'p':
|
||||
payments.append(OrderPayment(
|
||||
local_id=1,
|
||||
state='confirmed',
|
||||
amount=o.total,
|
||||
order=o,
|
||||
provider=o.payment_provider,
|
||||
payment_date=o.payment_date,
|
||||
info=o.payment_info,
|
||||
migrated=True,
|
||||
fee=o.fees.filter(fee_type="payment", internal_type=o.payment_provider).first(),
|
||||
))
|
||||
elif o.status == 'r':
|
||||
p = OrderPayment.objects.create(
|
||||
local_id=1,
|
||||
state='refunded',
|
||||
amount=o.total,
|
||||
order=o,
|
||||
provider=o.payment_provider,
|
||||
payment_date=o.payment_date,
|
||||
info=o.payment_info,
|
||||
migrated=True,
|
||||
fee=o.fees.filter(fee_type="payment", internal_type=o.payment_provider).first(),
|
||||
)
|
||||
refunds.append(OrderRefund(
|
||||
local_id=1,
|
||||
state='done',
|
||||
amount=o.total,
|
||||
order=o,
|
||||
provider=o.payment_provider,
|
||||
info=o.payment_info,
|
||||
source='admin',
|
||||
payment=p
|
||||
))
|
||||
elif o.status == 'c':
|
||||
payments.append(OrderPayment(
|
||||
local_id=1,
|
||||
state='canceled',
|
||||
amount=o.total,
|
||||
order=o,
|
||||
provider=o.payment_provider,
|
||||
payment_date=o.payment_date,
|
||||
info=o.payment_info,
|
||||
migrated=True,
|
||||
fee=o.fees.filter(fee_type="payment", internal_type=o.payment_provider).first(),
|
||||
))
|
||||
|
||||
if len(payments) > 500:
|
||||
OrderPayment.objects.bulk_create(payments)
|
||||
payments.clear()
|
||||
if len(refunds) > 500:
|
||||
OrderRefund.objects.bulk_create(refunds)
|
||||
refunds.clear()
|
||||
if len(payments) > 0:
|
||||
OrderPayment.objects.bulk_create(payments)
|
||||
if len(refunds) > 0:
|
||||
OrderRefund.objects.bulk_create(refunds)
|
||||
|
||||
|
||||
def notifications(apps, schema_editor):
|
||||
NotificationSetting = apps.get_model('pretixbase', 'NotificationSetting')
|
||||
for n in NotificationSetting.objects.filter(action_type='pretix.event.action_required'):
|
||||
n.pk = None
|
||||
n.action_type = 'pretix.event.order.refund.created.externally'
|
||||
n.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('pretixbase', '0096_auto_20180722_0801'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(create_payments, migrations.RunPython.noop),
|
||||
migrations.RunPython(notifications, migrations.RunPython.noop),
|
||||
migrations.RemoveField(
|
||||
model_name='order',
|
||||
name='payment_date',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='order',
|
||||
name='payment_info',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='order',
|
||||
name='payment_manual',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='order',
|
||||
name='payment_provider',
|
||||
),
|
||||
]
|
||||
Reference in New Issue
Block a user