2020-04-13 18:03:01 +00:00
|
|
|
from polymorphic.models import PolymorphicModel
|
|
|
|
from phonenumber_field.modelfields import PhoneNumberField
|
2020-05-27 13:06:38 +00:00
|
|
|
from internationalflavor.vat_number.models import VATNumberField
|
|
|
|
from django_countries.fields import CountryField
|
2020-04-13 18:03:01 +00:00
|
|
|
|
2020-05-27 13:06:38 +00:00
|
|
|
from django.db.models import OneToOneField, CASCADE, ImageField, Model, ForeignKey, SET_DEFAULT, ManyToManyField, DateTimeField, TextField
|
2020-04-13 18:03:01 +00:00
|
|
|
from django.contrib.auth import get_user_model
|
|
|
|
|
2020-04-18 13:02:41 +00:00
|
|
|
from core.helpers.files import generate_storage_filename
|
2020-05-27 13:06:38 +00:00
|
|
|
from core.models.local import Currency
|
|
|
|
from core.models.brands import Brand
|
|
|
|
from core.fields.base import LongCharField
|
2020-06-02 15:58:20 +00:00
|
|
|
from core.fields.color import ColorField
|
2020-05-27 13:06:38 +00:00
|
|
|
|
|
|
|
class ClientGroup(Model):
|
|
|
|
name = LongCharField()
|
2020-06-02 15:58:20 +00:00
|
|
|
color = ColorField()
|
2020-04-18 13:02:41 +00:00
|
|
|
|
2020-06-04 04:21:13 +00:00
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
2020-04-13 18:03:01 +00:00
|
|
|
class Profile(PolymorphicModel):
|
|
|
|
user = OneToOneField(get_user_model(), CASCADE)
|
|
|
|
mobile = PhoneNumberField(blank=True)
|
|
|
|
|
|
|
|
class AdminProfile(Profile):
|
2020-05-27 13:06:38 +00:00
|
|
|
role = LongCharField()
|
2020-04-18 13:02:41 +00:00
|
|
|
image = ImageField(null=True, blank=True, upload_to=generate_storage_filename)
|
2020-05-27 13:06:38 +00:00
|
|
|
display_name = LongCharField("Internal Display Name", null=True, blank=True)
|
2020-06-03 15:05:18 +00:00
|
|
|
permission_string = TextField(blank=True, default="")
|
2020-04-18 13:02:41 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def get_internal_name(self):
|
2020-05-27 13:06:38 +00:00
|
|
|
return self.display_name if self.display_name else self.user.get_full_name
|
|
|
|
|
2020-06-03 15:05:18 +00:00
|
|
|
@property
|
|
|
|
def permissions(self):
|
|
|
|
return self.permission_string.split(",")
|
|
|
|
|
|
|
|
@permissions.setter
|
|
|
|
def permissions(self, permissions):
|
|
|
|
if isinstance(permissions, str):
|
|
|
|
self.permission_string = permissions
|
|
|
|
else:
|
|
|
|
self.permission_string = ",".join(permissions)
|
|
|
|
|
2020-05-27 13:06:38 +00:00
|
|
|
class ClientProfile(Profile):
|
2020-05-31 12:08:26 +00:00
|
|
|
company = LongCharField(null=True, blank=True)
|
2020-05-27 13:06:38 +00:00
|
|
|
address1 = LongCharField()
|
2020-05-31 12:08:26 +00:00
|
|
|
address2 = LongCharField(null=True, blank=True)
|
2020-05-27 13:06:38 +00:00
|
|
|
zip = LongCharField()
|
|
|
|
city = LongCharField()
|
2020-05-31 12:08:26 +00:00
|
|
|
state = LongCharField(null=True, blank=True)
|
2020-05-27 13:06:38 +00:00
|
|
|
country = CountryField()
|
2020-05-31 12:08:26 +00:00
|
|
|
vat_id = VATNumberField(null=True, blank=True)
|
|
|
|
company_id = LongCharField(null=True, blank=True)
|
2020-05-27 13:06:38 +00:00
|
|
|
default_currency = ForeignKey(Currency, on_delete=SET_DEFAULT, default=Currency.get_base)
|
|
|
|
client_groups = ManyToManyField(ClientGroup)
|
|
|
|
brands = ManyToManyField(Brand)
|
|
|
|
marketing_opt_in = DateTimeField(null=True)
|
|
|
|
pgp_key = TextField(null=True)
|
|
|
|
main_client = ForeignKey("self", null=True, on_delete=SET_DEFAULT, default=None)
|