forked from uncloud/uncloud
Remove orderrecord
Signed-off-by: Nico Schottelius <nico@nico-notebook.schottelius.org>
This commit is contained in:
parent
db1a69561b
commit
78d1de9031
4 changed files with 37 additions and 45 deletions
16
uncloud_pay/migrations/0008_delete_orderrecord.py
Normal file
16
uncloud_pay/migrations/0008_delete_orderrecord.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
# Generated by Django 3.1 on 2020-08-08 20:36
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('uncloud_pay', '0007_remove_bill_bill_records'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.DeleteModel(
|
||||
name='OrderRecord',
|
||||
),
|
||||
]
|
|
@ -412,6 +412,7 @@ class Bill(models.Model):
|
|||
|
||||
# Calculate the start date
|
||||
if last_bill:
|
||||
# TODO: check that last bill is finished/closed, if not continue using it
|
||||
starting_date = last_bill.end_date + datetime.timedelta(seconds=1)
|
||||
else:
|
||||
if first_order:
|
||||
|
@ -436,7 +437,9 @@ class Bill(models.Model):
|
|||
order=order,
|
||||
starting_date=starting_date,
|
||||
ending_date=ending_date)
|
||||
pass
|
||||
|
||||
# Bill all active, recurring orders
|
||||
#if order.
|
||||
|
||||
return bill
|
||||
|
||||
|
@ -544,42 +547,6 @@ class BillRecord(models.Model):
|
|||
return f"{self.bill}: {self.quantity} x {self.order}"
|
||||
|
||||
|
||||
class OrderRecord(models.Model):
|
||||
"""
|
||||
Order records store billing informations for products: the actual product
|
||||
might be mutated and/or moved to another order but we do not want to loose
|
||||
the details of old orders.
|
||||
|
||||
Used as source of trust to dynamically generate bill entries.
|
||||
"""
|
||||
|
||||
order = models.ForeignKey(Order, on_delete=models.CASCADE)
|
||||
|
||||
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,
|
||||
max_digits=AMOUNT_MAX_DIGITS,
|
||||
decimal_places=AMOUNT_DECIMALS,
|
||||
validators=[MinValueValidator(0)])
|
||||
|
||||
description = models.TextField()
|
||||
|
||||
|
||||
@property
|
||||
def recurring_period(self):
|
||||
return self.order.recurring_period
|
||||
|
||||
@property
|
||||
def starting_date(self):
|
||||
return self.order.starting_date
|
||||
|
||||
@property
|
||||
def ending_date(self):
|
||||
return self.order.ending_date
|
||||
|
||||
|
||||
###
|
||||
# Products
|
||||
|
||||
|
|
|
@ -37,12 +37,6 @@ class CreatePaymentMethodSerializer(serializers.ModelSerializer):
|
|||
###
|
||||
# Orders & Products.
|
||||
|
||||
class OrderRecordSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = OrderRecord
|
||||
fields = ['one_time_price', 'recurring_price', 'description']
|
||||
|
||||
|
||||
class OrderSerializer(serializers.ModelSerializer):
|
||||
owner = serializers.PrimaryKeyRelatedField(queryset=get_user_model().objects.all())
|
||||
|
||||
|
|
|
@ -12,6 +12,14 @@ class ProductActivationTestCase(TestCase):
|
|||
username='jdoe',
|
||||
email='john.doe@domain.tld')
|
||||
|
||||
self.recurring_user = get_user_model().objects.create(
|
||||
username='recurrent_product_user',
|
||||
email='jane.doe@domain.tld')
|
||||
|
||||
self.user_without_address = get_user_model().objects.create(
|
||||
username='no_home_person',
|
||||
email='far.away@domain.tld')
|
||||
|
||||
self.billing_address = BillingAddress.objects.create(
|
||||
owner=self.user,
|
||||
organization = 'Test org',
|
||||
|
@ -19,6 +27,13 @@ class ProductActivationTestCase(TestCase):
|
|||
city="unknown",
|
||||
postal_code="unknown")
|
||||
|
||||
self.billing_address = BillingAddress.objects.create(
|
||||
owner=self.recurring_user,
|
||||
organization = 'Test org',
|
||||
street="Somewhere",
|
||||
city="Else",
|
||||
postal_code="unknown")
|
||||
|
||||
self.order_meta = {}
|
||||
self.order_meta[1] = {
|
||||
'starting_date': timezone.make_aware(datetime.datetime(2020,3,3)),
|
||||
|
@ -46,9 +61,9 @@ class ProductActivationTestCase(TestCase):
|
|||
|
||||
self.assertEqual(self.one_time_order.billrecord_set.count(), 1)
|
||||
|
||||
def test_bill_sum(self):
|
||||
def test_bill_sum_onetime(self):
|
||||
"""
|
||||
Ensure there is only 1 bill record per order
|
||||
Check the bill sum for a single one time order
|
||||
"""
|
||||
|
||||
bill = Bill.create_next_bill_for_user(self.user)
|
||||
|
|
Loading…
Reference in a new issue