kfet -- Fix available checkouts in K-Psul
The checkout validity is checked using the current datetime (when requesting the kpsul page).
This commit is contained in:
parent
e23e1bdba6
commit
525bb4d16d
2 changed files with 17 additions and 8 deletions
|
@ -296,17 +296,17 @@ class KPsulAccountForm(forms.ModelForm):
|
|||
|
||||
class KPsulCheckoutForm(forms.Form):
|
||||
checkout = forms.ModelChoiceField(
|
||||
queryset=(
|
||||
Checkout.objects
|
||||
.filter(
|
||||
is_protected=False,
|
||||
valid_from__lte=timezone.now(),
|
||||
valid_to__gte=timezone.now(),
|
||||
)
|
||||
),
|
||||
queryset=None,
|
||||
widget=forms.Select(attrs={'id': 'id_checkout_select'}),
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
# Create the queryset on form instanciation to use the current time.
|
||||
self.fields['checkout'].queryset = (
|
||||
Checkout.objects.is_valid().filter(is_protected=False))
|
||||
|
||||
|
||||
class KPsulOperationForm(forms.ModelForm):
|
||||
article = forms.ModelChoiceField(
|
||||
|
|
|
@ -341,6 +341,13 @@ class AccountNegative(models.Model):
|
|||
return self.start + kfet_config.overdraft_duration
|
||||
|
||||
|
||||
class CheckoutQuerySet(models.QuerySet):
|
||||
|
||||
def is_valid(self):
|
||||
now = timezone.now()
|
||||
return self.filter(valid_from__lte=now, valid_to__gte=now)
|
||||
|
||||
|
||||
class Checkout(models.Model):
|
||||
created_by = models.ForeignKey(
|
||||
Account, on_delete = models.PROTECT,
|
||||
|
@ -353,6 +360,8 @@ class Checkout(models.Model):
|
|||
default = 0)
|
||||
is_protected = models.BooleanField(default = False)
|
||||
|
||||
objects = CheckoutQuerySet.as_manager()
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('kfet.checkout.read', kwargs={'pk': self.pk})
|
||||
|
||||
|
|
Loading…
Reference in a new issue