orders only have 1 price

Signed-off-by: Nico Schottelius <nico@nico-notebook.schottelius.org>
This commit is contained in:
Nico Schottelius 2020-08-08 21:54:44 +02:00
parent 8da6a1e19c
commit c9be8cc50b
2 changed files with 51 additions and 9 deletions

View file

@ -0,0 +1,18 @@
# Generated by Django 3.1 on 2020-08-08 19:54
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('uncloud_pay', '0004_remove_order_one_time_price'),
]
operations = [
migrations.RenameField(
model_name='order',
old_name='recurring_price',
new_name='price',
),
]

View file

@ -301,12 +301,7 @@ class Order(models.Model):
recurring_period = models.IntegerField(choices = RecurringPeriod.choices,
default = RecurringPeriod.PER_30D)
one_time_price = models.DecimalField(default=0.0,
max_digits=AMOUNT_MAX_DIGITS,
decimal_places=AMOUNT_DECIMALS,
validators=[MinValueValidator(0)])
recurring_price = models.DecimalField(default=0.0,
price = models.DecimalField(default=0.0,
max_digits=AMOUNT_MAX_DIGITS,
decimal_places=AMOUNT_DECIMALS,
validators=[MinValueValidator(0)])
@ -402,6 +397,10 @@ class Bill(models.Model):
def __str__(self):
return f"Bill {self.owner}-{self.id}"
@property
def sum(self):
pass
@classmethod
def create_next_bill_for_user(cls, user):
@ -421,12 +420,20 @@ class Bill(models.Model):
ending_date = end_of_month(starting_date)
bill = cls()
for order in all_orders:
# check if order needs to be billed
# check if order has previous billing record
# one time orders
if not order.is_recurring:
pass
pass
return bill
@classmethod
def create_all_bills(cls):
for owner in get_user_model().objects.all():
@ -511,6 +518,8 @@ class BillRecord(models.Model):
# How many times the order has been used in this record
quantity = models.DecimalField(max_digits=19, decimal_places=10)
# quantity can actually be derived from starting/ending date
# The timeframe the bill record is for can (and probably often will) differ
# from the bill time
@ -518,6 +527,21 @@ class BillRecord(models.Model):
starting_date = models.DateTimeField()
ending_date = models.DateTimeField()
def quantity2(self):
if self.order.recurring_period == RecurringPeriod.ONE_TIME:
return 1
record_delta = self.ending_date - self.starting_date
return record_delta.total_seconds()/self.order.recurring_period
def sum(self):
if self.order.recurring_period == RecurringPeriod.ONE_TIME:
return 1
return self.quantity * 1
def __str__(self):
return f"{self.bill}: {self.quantity} x {self.order}"