forked from uncloud/uncloud
++ stuff
This commit is contained in:
parent
5b170ed521
commit
e726795495
3 changed files with 24 additions and 17 deletions
|
@ -19,6 +19,7 @@
|
|||
</title>
|
||||
|
||||
{% block css_extra %} {% endblock css_extra %}
|
||||
{% block head_extra %} {% endblock head_extra %}
|
||||
|
||||
{# Load CSS and JavaScript #}
|
||||
{% bootstrap_css %}
|
||||
|
|
|
@ -136,11 +136,11 @@ class Payment(models.Model):
|
|||
|
||||
@classmethod
|
||||
def withdraw(cls, owner, amount, currency='CHF', notes=''):
|
||||
return cls.objects.create(owner=owner, type="withdraw", amount=amount,
|
||||
return cls.objects.create(owner=owner, type="withdraw", amount=amount,
|
||||
currency=currency, notes=notes)
|
||||
|
||||
|
||||
|
||||
|
||||
# See https://docs.djangoproject.com/en/dev/ref/models/fields/#field-choices-enum-types
|
||||
class RecurringPeriodDefaultChoices(models.IntegerChoices):
|
||||
"""
|
||||
|
@ -240,7 +240,7 @@ class BillingAddress(UncloudAddress):
|
|||
self.owner,
|
||||
self.full_name, self.street, self.postal_code, self.city,
|
||||
self.country)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def get_address_for(user):
|
||||
return BillingAddress.objects.get(owner=user)
|
||||
|
@ -654,6 +654,7 @@ class Order(models.Model):
|
|||
billing_address = models.ForeignKey(BillingAddress,
|
||||
on_delete=models.CASCADE)
|
||||
|
||||
# Let's forget about this one
|
||||
customer = models.ForeignKey(StripeCustomer, on_delete=models.CASCADE, null=True)
|
||||
|
||||
product = models.ForeignKey(Product, blank=False, null=False, on_delete=models.CASCADE)
|
||||
|
@ -720,7 +721,7 @@ class Order(models.Model):
|
|||
|
||||
if self.recurring_period.duration_seconds > 0:
|
||||
delta = until_when - self.starting_date
|
||||
|
||||
|
||||
num_times = ceil(delta.total_seconds() / self.recurring_period.duration_seconds)
|
||||
|
||||
next_date = self.starting_date + datetime.timedelta(seconds=num_times * self.recurring_period.duration_seconds)
|
||||
|
@ -755,7 +756,7 @@ class Order(models.Model):
|
|||
"""
|
||||
|
||||
return sum([ br.quantity for br in self.bill_records.all() ])
|
||||
|
||||
|
||||
def cancel(self):
|
||||
self.ending_date = timezone.now()
|
||||
self.should_be_billed = False
|
||||
|
@ -798,7 +799,7 @@ class Order(models.Model):
|
|||
@property
|
||||
def is_one_time(self):
|
||||
return not self.is_recurring
|
||||
|
||||
|
||||
@property
|
||||
def description(self):
|
||||
desc = self.product.description + "( "
|
||||
|
@ -843,7 +844,7 @@ class Order(models.Model):
|
|||
|
||||
return new_order
|
||||
|
||||
|
||||
|
||||
def create_bill_record(self, bill):
|
||||
br = None
|
||||
if self.recurring_price != 0:
|
||||
|
@ -922,7 +923,7 @@ class Order(models.Model):
|
|||
if 'memory' in config:
|
||||
recurring_price += self.pricing_plan.ram_unit_price * int(config['memory'])
|
||||
if 'storage' in config:
|
||||
#TODO Fix the ssd static value
|
||||
#TODO Fix the ssd static value
|
||||
recurring_price += (10 * self.pricing_plan.storage_ssd_unit_price) + (self.pricing_plan.storage_hd_unit_price * int(config['storage']))
|
||||
|
||||
vat_rate = VATRate.get_vat_rate(self.billing_address)
|
||||
|
@ -933,7 +934,7 @@ class Order(models.Model):
|
|||
)
|
||||
return price_after_discount_with_vat
|
||||
except Exception as e:
|
||||
logger.error("An error occurred while parsing the config obj", e)
|
||||
logger.error("An error occurred while parsing the config obj", e)
|
||||
return 0
|
||||
|
||||
def check_parameters(self):
|
||||
|
@ -987,7 +988,7 @@ class Bill(models.Model):
|
|||
on_delete=models.CASCADE,
|
||||
editable=True,
|
||||
null=False)
|
||||
|
||||
|
||||
currency = models.CharField(max_length=32, choices=Currency.choices, default=Currency.CHF)
|
||||
|
||||
# FIXME: editable=True -> is in the admin, but also editable in DRF
|
||||
|
@ -1067,10 +1068,10 @@ class Bill(models.Model):
|
|||
|
||||
owner = billing_address.owner
|
||||
|
||||
all_orders = Order.objects.filter(Q(owner__id=owner.id), Q(should_be_billed=True),
|
||||
all_orders = Order.objects.filter(Q(owner__id=owner.id), Q(should_be_billed=True),
|
||||
Q(billing_address__id=billing_address.id)
|
||||
).order_by('id')
|
||||
|
||||
|
||||
if len(all_orders) > 0:
|
||||
bill = cls.get_or_create_bill(billing_address, ending_date=ending_date)
|
||||
for order in all_orders:
|
||||
|
@ -1084,7 +1085,7 @@ class Bill(models.Model):
|
|||
def create_next_bill_for_order(cls, order, ending_date=None):
|
||||
"""
|
||||
Create the next bill for a specific order of a user
|
||||
"""
|
||||
"""
|
||||
bill = cls.get_or_create_bill(order.billing_address, ending_date=ending_date)
|
||||
order.create_bill_record(bill)
|
||||
return bill
|
||||
|
@ -1122,7 +1123,7 @@ class Bill(models.Model):
|
|||
|
||||
if not ending_date:
|
||||
ending_date = end_of_month(starting_date)
|
||||
|
||||
|
||||
if not bill:
|
||||
bill = cls.objects.create(
|
||||
owner=billing_address.owner,
|
||||
|
@ -1132,7 +1133,7 @@ class Bill(models.Model):
|
|||
|
||||
|
||||
return bill
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.owner}-{self.id}"
|
||||
|
||||
|
@ -1182,7 +1183,7 @@ class BillRecord(models.Model):
|
|||
return self.order.recurring_price
|
||||
else:
|
||||
return self.order.one_time_price
|
||||
|
||||
|
||||
@property
|
||||
def subtotal(self):
|
||||
billing_address_ins = self.order.billing_address
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
{% extends 'uncloud/base.html' %}
|
||||
|
||||
{% block head_extra %}
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
|
||||
<script src="https://js.stripe.com/v3/"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
{% csrf_token %}
|
||||
<div id="content">
|
||||
|
@ -38,7 +42,7 @@
|
|||
var setupForm = document.getElementById('setup-form');
|
||||
var clientSecret = setupForm.dataset.secret;
|
||||
var stripe = Stripe('{{ stripe_pk }}');
|
||||
|
||||
|
||||
var cardButton = document.getElementById('card-button');
|
||||
var messageContainer = document.getElementById('message');
|
||||
var backmessage = document.getElementById('goback');
|
||||
|
@ -73,3 +77,4 @@
|
|||
});
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in a new issue