81 lines
No EOL
2.5 KiB
Python
81 lines
No EOL
2.5 KiB
Python
from django.contrib.gis.db import models
|
|
from django.utils import timezone
|
|
from django.conf import settings
|
|
|
|
from clients.models import ClientProfile
|
|
from partners.models import Establishment, RoomCategory
|
|
|
|
from dateutil.relativedelta import relativedelta
|
|
|
|
import uuid
|
|
|
|
class LengthChoices(models.IntegerChoices):
|
|
ANY = 0
|
|
SHORT = 1
|
|
LONG = 2
|
|
|
|
class Inquiry(models.Model):
|
|
uuid = models.UUIDField(default=uuid.uuid4, unique=True)
|
|
client = models.ForeignKey(ClientProfile, models.PROTECT, null=True, blank=True)
|
|
destination_name = models.CharField(max_length=128)
|
|
destination_coords = models.PointField()
|
|
destination_radius = models.IntegerField()
|
|
arrival = models.DateField()
|
|
min_nights = models.IntegerField(default=0, choices=LengthChoices.choices)
|
|
budget = models.DecimalField(max_digits=10, decimal_places=2)
|
|
adults = models.IntegerField()
|
|
children = models.IntegerField()
|
|
comment = models.TextField(null=True, blank=True)
|
|
activated = models.DateTimeField(null=True, blank=True)
|
|
gateway = models.CharField(max_length=128, null=True, blank=True)
|
|
|
|
@property
|
|
def is_paid(self):
|
|
if not self.invoice:
|
|
return False
|
|
|
|
return self.invoice.is_paid
|
|
|
|
def process_payment(self):
|
|
self.activated = timezone.now()
|
|
self.save()
|
|
|
|
@property
|
|
def expiry(self):
|
|
if self.activated:
|
|
return self.activated + relativedelta(days=settings.INQUIRY_RUNTIME)
|
|
|
|
@property
|
|
def expired(self):
|
|
return self.expiry and (self.expiry < timezone.now())
|
|
|
|
@property
|
|
def active(self):
|
|
try:
|
|
return bool(self.activated) and not self.expired
|
|
except:
|
|
return False
|
|
|
|
@property
|
|
def accepted(self):
|
|
try:
|
|
return Offer.objects.get(inquiry=self, accepted__isnull=False)
|
|
except Offer.DoesNotExist:
|
|
return False
|
|
|
|
class Offer(models.Model):
|
|
uuid = models.UUIDField(default=uuid.uuid4, unique=True)
|
|
inquiry = models.ForeignKey(Inquiry, models.PROTECT)
|
|
roomcategory = models.ForeignKey(RoomCategory, models.PROTECT)
|
|
departure = models.DateField()
|
|
comment = models.TextField(null=True, blank=True)
|
|
accepted = models.DateTimeField(null=True, blank=True)
|
|
hidden = models.BooleanField(default=False)
|
|
|
|
@property
|
|
def establishment(self):
|
|
return self.roomcategory.establishment
|
|
|
|
@property
|
|
def nights(self):
|
|
return (self.departure - self.inquiry.arrival).days |