forked from uncloud/uncloud
make price a real property of order
Signed-off-by: Nico Schottelius <nico@nico-notebook.schottelius.org>
This commit is contained in:
parent
64780bfc6c
commit
cbd5a08ae7
3 changed files with 68 additions and 17 deletions
23
uncloud_pay/migrations/0004_auto_20200801_1604.py
Normal file
23
uncloud_pay/migrations/0004_auto_20200801_1604.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
# Generated by Django 3.0.6 on 2020-08-01 16:04
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('uncloud_pay', '0003_auto_20200621_1442'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='order',
|
||||
name='replaced_by',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='order',
|
||||
name='replaces',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='replaced_by', to='uncloud_pay.Order'),
|
||||
),
|
||||
]
|
24
uncloud_pay/migrations/0005_auto_20200801_1626.py
Normal file
24
uncloud_pay/migrations/0005_auto_20200801_1626.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
# Generated by Django 3.0.6 on 2020-08-01 16:26
|
||||
|
||||
import django.core.validators
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('uncloud_pay', '0004_auto_20200801_1604'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='order',
|
||||
name='one_time_price',
|
||||
field=models.DecimalField(decimal_places=2, default=0.0, max_digits=10, validators=[django.core.validators.MinValueValidator(0)]),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='order',
|
||||
name='recurring_price',
|
||||
field=models.DecimalField(decimal_places=2, default=0.0, max_digits=10, validators=[django.core.validators.MinValueValidator(0)]),
|
||||
),
|
||||
]
|
|
@ -6,6 +6,9 @@ from django.core.validators import MinValueValidator
|
|||
from django.utils import timezone
|
||||
from django.core.exceptions import ObjectDoesNotExist, ValidationError
|
||||
|
||||
from django.contrib.contenttypes.fields import GenericForeignKey
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
|
||||
import logging
|
||||
from functools import reduce
|
||||
import itertools
|
||||
|
@ -296,13 +299,13 @@ class Order(models.Model):
|
|||
|
||||
billing_address = models.ForeignKey(BillingAddress,
|
||||
on_delete=models.CASCADE)
|
||||
|
||||
description = models.TextField()
|
||||
|
||||
# TODO: enforce ending_date - starting_date to be larger than recurring_period.
|
||||
creation_date = models.DateTimeField(auto_now_add=True)
|
||||
starting_date = models.DateTimeField(default=timezone.now)
|
||||
ending_date = models.DateTimeField(blank=True,
|
||||
null=True)
|
||||
ending_date = models.DateTimeField(blank=True, null=True)
|
||||
|
||||
recurring_period = models.IntegerField(choices = RecurringPeriod.choices,
|
||||
default = RecurringPeriod.PER_30D)
|
||||
|
@ -317,17 +320,17 @@ class Order(models.Model):
|
|||
decimal_places=AMOUNT_DECIMALS,
|
||||
validators=[MinValueValidator(0)])
|
||||
|
||||
replaced_by = models.ForeignKey('self',
|
||||
related_name='supersede',
|
||||
on_delete=models.PROTECT,
|
||||
blank=True,
|
||||
null=True)
|
||||
replaces = models.ForeignKey('self',
|
||||
related_name='replaced_by',
|
||||
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)
|
||||
related_name='parent_of',
|
||||
on_delete=models.PROTECT,
|
||||
blank=True,
|
||||
null=True)
|
||||
|
||||
@property
|
||||
def count_billed(self):
|
||||
|
@ -395,13 +398,14 @@ class Order(models.Model):
|
|||
def records(self):
|
||||
return OrderRecord.objects.filter(order=self)
|
||||
|
||||
@property
|
||||
def one_time_price(self):
|
||||
return reduce(lambda acc, record: acc + record.one_time_price, self.records, 0)
|
||||
# these are reald fields!!!
|
||||
# @property
|
||||
# def one_time_price(self):
|
||||
# return reduce(lambda acc, record: acc + record.one_time_price, self.records, 0)
|
||||
|
||||
@property
|
||||
def recurring_price(self):
|
||||
return reduce(lambda acc, record: acc + record.recurring_price, self.records, 0)
|
||||
# @property
|
||||
# def recurring_price(self):
|
||||
# return reduce(lambda acc, record: acc + record.recurring_price, self.records, 0)
|
||||
|
||||
# Used by uncloud_pay tests.
|
||||
@property
|
||||
|
|
Loading…
Reference in a new issue