expephalon-demomodule/core/models/local.py
Klaus-Uwe Mitterer 85fe13edcf Implemented TOTP
Implemented currencies and taxes
2020-05-22 18:13:23 +02:00

34 lines
1.2 KiB
Python

from django.db.models import Model, CharField, BooleanField, DecimalField, ForeignKey, CASCADE
from django_countries.fields import CountryField
class Currency(Model):
name = CharField(max_length=255, unique=True)
code = CharField(max_length=16, unique=True)
symbol = CharField(max_length=8)
base = BooleanField(default=False)
rate = DecimalField(default=1, max_digits=30, decimal_places=10)
def set_base(self):
type(self).get_base().update(base=False)
self.update(base=True)
@classmethod
def get_base(cls):
return cls.objects.get(base=True)
class TaxPolicy(Model):
name = CharField(max_length=255, blank=True)
default_rate = DecimalField(default=0, max_digits=10, decimal_places=5)
def get_applicable_rate(self, country, reverse_charge=False):
rule = self.taxrule_set.get(destination_country=country)
if reverse_charge:
return rule.tax_rate if not rule.reverse_charge else 0
return rule.tax_rate
class TaxRule(Model):
policy = ForeignKey(TaxPolicy, on_delete=CASCADE)
destination_country = CountryField()
tax_rate = DecimalField(max_digits=10, decimal_places=5)
reverse_charge = BooleanField(default=False)