2014-05-08 16:59:35 +00:00
|
|
|
from django.db import models
|
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
|
2014-07-29 14:29:59 +00:00
|
|
|
from orchestra.core import accounts
|
2014-05-08 16:59:35 +00:00
|
|
|
from orchestra.models.fields import MultiSelectField
|
|
|
|
|
|
|
|
from . import settings
|
|
|
|
|
|
|
|
|
2014-09-04 15:55:43 +00:00
|
|
|
class ContactQuerySet(models.QuerySet):
|
|
|
|
def filter(self, *args, **kwargs):
|
|
|
|
usages = kwargs.pop('email_usages', [])
|
|
|
|
qs = models.Q()
|
|
|
|
for usage in usages:
|
|
|
|
qs = qs | models.Q(email_usage__regex=r'.*(^|,)+%s($|,)+.*' % usage)
|
|
|
|
return super(ContactQuerySet, self).filter(qs, *args, **kwargs)
|
|
|
|
|
|
|
|
|
2014-05-08 16:59:35 +00:00
|
|
|
class Contact(models.Model):
|
2014-09-04 15:55:43 +00:00
|
|
|
BILLING = 'BILLING'
|
|
|
|
EMAIL_USAGES = (
|
|
|
|
('SUPPORT', _("Support tickets")),
|
|
|
|
('ADMIN', _("Administrative")),
|
|
|
|
(BILLING, _("Billing")),
|
|
|
|
('TECH', _("Technical")),
|
|
|
|
('ADDS', _("Announcements")),
|
|
|
|
('EMERGENCY', _("Emergency contact")),
|
|
|
|
)
|
|
|
|
|
|
|
|
objects = ContactQuerySet.as_manager()
|
|
|
|
|
2014-05-08 16:59:35 +00:00
|
|
|
account = models.ForeignKey('accounts.Account', verbose_name=_("Account"),
|
|
|
|
related_name='contacts', null=True)
|
|
|
|
short_name = models.CharField(_("short name"), max_length=128)
|
|
|
|
full_name = models.CharField(_("full name"), max_length=256, blank=True)
|
|
|
|
email = models.EmailField()
|
|
|
|
email_usage = MultiSelectField(_("email usage"), max_length=256, blank=True,
|
2014-09-04 15:55:43 +00:00
|
|
|
choices=EMAIL_USAGES,
|
2014-05-08 16:59:35 +00:00
|
|
|
default=settings.CONTACTS_DEFAULT_EMAIL_USAGES)
|
2014-07-29 14:29:59 +00:00
|
|
|
phone = models.CharField(_("phone"), max_length=32, blank=True)
|
|
|
|
phone2 = models.CharField(_("alternative phone"), max_length=32, blank=True)
|
2014-05-08 16:59:35 +00:00
|
|
|
address = models.TextField(_("address"), blank=True)
|
|
|
|
city = models.CharField(_("city"), max_length=128, blank=True,
|
|
|
|
default=settings.CONTACTS_DEFAULT_CITY)
|
|
|
|
zipcode = models.PositiveIntegerField(_("zip code"), null=True, blank=True)
|
|
|
|
country = models.CharField(_("country"), max_length=20, blank=True,
|
|
|
|
default=settings.CONTACTS_DEFAULT_COUNTRY)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return self.short_name
|
|
|
|
|
|
|
|
|
|
|
|
class InvoiceContact(models.Model):
|
|
|
|
account = models.OneToOneField('accounts.Account', verbose_name=_("account"),
|
|
|
|
related_name='invoicecontact')
|
|
|
|
name = models.CharField(_("name"), max_length=256)
|
|
|
|
address = models.TextField(_("address"))
|
|
|
|
city = models.CharField(_("city"), max_length=128,
|
|
|
|
default=settings.CONTACTS_DEFAULT_CITY)
|
|
|
|
zipcode = models.PositiveIntegerField(_("zip code"))
|
|
|
|
country = models.CharField(_("country"), max_length=20,
|
|
|
|
default=settings.CONTACTS_DEFAULT_COUNTRY)
|
|
|
|
vat = models.CharField(_("VAT number"), max_length=64)
|
2014-07-29 14:29:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
accounts.register(Contact)
|