diff --git a/digitalglarus/admin.py b/digitalglarus/admin.py index a83ac4ad..4f8bdcfa 100644 --- a/digitalglarus/admin.py +++ b/digitalglarus/admin.py @@ -1,15 +1,29 @@ from django.contrib import admin from .models import Supporter, DGGallery, DGPicture, Booking, BookingPrice,\ - MembershipOrder, Membership, MembershipType, BookingOrder + MembershipOrder, Membership, MembershipType, BookingOrder, BookingCancellation +from django.core.urlresolvers import reverse from utils.models import ContactMessage -# +from django.utils.html import format_html + + class DGPictureInline(admin.StackedInline): model = DGPicture + class DGGalleryAdmin(admin.ModelAdmin): inlines = [DGPictureInline] + +class BookingCancellationAdmin(admin.ModelAdmin): + list_display = ('id', 'get_order', 'created_at', 'required_refund', 'refund') + + def get_order(self, obj): + order = obj.order + order_url = reverse("admin:digitalglarus_bookingorder_change", args=[order.id]) + return format_html("{order_id}", url=order_url, order_id=order.id) + + admin.site.register(DGGallery, DGGalleryAdmin) admin.site.register(ContactMessage) admin.site.register(Booking) @@ -18,3 +32,4 @@ admin.site.register(MembershipOrder) admin.site.register(Membership) admin.site.register(MembershipType) admin.site.register(BookingOrder) +admin.site.register(BookingCancellation, BookingCancellationAdmin) diff --git a/digitalglarus/forms.py b/digitalglarus/forms.py index b6fb9ea7..9dc35eed 100644 --- a/digitalglarus/forms.py +++ b/digitalglarus/forms.py @@ -81,12 +81,12 @@ class CancelBookingForm(forms.ModelForm): 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 + # 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): diff --git a/digitalglarus/migrations/0024_bookingcancellation.py b/digitalglarus/migrations/0024_bookingcancellation.py new file mode 100644 index 00000000..70c8a23a --- /dev/null +++ b/digitalglarus/migrations/0024_bookingcancellation.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.4 on 2016-12-02 02:22 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('digitalglarus', '0023_bookingorder_status'), + ] + + operations = [ + migrations.CreateModel( + name='BookingCancellation', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created_at', models.DateTimeField(auto_now=True)), + ('required_refund', models.BooleanField(default=True)), + ('refund', models.BooleanField(default=False)), + ('order', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='digitalglarus.BookingOrder')), + ], + ), + ] diff --git a/digitalglarus/models.py b/digitalglarus/models.py index 82f6b35b..26ecb4ff 100644 --- a/digitalglarus/models.py +++ b/digitalglarus/models.py @@ -264,16 +264,31 @@ 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 refund_required(self): + days_to_start = (self.booking.start_date - datetime.today().date()).days + return True if days_to_start < 7 else False def cancel(self): self.status = self.CANCELLED self.save() +class BookingCancellation(models.Model): + + order = models.ForeignKey(BookingOrder) + created_at = models.DateTimeField(auto_now=True) + required_refund = models.BooleanField(default=True) + refund = models.BooleanField(default=False) + + def __str__(self): + return "Order: {} - Required Refund: {}".format(self.order.id, self.refund) + + @classmethod + def create(cls, booking_order): + required_refund = booking_order.refund_required() + cls.objects.create(order=booking_order, required_refund=required_refund) + + class Supporter(models.Model): name = models.CharField(max_length=200) description = models.TextField(null=True, blank=True) diff --git a/digitalglarus/templates/digitalglarus/booking_orders_detail.html b/digitalglarus/templates/digitalglarus/booking_orders_detail.html index 2cfe2f76..725e58d7 100644 --- a/digitalglarus/templates/digitalglarus/booking_orders_detail.html +++ b/digitalglarus/templates/digitalglarus/booking_orders_detail.html @@ -87,6 +87,9 @@
Do you want to cancel your booking?
++ Your booking is within 7 days. You may cancel your booking but the fees will not be refunded. Your booking can be only cancelled freely until 7 days before the booked date. +