diff --git a/digitalglarus/forms.py b/digitalglarus/forms.py index f5bb53aa..b6fb9ea7 100644 --- a/digitalglarus/forms.py +++ b/digitalglarus/forms.py @@ -8,7 +8,7 @@ from utils.models import BillingAddress from utils.forms import LoginFormMixin, SignupFormMixin, BillingAddressForm from .models import MembershipType, MembershipOrder -from .models import Booking +from .models import Booking, BookingOrder class LoginForm(LoginFormMixin): @@ -74,6 +74,21 @@ class BookingBillingForm(BillingAddressForm): } +class CancelBookingForm(forms.ModelForm): + status = forms.CharField(widget=forms.HiddenInput(), required=False) + + class Meta: + model = BookingOrder + fields = ['status'] + + def clean(self): + booking = self.instance.booking + days_to_start = (booking.start_date - datetime.today().date()).days + if days_to_start < 7: + raise forms.ValidationError("You can't cancel your booking") + return self.cleaned_data + + class BookingDateForm(forms.Form): start_date = forms.DateField(required=False, widget=forms.TextInput(attrs={'id': 'booking-date-1', diff --git a/digitalglarus/migrations/0023_bookingorder_status.py b/digitalglarus/migrations/0023_bookingorder_status.py new file mode 100644 index 00000000..80f6cd83 --- /dev/null +++ b/digitalglarus/migrations/0023_bookingorder_status.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.4 on 2016-11-25 03:04 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('digitalglarus', '0022_auto_20161023_0218'), + ] + + operations = [ + migrations.AddField( + model_name='bookingorder', + name='status', + field=models.PositiveIntegerField(choices=[(1, 'Approved'), (2, 'Cancelled')], default=1), + ), + ] diff --git a/digitalglarus/models.py b/digitalglarus/models.py index ae91db47..82f6b35b 100644 --- a/digitalglarus/models.py +++ b/digitalglarus/models.py @@ -238,9 +238,18 @@ class Booking(models.Model): class BookingOrder(Ordereable, models.Model): + + APPROVED, CANCELLED = range(1, 3) + + STATUS_CHOICES = ( + (APPROVED, 'Approved'), + (CANCELLED, 'Cancelled') + ) + booking = models.OneToOneField(Booking) original_price = models.FloatField() special_month_price = models.FloatField() + status = models.PositiveIntegerField(choices=STATUS_CHOICES, default=1) @classmethod def user_has_not_bookings(cls, user): @@ -255,6 +264,15 @@ class BookingOrder(Ordereable, models.Model): def booking_days(self): return (self.booking.end_date - self.booking.start_date).days + 1 + def cancellation_available(self): + days_to_start = (booking.start_date - datetime.today()).days + return False if days_to_start < 7 else True + + + def cancel(self): + self.status = self.CANCELLED + self.save() + class Supporter(models.Model): name = models.CharField(max_length=200) diff --git a/digitalglarus/templates/digitalglarus/booking_orders_detail.html b/digitalglarus/templates/digitalglarus/booking_orders_detail.html index 9dd8a25c..2cfe2f76 100644 --- a/digitalglarus/templates/digitalglarus/booking_orders_detail.html +++ b/digitalglarus/templates/digitalglarus/booking_orders_detail.html @@ -20,10 +20,22 @@
View my bookings
Go to my page
-