Skip to content

Commit

Permalink
Merge a551580 into 3c48b2e
Browse files Browse the repository at this point in the history
  • Loading branch information
rayrayndwiga committed Nov 2, 2017
2 parents 3c48b2e + a551580 commit d9537b2
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 17 deletions.
20 changes: 20 additions & 0 deletions parkstay/migrations/0039_booking_cancelation_time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.8 on 2017-11-02 02:45
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('parkstay', '0038_auto_20171019_1402'),
]

operations = [
migrations.AddField(
model_name='booking',
name='cancelation_time',
field=models.DateTimeField(blank=True, null=True),
),
]
2 changes: 2 additions & 0 deletions parkstay/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,7 @@ class Booking(models.Model):
campground = models.ForeignKey('Campground', null=True)
is_canceled = models.BooleanField(default=False)
cancellation_reason = models.TextField(null=True,blank=True)
cancelation_time = models.DateTimeField(null=True,blank=True)
confirmation_sent = models.BooleanField(default=False)
created = models.DateTimeField(default=timezone.now)

Expand Down Expand Up @@ -1133,6 +1134,7 @@ def cancelBooking(self,reason):
raise ValidationError('You cannot cancel a booking past the departure date.')
self.cancellation_reason = reason
self.is_canceled = True
self.cancelation_time = timezone.now()
self.campsites.all().delete()
references = self.invoices.all().values('invoice_reference')
for r in references:
Expand Down
2 changes: 1 addition & 1 deletion parkstay/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def booking_refunds(start,end):
cash.extend([x for x in CashTransaction.objects.filter(created__gte=start, created__lte=end,type='refund')])

strIO = StringIO()
fieldnames = ['Confirmation Number', 'Name', 'Type','Amount','Oracle Code','Date','Refunded By']
fieldnames = ['Confirmation Number', 'Name', 'Type','Amount','Oracle Code','Date','Refunded By','Invoice']
writer = csv.writer(strIO)
writer.writerow(fieldnames)

Expand Down
13 changes: 13 additions & 0 deletions parkstay/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@
'parkstay.cron.OracleIntegrationCronJob',
]

# Additional logging for parkstay
LOGGING['handlers']['booking_checkout'] = {
'level': 'INFO',
'class': 'logging.handlers.RotatingFileHandler',
'filename': os.path.join(BASE_DIR, 'logs', 'parkstay_booking_checkout.log'),
'formatter': 'verbose',
'maxBytes': 5242880
}
LOGGING['loggers']['booking_checkout'] = {
'handlers': ['booking_checkout'],
'level': 'INFO'
}

CAMPGROUNDS_EMAIL = env('CAMPGROUNDS_EMAIL','parkstaybookings@dbca.wa.gov.au')
EXPLORE_PARKS_URL = env('EXPLORE_PARKS_URL','https://parks-oim.dpaw.wa.gov.au')
PARKSTAY_EXTERNAL_URL = env('PARKSTAY_EXTERNAL_URL','https://parkstay.dbca.wa.gov.au')
Expand Down
51 changes: 35 additions & 16 deletions parkstay/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

import logging
from django.db.models import Q
from django.http import Http404, HttpResponse, JsonResponse
from django.shortcuts import render, get_object_or_404, redirect
Expand Down Expand Up @@ -29,13 +29,16 @@
)
from parkstay import emails
from ledger.accounts.models import EmailUser, Address
from ledger.payments.models import Invoice
from django_ical.views import ICalFeed
from datetime import datetime, timedelta
from decimal import *

from parkstay.helpers import is_officer
from parkstay import utils

logger = logging.getLogger('booking_checkout')

class CampsiteBookingSelector(TemplateView):
template_name = 'ps/campsite_booking_selector.html'

Expand Down Expand Up @@ -311,22 +314,38 @@ def get(self, request, *args, **kwargs):
booking = utils.get_session_booking(request.session)
invoice_ref = request.GET.get('invoice')

# FIXME: replace with server side notify_url callback
book_inv, created = BookingInvoice.objects.get_or_create(booking=booking, invoice_reference=invoice_ref)

# set booking to be permanent fixture
booking.booking_type = 1 # internet booking
booking.expiry_time = None
booking.save()
try:
inv = Invoice.objects.get(reference=invoice_ref)
except Invoice.DoesNotExist:
logger.error('{} tried making a booking with an incorrect invoice'.format('User {} with id {}'.format(booking.customer.get_full_name(),booking.customer.id) if booking.customer else 'An anonymous user'))
return redirect('public_make_booking')

utils.delete_session_booking(request.session)
request.session['ps_last_booking'] = booking.id

# send out the invoice before the confirmation is sent
emails.send_booking_invoice(booking)
# for fully paid bookings, fire off confirmation email
if booking.paid:
emails.send_booking_confirmation(booking,request)
if inv.system not in ['0019']:
logger.error('{} tried making a booking with an invoice from another system with reference number {}'.format('User {} with id {}'.format(booking.customer.get_full_name(),booking.customer.id) if booking.customer else 'An anonymous user',inv.reference))
return redirect('public_make_booking')

try:
b = BookingInvoice.objects.get(invoice_reference=invoice_ref)
logger.error('{} tried making a booking with an already used invoice with reference number {}'.format('User {} with id {}'.format(booking.customer.get_full_name(),booking.customer.id) if booking.customer else 'An anonymous user',inv.reference))
return redirect('public_make_booking')
except BookingInvoice.DoesNotExist:

# FIXME: replace with server side notify_url callback
book_inv, created = BookingInvoice.objects.get_or_create(booking=booking, invoice_reference=invoice_ref)

# set booking to be permanent fixture
booking.booking_type = 1 # internet booking
booking.expiry_time = None
booking.save()

utils.delete_session_booking(request.session)
request.session['ps_last_booking'] = booking.id

# send out the invoice before the confirmation is sent
emails.send_booking_invoice(booking)
# for fully paid bookings, fire off confirmation email
if booking.paid:
emails.send_booking_confirmation(booking,request)

except Exception as e:
if ('ps_last_booking' in request.session) and Booking.objects.filter(id=request.session['ps_last_booking']).exists():
Expand Down

0 comments on commit d9537b2

Please sign in to comment.