various updates
This commit is contained in:
parent
0cd8a3a787
commit
8959bc6ad5
7 changed files with 103 additions and 10 deletions
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.
|
||||
|
||||
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}"
|
||||
|
|
|
|||
|
|
@ -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 %}
|
||||
|
|
|
|||
|
|
@ -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})
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue