Make recurring_period an Enum, VMProduct a Product, initial wire for

order
This commit is contained in:
fnux 2020-02-27 17:13:56 +01:00
commit b2fe5014d8
6 changed files with 113 additions and 24 deletions

View file

@ -1,12 +1,23 @@
from django.db import models
from django.contrib.auth import get_user_model
from django.core.validators import MinValueValidator
from django.utils.translation import gettext_lazy as _
import uuid
AMOUNT_MAX_DIGITS=10
AMOUNT_DECIMALS=2
# See https://docs.djangoproject.com/en/dev/ref/models/fields/#field-choices-enum-types
class RecurringPeriod(models.TextChoices):
ONE_TIME = 'ONCE', _('Onetime')
PER_YEAR = 'YEAR', _('Per Year')
PER_MONTH = 'MONTH', _('Per Month')
PER_MINUTE = 'MINUTE', _('Per Minute')
PER_DAY = 'DAY', _('Per Day')
PER_HOUR = 'HOUR', _('Per Hour')
PER_SECOND = 'SECOND', _('Per Second')
class Bill(models.Model):
owner = models.ForeignKey(get_user_model(),
on_delete=models.CASCADE)
@ -31,7 +42,7 @@ class Order(models.Model):
on_delete=models.CASCADE,
editable=False)
creation_date = models.DateTimeField()
creation_date = models.DateTimeField(auto_now_add=True)
starting_date = models.DateTimeField()
ending_date = models.DateTimeField(blank=True,
null=True)
@ -46,19 +57,8 @@ class Order(models.Model):
one_time_price = models.FloatField(editable=False)
recurring_period = models.CharField(max_length=32,
choices = (
('onetime', 'Onetime'),
('per_year', 'Per Year'),
('per_month', 'Per Month'),
('per_week', 'Per Week'),
('per_day', 'Per Day'),
('per_hour', 'Per Hour'),
('per_minute', 'Per Minute'),
('per_second', 'Per Second'),
),
default='onetime'
)
choices = RecurringPeriod.choices,
default = RecurringPeriod.PER_MONTH)
# def amount(self):
# amount = recurring_price
@ -133,7 +133,12 @@ class Product(models.Model):
order = models.ForeignKey(Order,
on_delete=models.CASCADE,
editable=False)
editable=False,
null=True)
@property
def recurring_price(self, recurring_period=RecurringPeriod.PER_MONTH):
pass # To be implemented in child.
class Meta:
abstract = True