various updates
This commit is contained in:
parent
0cd8a3a787
commit
8959bc6ad5
7 changed files with 103 additions and 10 deletions
21
uncloud/migrations/0005_uncloudprovider_coupon_network.py
Normal file
21
uncloud/migrations/0005_uncloudprovider_coupon_network.py
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
# Generated by Django 3.1 on 2020-10-12 17:32
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('uncloud_net', '0010_auto_20201011_2009'),
|
||||||
|
('uncloud', '0004_auto_20201011_2031'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='uncloudprovider',
|
||||||
|
name='coupon_network',
|
||||||
|
field=models.ForeignKey(default=0, on_delete=django.db.models.deletion.CASCADE, related_name='uncloudprovidercoupon', to='uncloud_net.uncloudnetwork'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
]
|
|
@ -87,6 +87,7 @@ class UncloudProvider(UncloudAddress):
|
||||||
|
|
||||||
billing_network = models.ForeignKey(UncloudNetwork, related_name="uncloudproviderbill", on_delete=models.CASCADE)
|
billing_network = models.ForeignKey(UncloudNetwork, related_name="uncloudproviderbill", on_delete=models.CASCADE)
|
||||||
referral_network = models.ForeignKey(UncloudNetwork, related_name="uncloudproviderreferral", on_delete=models.CASCADE)
|
referral_network = models.ForeignKey(UncloudNetwork, related_name="uncloudproviderreferral", on_delete=models.CASCADE)
|
||||||
|
coupon_network = models.ForeignKey(UncloudNetwork, related_name="uncloudprovidercoupon", on_delete=models.CASCADE)
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -112,7 +113,8 @@ class UncloudProvider(UncloudAddress):
|
||||||
country="CH",
|
country="CH",
|
||||||
starting_date=timezone.now(),
|
starting_date=timezone.now(),
|
||||||
billing_network=UncloudNetwork.objects.get(description="uncloud Billing"),
|
billing_network=UncloudNetwork.objects.get(description="uncloud Billing"),
|
||||||
referral_network=UncloudNetwork.objects.get(description="uncloud Referral")
|
referral_network=UncloudNetwork.objects.get(description="uncloud Referral"),
|
||||||
|
coupon_network=UncloudNetwork.objects.get(description="uncloud Coupon")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,8 @@ class UncloudNetwork(models.Model):
|
||||||
def populate_db_defaults(cls):
|
def populate_db_defaults(cls):
|
||||||
for net, desc in [
|
for net, desc in [
|
||||||
( "2a0a:e5c0:11::", "uncloud Billing" ),
|
( "2a0a:e5c0:11::", "uncloud Billing" ),
|
||||||
( "2a0a:e5c0:11:1::", "uncloud Referral" )
|
( "2a0a:e5c0:11:1::", "uncloud Referral" ),
|
||||||
|
( "2a0a:e5c0:11:2::", "uncloud Coupon" )
|
||||||
]:
|
]:
|
||||||
obj, created = cls.objects.get_or_create(network_address=net,
|
obj, created = cls.objects.get_or_create(network_address=net,
|
||||||
defaults= {
|
defaults= {
|
||||||
|
|
48
uncloud_pay/migrations/0035_auto_20201012_1728.py
Normal file
48
uncloud_pay/migrations/0035_auto_20201012_1728.py
Normal file
File diff suppressed because one or more lines are too long
|
@ -263,7 +263,7 @@ class RecurringPeriod(models.Model):
|
||||||
###
|
###
|
||||||
# Bills.
|
# Bills.
|
||||||
|
|
||||||
class BillingAddress(models.Model):
|
class BillingAddress(UncloudAddress):
|
||||||
owner = models.ForeignKey(get_user_model(), on_delete=models.CASCADE)
|
owner = models.ForeignKey(get_user_model(), on_delete=models.CASCADE)
|
||||||
vat_number = models.CharField(max_length=100, default="", blank=True)
|
vat_number = models.CharField(max_length=100, default="", blank=True)
|
||||||
active = models.BooleanField(default=False)
|
active = models.BooleanField(default=False)
|
||||||
|
@ -300,7 +300,6 @@ class BillingAddress(models.Model):
|
||||||
active=True)
|
active=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_address_for(user):
|
def get_address_for(user):
|
||||||
return BillingAddress.objects.get(owner=user, active=True)
|
return BillingAddress.objects.get(owner=user, active=True)
|
||||||
|
@ -308,7 +307,7 @@ class BillingAddress(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "{} - {}, {}, {} {}, {}".format(
|
return "{} - {}, {}, {} {}, {}".format(
|
||||||
self.owner,
|
self.owner,
|
||||||
self.name, self.street, self.postal_code, self.city,
|
self.full_name, self.street, self.postal_code, self.city,
|
||||||
self.country)
|
self.country)
|
||||||
|
|
||||||
###
|
###
|
||||||
|
@ -1059,7 +1058,21 @@ class Bill(models.Model):
|
||||||
- If the customer is outside EU and outside CH -> do not apply VAT
|
- If the customer is outside EU and outside CH -> do not apply VAT
|
||||||
"""
|
"""
|
||||||
|
|
||||||
provider_country = UncloudProvider.objects.get()
|
provider = UncloudProvider.objects.get()
|
||||||
|
|
||||||
|
# Assume always VAT inside the country
|
||||||
|
if provider.country = self.billing_address.country:
|
||||||
|
vat_rate = VATRate.objects.get(country=provider.country,
|
||||||
|
when=self.ending_date)
|
||||||
|
elif self.billing_address.country in EU:
|
||||||
|
# FIXME: need to check for validated vat number
|
||||||
|
if self.billing_address.vat_number:
|
||||||
|
return 0
|
||||||
|
else:
|
||||||
|
return VATRate.objects.get(country=self.biling_address.country,
|
||||||
|
when=self.ending_date)
|
||||||
|
else: # non-EU, non-national
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -1182,6 +1195,13 @@ class BillRecord(models.Model):
|
||||||
else:
|
else:
|
||||||
return self.order.one_time_price
|
return self.order.one_time_price
|
||||||
|
|
||||||
|
@property
|
||||||
|
def price(self):
|
||||||
|
if self.is_recurring_record:
|
||||||
|
return self.order.recurring_price
|
||||||
|
else:
|
||||||
|
return self.order.one_time_price
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
if self.is_recurring_record:
|
if self.is_recurring_record:
|
||||||
bill_line = f"{self.starting_date} - {self.ending_date}: {self.quantity} x {self.order}"
|
bill_line = f"{self.starting_date} - {self.ending_date}: {self.quantity} x {self.order}"
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
Icons, fonts, etc. are INLINED. This is rather ugly, but as the PDF
|
Icons, fonts, etc. are INLINED. This is rather ugly, but as the PDF
|
||||||
generation is based on a local snapshot of the HTML file, URLs are
|
generation is based on a local snapshot of the HTML file, URLs are
|
||||||
screwed if they are not absolute.
|
screwed if they are not absolute to the *local* filesystem.
|
||||||
|
|
||||||
As this document is used ONLY for bills and ONLY for downloading, I
|
As this document is used ONLY for bills and ONLY for downloading, I
|
||||||
decided that this is an acceptable uglyness.
|
decided that this is an acceptable uglyness.
|
||||||
|
@ -695,9 +695,9 @@ oAsAAAAAAACGQNAFAAAAAAAAQyDoAgAAAAAAgCEQdAEAAAAAAMAQCLoAAAAAAABgCP83AL6WQ1Y7
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Detail</th>
|
<th>Detail</th>
|
||||||
<th>Units</th>
|
|
||||||
<th>Price/Unit</th>
|
<th>Price/Unit</th>
|
||||||
<th class="tr">Total price</tH>
|
<th>Units</th>
|
||||||
|
<th>Total price</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
@ -707,8 +707,8 @@ oAsAAAAAAACGQNAFAAAAAAAAQyDoAgAAAAAAgCEQdAEAAAAAAMAQCLoAAAAAAABgCP83AL6WQ1Y7
|
||||||
- {{ record.ending_date|date:"c" }}
|
- {{ record.ending_date|date:"c" }}
|
||||||
{{ record.order }}
|
{{ record.order }}
|
||||||
</td>
|
</td>
|
||||||
|
<td>{{ record.price|floatformat:2 }}</td>
|
||||||
<td>{{ record.quantity|floatformat:2 }}</td>
|
<td>{{ record.quantity|floatformat:2 }}</td>
|
||||||
<td>{{ record.order.price|floatformat:2 }}</td>
|
|
||||||
<td>{{ record.sum|floatformat:2 }}</td>
|
<td>{{ record.sum|floatformat:2 }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
@ -201,6 +201,7 @@ class BillViewSet(viewsets.ReadOnlyModelViewSet):
|
||||||
Allow to download
|
Allow to download
|
||||||
"""
|
"""
|
||||||
bill = self.get_object()
|
bill = self.get_object()
|
||||||
|
provider = UncloudProvider.get_provider()
|
||||||
output_file = NamedTemporaryFile()
|
output_file = NamedTemporaryFile()
|
||||||
bill_html = render_to_string("bill.html.j2", {'bill': bill})
|
bill_html = render_to_string("bill.html.j2", {'bill': bill})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue