orders only have 1 price
Signed-off-by: Nico Schottelius <nico@nico-notebook.schottelius.org>
This commit is contained in:
parent
8da6a1e19c
commit
c9be8cc50b
2 changed files with 51 additions and 9 deletions
18
uncloud_pay/migrations/0005_auto_20200808_1954.py
Normal file
18
uncloud_pay/migrations/0005_auto_20200808_1954.py
Normal 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',
|
||||||
|
),
|
||||||
|
]
|
|
@ -301,15 +301,10 @@ class Order(models.Model):
|
||||||
recurring_period = models.IntegerField(choices = RecurringPeriod.choices,
|
recurring_period = models.IntegerField(choices = RecurringPeriod.choices,
|
||||||
default = RecurringPeriod.PER_30D)
|
default = RecurringPeriod.PER_30D)
|
||||||
|
|
||||||
one_time_price = models.DecimalField(default=0.0,
|
price = models.DecimalField(default=0.0,
|
||||||
max_digits=AMOUNT_MAX_DIGITS,
|
max_digits=AMOUNT_MAX_DIGITS,
|
||||||
decimal_places=AMOUNT_DECIMALS,
|
decimal_places=AMOUNT_DECIMALS,
|
||||||
validators=[MinValueValidator(0)])
|
validators=[MinValueValidator(0)])
|
||||||
|
|
||||||
recurring_price = models.DecimalField(default=0.0,
|
|
||||||
max_digits=AMOUNT_MAX_DIGITS,
|
|
||||||
decimal_places=AMOUNT_DECIMALS,
|
|
||||||
validators=[MinValueValidator(0)])
|
|
||||||
|
|
||||||
replaces = models.ForeignKey('self',
|
replaces = models.ForeignKey('self',
|
||||||
related_name='replaced_by',
|
related_name='replaced_by',
|
||||||
|
@ -402,6 +397,10 @@ class Bill(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"Bill {self.owner}-{self.id}"
|
return f"Bill {self.owner}-{self.id}"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def sum(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_next_bill_for_user(cls, user):
|
def create_next_bill_for_user(cls, user):
|
||||||
|
@ -421,12 +420,20 @@ class Bill(models.Model):
|
||||||
|
|
||||||
ending_date = end_of_month(starting_date)
|
ending_date = end_of_month(starting_date)
|
||||||
|
|
||||||
|
bill = cls()
|
||||||
|
|
||||||
for order in all_orders:
|
for order in all_orders:
|
||||||
# check if order needs to be billed
|
# check if order needs to be billed
|
||||||
# check if order has previous billing record
|
# check if order has previous billing record
|
||||||
|
|
||||||
|
# one time orders
|
||||||
|
if not order.is_recurring:
|
||||||
|
pass
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
return bill
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_all_bills(cls):
|
def create_all_bills(cls):
|
||||||
for owner in get_user_model().objects.all():
|
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
|
# How many times the order has been used in this record
|
||||||
quantity = models.DecimalField(max_digits=19, decimal_places=10)
|
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
|
# The timeframe the bill record is for can (and probably often will) differ
|
||||||
# from the bill time
|
# from the bill time
|
||||||
|
|
||||||
|
@ -518,6 +527,21 @@ class BillRecord(models.Model):
|
||||||
starting_date = models.DateTimeField()
|
starting_date = models.DateTimeField()
|
||||||
ending_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):
|
def __str__(self):
|
||||||
return f"{self.bill}: {self.quantity} x {self.order}"
|
return f"{self.bill}: {self.quantity} x {self.order}"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue