diff --git a/uncloud/templates/uncloud/base.html b/uncloud/templates/uncloud/base.html index d0295ca..3f1632d 100644 --- a/uncloud/templates/uncloud/base.html +++ b/uncloud/templates/uncloud/base.html @@ -19,6 +19,7 @@ {% block css_extra %} {% endblock css_extra %} + {% block head_extra %} {% endblock head_extra %} {# Load CSS and JavaScript #} {% bootstrap_css %} diff --git a/uncloud_pay/models.py b/uncloud_pay/models.py index 0b755d4..51de3ad 100644 --- a/uncloud_pay/models.py +++ b/uncloud_pay/models.py @@ -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 diff --git a/uncloud_pay/templates/uncloud_pay/register_stripe.html b/uncloud_pay/templates/uncloud_pay/register_stripe.html index d8d8ab7..6d192a4 100644 --- a/uncloud_pay/templates/uncloud_pay/register_stripe.html +++ b/uncloud_pay/templates/uncloud_pay/register_stripe.html @@ -1,7 +1,11 @@ {% extends 'uncloud/base.html' %} + +{% block head_extra %} {% endblock %} + +{% block content %}