various updates

This commit is contained in:
Nico Schottelius 2020-10-25 13:52:36 +01:00
parent 0cd8a3a787
commit 8959bc6ad5
7 changed files with 103 additions and 10 deletions

View 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,
),
]

View File

@ -87,6 +87,7 @@ class UncloudProvider(UncloudAddress):
billing_network = models.ForeignKey(UncloudNetwork, related_name="uncloudproviderbill", 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
@ -112,7 +113,8 @@ class UncloudProvider(UncloudAddress):
country="CH",
starting_date=timezone.now(),
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")
)

View File

@ -23,7 +23,8 @@ class UncloudNetwork(models.Model):
def populate_db_defaults(cls):
for net, desc in [
( "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,
defaults= {

File diff suppressed because one or more lines are too long

View File

@ -263,7 +263,7 @@ class RecurringPeriod(models.Model):
###
# Bills.
class BillingAddress(models.Model):
class BillingAddress(UncloudAddress):
owner = models.ForeignKey(get_user_model(), on_delete=models.CASCADE)
vat_number = models.CharField(max_length=100, default="", blank=True)
active = models.BooleanField(default=False)
@ -300,7 +300,6 @@ class BillingAddress(models.Model):
active=True)
@staticmethod
def get_address_for(user):
return BillingAddress.objects.get(owner=user, active=True)
@ -308,7 +307,7 @@ class BillingAddress(models.Model):
def __str__(self):
return "{} - {}, {}, {} {}, {}".format(
self.owner,
self.name, self.street, self.postal_code, self.city,
self.full_name, self.street, self.postal_code, self.city,
self.country)
###
@ -1059,7 +1058,21 @@ class Bill(models.Model):
- 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
@ -1182,6 +1195,13 @@ class BillRecord(models.Model):
else:
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):
if self.is_recurring_record:
bill_line = f"{self.starting_date} - {self.ending_date}: {self.quantity} x {self.order}"

View File

@ -6,7 +6,7 @@
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
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
decided that this is an acceptable uglyness.
@ -695,9 +695,9 @@ oAsAAAAAAACGQNAFAAAAAAAAQyDoAgAAAAAAgCEQdAEAAAAAAMAQCLoAAAAAAABgCP83AL6WQ1Y7
<thead>
<tr>
<th>Detail</th>
<th>Units</th>
<th>Price/Unit</th>
<th class="tr">Total price</tH>
<th>Units</th>
<th>Total price</th>
</tr>
</thead>
<tbody>
@ -707,8 +707,8 @@ oAsAAAAAAACGQNAFAAAAAAAAQyDoAgAAAAAAgCEQdAEAAAAAAMAQCLoAAAAAAABgCP83AL6WQ1Y7
- {{ record.ending_date|date:"c" }}
{{ record.order }}
</td>
<td>{{ record.price|floatformat:2 }}</td>
<td>{{ record.quantity|floatformat:2 }}</td>
<td>{{ record.order.price|floatformat:2 }}</td>
<td>{{ record.sum|floatformat:2 }}</td>
</tr>
{% endfor %}

View File

@ -201,6 +201,7 @@ class BillViewSet(viewsets.ReadOnlyModelViewSet):
Allow to download
"""
bill = self.get_object()
provider = UncloudProvider.get_provider()
output_file = NamedTemporaryFile()
bill_html = render_to_string("bill.html.j2", {'bill': bill})