Late commits

This commit is contained in:
Nico Schottelius 2021-06-20 11:51:27 +02:00
commit a463bcf7bd
9 changed files with 161 additions and 14 deletions

View file

@ -1,6 +1,9 @@
from django.utils import timezone
from django.db import transaction
from django.db.models import Q
from uncloud.selectors import filter_for_when
from uncloud.models import UncloudProvider
from .models import *
def get_payments_for_user(user):
@ -24,3 +27,32 @@ def get_balance_for_user(user):
def get_billing_address_for_user(user):
return BillingAddress.objects.get(owner=user, active=True)
def get_vat_rate(billing_address, when=None):
"""
Returns the VAT rate for business to customer.
B2B is always 0% with the exception of trading within the own country
"""
country = billing_address.country
# Need to have a provider country
uncloud_provider = filter_for_when(UncloudProvider.objects.all()).get()
vatrate = filter_for_when(VATRate.objects.filter(territory_codes=country), when).first()
# By default we charge VAT. This affects:
# - Same country sales (VAT applied)
# - B2C to EU (VAT applied)
rate = vatrate.rate
# Exception: if...
# - the billing_address is in EU,
# - the vat_number has been set
# - the vat_number has been verified
# Then we do not charge VAT
if uncloud_provider.country != country and billing_address.vat_number and billing_address.vat_number_verified:
rate = 0
return rate