various updates

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

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}"