2016-04-10 21:12:43 +00:00
|
|
|
from django.db import models
|
2016-10-14 04:33:48 +00:00
|
|
|
|
|
|
|
from membership.models import CustomUser
|
2016-04-10 21:12:43 +00:00
|
|
|
|
2016-04-26 06:16:03 +00:00
|
|
|
from .fields import CountryField
|
|
|
|
|
2016-04-10 21:12:43 +00:00
|
|
|
|
2016-10-14 04:33:48 +00:00
|
|
|
# Create your models here.
|
2016-04-10 21:12:43 +00:00
|
|
|
|
2016-10-14 04:33:48 +00:00
|
|
|
class BaseBillingAddress(models.Model):
|
2017-07-16 09:53:18 +00:00
|
|
|
cardholder_name = models.CharField(max_length=100, default="")
|
2016-04-26 06:16:03 +00:00
|
|
|
street_address = models.CharField(max_length=100)
|
|
|
|
city = models.CharField(max_length=50)
|
|
|
|
postal_code = models.CharField(max_length=50)
|
|
|
|
country = CountryField()
|
2019-12-25 03:01:40 +00:00
|
|
|
vat_number = models.CharField(max_length=100, default="", blank=True)
|
2019-12-26 06:11:29 +00:00
|
|
|
stripe_tax_id = models.CharField(max_length=100, default="", blank=True)
|
2019-12-25 05:30:04 +00:00
|
|
|
vat_number_validated_on = models.DateTimeField(blank=True, null=True)
|
2019-12-26 14:05:50 +00:00
|
|
|
vat_validation_status = models.CharField(max_length=25, default="",
|
|
|
|
blank=True)
|
2016-04-26 06:16:03 +00:00
|
|
|
|
2016-10-14 04:33:48 +00:00
|
|
|
class Meta:
|
|
|
|
abstract = True
|
|
|
|
|
2017-06-29 14:34:40 +00:00
|
|
|
|
2016-10-14 04:33:48 +00:00
|
|
|
class BillingAddress(BaseBillingAddress):
|
2016-07-27 05:08:45 +00:00
|
|
|
def __str__(self):
|
2019-12-21 03:22:06 +00:00
|
|
|
if self.vat_number:
|
2019-12-26 14:25:28 +00:00
|
|
|
return "%s, %s, %s, %s, %s, %s %s %s %s" % (
|
2019-12-21 03:22:06 +00:00
|
|
|
self.cardholder_name, self.street_address, self.city,
|
2019-12-26 13:04:26 +00:00
|
|
|
self.postal_code, self.country, self.vat_number,
|
2019-12-26 14:25:28 +00:00
|
|
|
self.stripe_tax_id, self.vat_number_validated_on,
|
|
|
|
self.vat_validation_status
|
2019-12-21 03:22:06 +00:00
|
|
|
)
|
|
|
|
else:
|
|
|
|
return "%s, %s, %s, %s, %s" % (
|
|
|
|
self.cardholder_name, self.street_address, self.city,
|
|
|
|
self.postal_code, self.country
|
|
|
|
)
|
2016-07-27 05:08:45 +00:00
|
|
|
|
2016-04-26 06:16:03 +00:00
|
|
|
|
2016-10-14 04:33:48 +00:00
|
|
|
class UserBillingAddress(BaseBillingAddress):
|
|
|
|
user = models.ForeignKey(CustomUser, related_name='billing_addresses')
|
|
|
|
current = models.BooleanField(default=True)
|
|
|
|
|
|
|
|
def __str__(self):
|
2019-12-21 04:35:58 +00:00
|
|
|
if self.vat_number:
|
2019-12-26 14:25:28 +00:00
|
|
|
return "%s, %s, %s, %s, %s, %s %s %s %s" % (
|
2019-12-21 04:35:58 +00:00
|
|
|
self.cardholder_name, self.street_address, self.city,
|
2019-12-26 13:04:26 +00:00
|
|
|
self.postal_code, self.country, self.vat_number,
|
2019-12-26 14:25:28 +00:00
|
|
|
self.stripe_tax_id, self.vat_number_validated_on,
|
|
|
|
self.vat_validation_status
|
2019-12-21 04:35:58 +00:00
|
|
|
)
|
|
|
|
else:
|
|
|
|
return "%s, %s, %s, %s, %s" % (
|
|
|
|
self.cardholder_name, self.street_address, self.city,
|
|
|
|
self.postal_code, self.country
|
|
|
|
)
|
2016-10-14 04:33:48 +00:00
|
|
|
|
|
|
|
def to_dict(self):
|
|
|
|
return {
|
2017-07-16 17:04:49 +00:00
|
|
|
'Cardholder Name': self.cardholder_name,
|
2016-10-14 04:33:48 +00:00
|
|
|
'Street Address': self.street_address,
|
|
|
|
'City': self.city,
|
|
|
|
'Postal Code': self.postal_code,
|
|
|
|
'Country': self.country,
|
2019-12-21 04:35:58 +00:00
|
|
|
'VAT Number': self.vat_number
|
2016-10-14 04:33:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-10 21:12:43 +00:00
|
|
|
class ContactMessage(models.Model):
|
|
|
|
name = models.CharField(max_length=200)
|
|
|
|
email = models.EmailField()
|
2017-03-22 15:18:10 +00:00
|
|
|
phone_number = models.CharField(max_length=200, blank=True)
|
2016-04-10 21:12:43 +00:00
|
|
|
message = models.TextField()
|
|
|
|
received_date = models.DateTimeField(auto_now_add=True)
|
|
|
|
|
|
|
|
def __str__(self):
|
2016-04-26 06:16:03 +00:00
|
|
|
return "%s - %s - %s" % (self.name, self.email, self.received_date)
|