Move variables into database

Improve auction activation logic
This commit is contained in:
Kumi 2021-05-30 17:47:56 +02:00
parent b586fb89b5
commit 2b175339dc
2 changed files with 14 additions and 13 deletions

View file

@ -1,12 +1,13 @@
from django.contrib.gis.db import models from django.contrib.gis.db import models
from django.utils import timezone from django.utils import timezone
from django.conf import settings
from django.contrib.gis.db.models.functions import Distance from django.contrib.gis.db.models.functions import Distance
from clients.models import ClientProfile from clients.models import ClientProfile
from partners.models import Establishment, RoomCategory from partners.models import Establishment, RoomCategory
from dateutil.relativedelta import relativedelta from dbsettings.functions import getValue
from datetime import timedelta
import uuid import uuid
@ -28,6 +29,7 @@ class Inquiry(models.Model):
children = models.IntegerField() children = models.IntegerField()
comment = models.TextField(null=True, blank=True) comment = models.TextField(null=True, blank=True)
activated = models.DateTimeField(null=True, blank=True) activated = models.DateTimeField(null=True, blank=True)
bidding_end = models.DateTimeField(null=True, blank=True)
gateway = models.CharField(max_length=128, null=True, blank=True) gateway = models.CharField(max_length=128, null=True, blank=True)
@property @property
@ -37,15 +39,18 @@ class Inquiry(models.Model):
return self.invoice.is_paid return self.invoice.is_paid
def process_payment(self): def activate(self):
if self.invoice.is_paid: if self.activated:
return False
self.activated = timezone.now() self.activated = timezone.now()
self.bidding_end = self.activated + timedelta(hours=getValue("auction.bidding_period", 24))
self.auction_end = self.bidding_end + timedelta(hours=getValue("auction.selection_period", 24))
self.save() self.save()
@property def process_payment(self):
def expiry(self): if self.invoice.is_paid:
if self.activated: self.activate()
return self.activated + relativedelta(days=settings.INQUIRY_RUNTIME)
@property @property
def expired(self): def expired(self):

View file

@ -58,7 +58,3 @@ JOKER_COUNTRIES = ["AT"]
CURRENCY_SYMBOL = "" CURRENCY_SYMBOL = ""
CURRENCY_CODE = "EUR" CURRENCY_CODE = "EUR"
CURRENCY_NAME = "Euro" CURRENCY_NAME = "Euro"
# Run time of inquiries in days
INQUIRY_RUNTIME = 7