Commit 65440ab2 authored by fnux's avatar fnux

Add depends_on relation on orders

parent d794b24c
Pipeline #1414 passed with stage
in 1 minute and 3 seconds
# Generated by Django 3.0.6 on 2020-05-08 14:46
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('uncloud_pay', '0012_billnico'),
]
operations = [
migrations.AddField(
model_name='order',
name='depends_on',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='parent_of', to='uncloud_pay.Order'),
),
migrations.AlterField(
model_name='order',
name='replaced_by',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='supersede', to='uncloud_pay.Order'),
),
]
......@@ -609,9 +609,17 @@ class Order(models.Model):
validators=[MinValueValidator(0)])
replaced_by = models.ForeignKey('self',
related_name='supersede',
on_delete=models.PROTECT,
blank=True,
null=True)
depends_on = models.ForeignKey('self',
related_name='parent_of',
on_delete=models.PROTECT,
blank=True,
null=True)
@property
def is_terminated(self):
return self.ending_date != None and self.ending_date < timezone.now()
......
......@@ -70,9 +70,9 @@ class OrderSerializer(serializers.ModelSerializer):
class Meta:
model = Order
read_only_fields = ['replaced_by', 'depends_on']
fields = ['uuid', 'owner', 'description', 'creation_date', 'starting_date', 'ending_date',
'bill', 'recurring_period', 'recurring_price', 'one_time_price', 'replaced_by']
read_only_fields = ['replaced_by']
'bill', 'recurring_period', 'recurring_price', 'one_time_price'] + read_only_fields
###
......
......@@ -174,7 +174,8 @@ class VMProductViewSet(ProductViewSet):
disk_order = Order.from_product(
disk,
recurring_period=order_recurring_period,
starting_date=timezone.now()
starting_date=timezone.now(),
depends_on=vm_order
)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment