forked from uncloud/uncloud
Add depends_on relation on orders
This commit is contained in:
parent
d794b24c86
commit
65440ab2ef
4 changed files with 36 additions and 3 deletions
24
uncloud_pay/migrations/0013_auto_20200508_1446.py
Normal file
24
uncloud_pay/migrations/0013_auto_20200508_1446.py
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
# 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)])
|
validators=[MinValueValidator(0)])
|
||||||
|
|
||||||
replaced_by = models.ForeignKey('self',
|
replaced_by = models.ForeignKey('self',
|
||||||
|
related_name='supersede',
|
||||||
on_delete=models.PROTECT,
|
on_delete=models.PROTECT,
|
||||||
blank=True,
|
blank=True,
|
||||||
null=True)
|
null=True)
|
||||||
|
|
||||||
|
depends_on = models.ForeignKey('self',
|
||||||
|
related_name='parent_of',
|
||||||
|
on_delete=models.PROTECT,
|
||||||
|
blank=True,
|
||||||
|
null=True)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_terminated(self):
|
def is_terminated(self):
|
||||||
return self.ending_date != None and self.ending_date < timezone.now()
|
return self.ending_date != None and self.ending_date < timezone.now()
|
||||||
|
|
|
@ -70,9 +70,9 @@ class OrderSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Order
|
model = Order
|
||||||
|
read_only_fields = ['replaced_by', 'depends_on']
|
||||||
fields = ['uuid', 'owner', 'description', 'creation_date', 'starting_date', 'ending_date',
|
fields = ['uuid', 'owner', 'description', 'creation_date', 'starting_date', 'ending_date',
|
||||||
'bill', 'recurring_period', 'recurring_price', 'one_time_price', 'replaced_by']
|
'bill', 'recurring_period', 'recurring_price', 'one_time_price'] + read_only_fields
|
||||||
read_only_fields = ['replaced_by']
|
|
||||||
|
|
||||||
|
|
||||||
###
|
###
|
||||||
|
|
|
@ -174,7 +174,8 @@ class VMProductViewSet(ProductViewSet):
|
||||||
disk_order = Order.from_product(
|
disk_order = Order.from_product(
|
||||||
disk,
|
disk,
|
||||||
recurring_period=order_recurring_period,
|
recurring_period=order_recurring_period,
|
||||||
starting_date=timezone.now()
|
starting_date=timezone.now(),
|
||||||
|
depends_on=vm_order
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue