Remove legacy ungleich_service migrations

This commit is contained in:
fnux 2020-04-18 10:39:57 +02:00
parent c0e12884e1
commit dd0c1cba94
5 changed files with 31 additions and 61 deletions

View file

@ -46,7 +46,8 @@ class GenericServiceProduct(Product):
decimal_places=AMOUNT_DECIMALS,
validators=[MinValueValidator(0)])
def recurring_price(self, recurring_period=RecurringPeriod.PER_MONTH):
@property
def recurring_price(self):
# FIXME: handle recurring_period somehow.
return self.custom_recurring_price

View file

@ -23,12 +23,26 @@ class MatrixServiceProductSerializer(serializers.ModelSerializer):
read_only_fields = ['uuid', 'order', 'owner', 'status']
class GenericServiceProductSerializer(serializers.ModelSerializer):
# Custom field used at creation (= ordering) only.
recurring_period = serializers.ChoiceField(
choices=GenericServiceProduct.allowed_recurring_periods())
class Meta:
model = GenericServiceProduct
fields = ['uuid', 'order', 'owner', 'status', 'custom_recurring_price',
'custom_description', 'custom_one_time_price', 'recurring_period']
'custom_description', 'custom_one_time_price']
read_only_fields = ['uuid', 'order', 'owner', 'status']
class OrderGenericServiceProductSerializer(GenericServiceProductSerializer):
recurring_period = serializers.ChoiceField(
choices=GenericServiceProduct.allowed_recurring_periods())
def __init__(self, *args, **kwargs):
super(OrderGenericServiceProductSerializer, self).__init__(*args, **kwargs)
self.fields['billing_address'] = serializers.ChoiceField(
choices=BillingAddress.get_addresses_for(
self.context['request'].user)
)
class Meta:
model = GenericServiceProductSerializer.Meta.model
fields = GenericServiceProductSerializer.Meta.fields + [
'recurring_period', 'billing_address'
]
read_only_fields = GenericServiceProductSerializer.Meta.read_only_fields

View file

@ -44,11 +44,13 @@ class MatrixServiceProductViewSet(ProductViewSet):
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
order_recurring_period = serializer.validated_data.pop("recurring_period")
order_billing_address = serializer.validated_data.pop("billing_address")
# Create base order.)
order = Order.objects.create(
recurring_period=order_recurring_period,
owner=request.user,
billing_address=order_billing_address,
starting_date=timezone.now()
)
order.save()
@ -72,22 +74,29 @@ class MatrixServiceProductViewSet(ProductViewSet):
class GenericServiceProductViewSet(ProductViewSet):
permission_classes = [permissions.IsAuthenticated]
serializer_class = GenericServiceProductSerializer
def get_queryset(self):
return GenericServiceProduct.objects.filter(owner=self.request.user)
def get_serializer_class(self):
if self.action == 'create':
return OrderGenericServiceProductSerializer
else:
return GenericServiceProductSerializer
@transaction.atomic
def create(self, request):
# Extract serializer data.
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
order_recurring_period = serializer.validated_data.pop("recurring_period")
order_billing_address = serializer.validated_data.pop("billing_address")
# Create base order.
order = Order.objects.create(
recurring_period=order_recurring_period,
owner=request.user,
billing_address=order_billing_address,
starting_date=timezone.now()
)
order.save()

View file

@ -1,18 +0,0 @@
# Generated by Django 3.0.5 on 2020-04-17 05:51
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('ungleich_service', '0004_auto_20200403_1727'),
]
operations = [
migrations.AlterField(
model_name='matrixserviceproduct',
name='status',
field=models.CharField(choices=[('PENDING', 'Pending'), ('AWAITING_PAYMENT', 'Awaiting payment'), ('BEING_CREATED', 'Being created'), ('SCHEDULED', 'Scheduled'), ('ACTIVE', 'Active'), ('MODIFYING', 'Modifying'), ('DELETED', 'Deleted'), ('DISABLED', 'Disabled'), ('UNUSABLE', 'Unusable')], default='AWAITING_PAYMENT', max_length=32),
),
]

View file

@ -1,36 +0,0 @@
# Generated by Django 3.0.5 on 2020-04-17 08:02
from django.conf import settings
import django.contrib.postgres.fields.jsonb
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
import uuid
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('uncloud_pay', '0005_auto_20200417_0551'),
('ungleich_service', '0005_auto_20200417_0551'),
]
operations = [
migrations.CreateModel(
name='GenericServiceProduct',
fields=[
('extra_data', django.contrib.postgres.fields.jsonb.JSONField(blank=True, editable=False, null=True)),
('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('status', models.CharField(choices=[('PENDING', 'Pending'), ('AWAITING_PAYMENT', 'Awaiting payment'), ('BEING_CREATED', 'Being created'), ('SCHEDULED', 'Scheduled'), ('ACTIVE', 'Active'), ('MODIFYING', 'Modifying'), ('DELETED', 'Deleted'), ('DISABLED', 'Disabled'), ('UNUSABLE', 'Unusable')], default='AWAITING_PAYMENT', max_length=32)),
('custom_description', models.TextField()),
('custom_recurring_price', models.DecimalField(decimal_places=2, default=0.0, max_digits=10, validators=[django.core.validators.MinValueValidator(0)])),
('custom_one_time_price', models.DecimalField(decimal_places=2, default=0.0, max_digits=10, validators=[django.core.validators.MinValueValidator(0)])),
('order', models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, to='uncloud_pay.Order')),
('owner', models.ForeignKey(editable=False, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
options={
'abstract': False,
},
),
]