Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mooring Updates #371

Merged
merged 1 commit into from
Aug 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions mooring/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1355,6 +1355,7 @@ def create_booking(request, *args, **kwargs):
@require_http_methods(['GET'])
def get_confirmation(request, *args, **kwargs):
# fetch booking for ID
print "get_confirmation"
booking_id = kwargs.get('booking_id', None)
if (booking_id is None):
return HttpResponse('Booking ID not specified', status=400)
Expand Down Expand Up @@ -1649,7 +1650,7 @@ def list(self, request, *args, **kwargs):
join mooring_district on mooring_marinepark.district_id = mooring_district.id\
full outer join accounts_emailuser on mooring_booking.customer_id = accounts_emailuser.id\
join mooring_region on mooring_district.region_id = mooring_region.id\
left outer join mooring_mooringareagroup_campgrounds cg on cg.mooringarea_id = mooring_booking.mooringarea_id\
left outer join mooring_mooringareagroup_moorings cg on cg.mooringarea_id = mooring_booking.mooringarea_id\
full outer join mooring_mooringareagroup_members cm on cm.mooringareagroup_id = cg.mooringareagroup_id'

#sql = sqlSelect + sqlFrom + " where " if arrival or campground or region else sqlSelect + sqlFrom
Expand Down Expand Up @@ -1870,17 +1871,20 @@ def update(self, request, *args, **kwargs):
start_date = datetime.strptime(request.data['arrival'],'%d/%m/%Y').date()
end_date = datetime.strptime(request.data['departure'],'%d/%m/%Y').date()
guests = request.data['guests']

print "UPDATE"
print request.data
print instance
booking_details = {
'campsites':request.data['campsites'],
'start_date' : start_date,
'campground' : request.data['campground'],
'mooringarea' : request.data['mooringarea'],
'end_date' : end_date,
'num_adult' : guests['adults'],
'num_concession' : guests['concession'],
'num_child' : guests['children'],
'num_infant' : guests['infants'],
}

data = utils.update_booking(request,instance,booking_details)
serializer = BookingSerializer(data)

Expand Down
10 changes: 5 additions & 5 deletions mooring/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ class LoginForm(forms.Form):
email = forms.EmailField(max_length=254)

VEHICLE_TYPES = (
('0', 'Vehicle'),
('1', 'Vehicle (concession)'),
('2', 'Motorcycle')
('0', 'Vessel'),
# ('1', 'Vehicle (concession)'),
# ('2', 'Motorcycle')
)

class VehicleInfoForm(forms.Form):
vehicle_rego = forms.CharField(label="Vehicle Registration", widget=forms.TextInput(attrs={'required':True}))
vehicle_type = forms.ChoiceField(label="Vehicle Type", choices=VEHICLE_TYPES)
vehicle_rego = forms.CharField(label="Vessel Registration", widget=forms.TextInput(attrs={'required':True}))
vehicle_type = forms.ChoiceField(label="Vessel Type", choices=VEHICLE_TYPES)
entry_fee = forms.BooleanField(required=False, label="Entry fee")

VehicleInfoFormset = forms.formset_factory(VehicleInfoForm, extra=1, max_num=8)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<label class="control-label pull-left required" for="Dates">Mooring: </label>
</div>
<div class="col-md-8">
<select @change="updateCampground" class="form-control" name="campground" v-model="booking.mooringarea" readonly="true">
<select @change="updateCampground" class="form-control" name="campground" v-model="booking.mooringarea" >
<option v-for="c in onlineCampgrounds" :value="c.id">{{c.name}}</option>
</select>
</div>
Expand Down Expand Up @@ -219,6 +219,7 @@ export default {
loading: [],
guestsText: "",
campground: null,
mooringarea: null,
guestsPicker: [{
id: "adults",
name: "Adults (no concession)",
Expand Down Expand Up @@ -250,7 +251,7 @@ export default {
name: "Vehicle",
amount: 0,
price: 0,
description: "Vehicle Registration",
description: "Registration",
rego: "",
entry_fee: true
},
Expand Down Expand Up @@ -379,6 +380,7 @@ export default {
let vm = this;
console.log('SETTING CAMPGROUND');
vm.campground = vm.booking.mooringarea ? vm.campgrounds.find(c => parseInt(c.id) === parseInt(vm.booking.mooringarea)) : null;
vm.mooringarea = vm.booking.mooringarea ? vm.campgrounds.find(c => parseInt(c.id) === parseInt(vm.booking.mooringarea)) : null;
console.log('AM I'+vm.campground);
vm.fetchSites();
},
Expand Down Expand Up @@ -720,7 +722,8 @@ export default {
booking.departure = vm.booking.departure;
booking.guests = vm.booking.guests;
booking.campsites = [vm.selected_campsite];
booking.campground = vm.booking.campground
booking.campground = vm.booking.campground;
booking.mooringarea = vm.booking.mooringarea;
// Hide the alert
vm.$store.dispatch("updateAlert", {
visible: false,
Expand Down
20 changes: 20 additions & 0 deletions mooring/migrations/0035_auto_20180807_1301.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 2018-08-07 05:01
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('mooring', '0034_auto_20180807_1206'),
]

operations = [
migrations.AlterField(
model_name='bookingvehiclerego',
name='type',
field=models.CharField(choices=[('vessel', 'Vessel')], max_length=10),
),
]
20 changes: 20 additions & 0 deletions mooring/migrations/0036_auto_20180808_1528.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 2018-08-08 07:28
from __future__ import unicode_literals

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('mooring', '0035_auto_20180807_1301'),
]

operations = [
migrations.RenameField(
model_name='bookinghistory',
old_name='vehicles',
new_name='vessels',
),
]
19 changes: 10 additions & 9 deletions mooring/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ class MooringArea(models.Model):

CAMPGROUND_PRICE_LEVEL_CHOICES = (
(0, 'Mooring level'),
# (1, 'Mooringsite Class level'),
(1, 'Mooringsite Class level'),
# (2, 'Mooringsite level'),
)

SITE_TYPE_CHOICES = (
(0, 'Bookable Per Site'),
#(1, 'Bookable Per Site Type'),
(1, 'Bookable Per Site Type'),
#(2, 'Bookable Per Site Type (hide site number)'),
)

Expand Down Expand Up @@ -1238,7 +1238,7 @@ def cancelBooking(self,reason,user=None):

def _generate_history(self,user=None):
campsites = list(set([x.campsite.name for x in self.campsites.all()]))
vehicles = [{'rego':x.rego,'type':x.type,'entry_fee':x.entry_fee,'park_entry_fee':x.park_entry_fee} for x in self.regos.all()]
vessels = [{'rego':x.rego,'type':x.type,'entry_fee':x.entry_fee,'park_entry_fee':x.park_entry_fee} for x in self.regos.all()]
BookingHistory.objects.create(
booking = self,
updated_by=user,
Expand All @@ -1249,7 +1249,7 @@ def _generate_history(self,user=None):
confirmation_sent = self.confirmation_sent,
campground = self.mooringarea.name,
campsites = campsites,
vehicles = vehicles,
vessels = vessels,
invoice=self.active_invoice
)

Expand Down Expand Up @@ -1309,7 +1309,7 @@ def vehicle_payment_status(self):
payment_dict.append(data)
else:
pass

print payment_dict
return payment_dict

class BookingHistory(models.Model):
Expand All @@ -1322,7 +1322,7 @@ class BookingHistory(models.Model):
confirmation_sent = models.BooleanField()
campground = models.CharField(max_length=100)
campsites = JSONField()
vehicles = JSONField()
vessels = JSONField()
updated_by = models.ForeignKey(EmailUser,on_delete=models.PROTECT, blank=True, null=True)
invoice=models.ForeignKey(Invoice,null=True,blank=True)

Expand Down Expand Up @@ -1353,9 +1353,10 @@ def active(self):
class BookingVehicleRego(models.Model):
"""docstring for BookingVehicleRego."""
VEHICLE_CHOICES = (
('vehicle','Vehicle'),
('motorbike','Motorcycle'),
('concession','Vehicle (concession)')
# ('vehicle','Vehicle'),
('vessel','Vessel'),
# ('motorbike','Motorcycle'),
# ('concession','Vehicle (concession)')
)

booking = models.ForeignKey(Booking, related_name = "regos")
Expand Down
10 changes: 5 additions & 5 deletions mooring/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ def create_confirmation(confirmation_buffer, booking):


table_data = []
table_data.append([Paragraph('Campground', styles['BoldLeft']), Paragraph('{}, {}'.format(booking.mooringarea.name, booking.mooringarea.park.name), styles['BoldLeft'])])
table_data.append([Paragraph('Mooring', styles['BoldLeft']), Paragraph('{}, {}'.format(booking.mooringarea.name, booking.mooringarea.park.name), styles['BoldLeft'])])
campsite = u'{}'.format(booking.first_campsite.type) if booking.mooringarea.site_type == 2 else u'{} ({})'.format(booking.first_campsite.name, booking.first_campsite.type)
table_data.append([Paragraph('Camp Site', styles['BoldLeft']), Paragraph(campsite, styles['Left'])])
# table_data.append([Paragraph('Camp Site', styles['BoldLeft']), Paragraph(campsite, styles['Left'])])

table_data.append([Paragraph('Dates', styles['BoldLeft']), Paragraph(booking.stay_dates, styles['Left'])])
table_data.append([Paragraph('Number of guests', styles['BoldLeft']), Paragraph(booking.stay_guests, styles['Left'])])
# table_data.append([Paragraph('Number of guests', styles['BoldLeft']), Paragraph(booking.stay_guests, styles['Left'])])
table_data.append([Paragraph('Name', styles['BoldLeft']), Paragraph(u'{} {} ({})'.format(booking.details.get('first_name', ''), booking.details.get('last_name', ''), booking.customer.email if booking.customer else None), styles['Left'])])
table_data.append([Paragraph('Booking confirmation number', styles['BoldLeft']), Paragraph(booking.confirmation_number, styles['Left'])])

Expand All @@ -152,9 +152,9 @@ def create_confirmation(confirmation_buffer, booking):
vehicle_data.append(data)

vehicles = Table(vehicle_data, style=TableStyle([('VALIGN', (0, 0), (-1, -1), 'TOP')]))
table_data.append([Paragraph('Vehicles', styles['BoldLeft']), vehicles])
table_data.append([Paragraph('Vessel', styles['BoldLeft']), vehicles])
else:
table_data.append([Paragraph('Vehicles', styles['BoldLeft']), Paragraph('No vehicles', styles['Left'])])
table_data.append([Paragraph('Vessel', styles['BoldLeft']), Paragraph('No vessel', styles['Left'])])

if booking.mooringarea.additional_info:
table_data.append([Paragraph('Additional confirmation information', styles['BoldLeft']), Paragraph(booking.mooringarea.additional_info, styles['Left'])])
Expand Down
2 changes: 1 addition & 1 deletion mooring/static/parkstay/js/parkstay.js

Large diffs are not rendered by default.

15 changes: 9 additions & 6 deletions mooring/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ def price_or_lineitems(request,booking,campsite_list,lines=True,old_booking=None
raise Exception('A marine park entry Oracle code has not been set for the park that the mooringarea belongs to.')
park_entry_rate = get_park_entry_rate(request,booking.arrival.strftime('%Y-%m-%d'))
vehicle_dict = {
'vessel' : vehicles.filter(entry_fee=True, type='vessel'),
'vehicle': vehicles.filter(entry_fee=True, type='vehicle'),
'motorbike': vehicles.filter(entry_fee=True, type='motorbike'),
'concession': vehicles.filter(entry_fee=True, type='concession')
Expand Down Expand Up @@ -635,16 +636,15 @@ def update_booking(request,old_booking,booking_details):
departure =booking_details['end_date'],
details = new_details,
customer=old_booking.customer,
campground = MooringArea.objects.get(id=booking_details['campground']))
mooringarea = MooringArea.objects.get(id=booking_details['mooringarea']))
# Check that the departure is not less than the arrival
if booking.departure < booking.arrival:
raise Exception('The departure date cannot be before the arrival date')
today = datetime.now().date()
if today > old_booking.departure:
raise ValidationError('You cannot change a booking past the departure date.')

# Check if it is the same campground
if old_booking.campground.id == booking.campground.id:
if old_booking.mooringarea.id == booking.mooringarea.id:
same_campground = True
# Check if dates are the same
if (old_booking.arrival == booking.arrival) and (old_booking.departure == booking.departure):
Expand All @@ -661,7 +661,9 @@ def update_booking(request,old_booking,booking_details):

# Add history
new_history = old_booking._generate_history(user=request.user)

print "BOOKING"
# print old_booking._generate_history()
print new_history
if request.data.get('entryFees').get('regos'):
new_regos = request.data['entryFees'].pop('regos')
sent_regos = [r['rego'] for r in new_regos]
Expand Down Expand Up @@ -704,7 +706,8 @@ def update_booking(request,old_booking,booking_details):
current_regos.delete()

if same_campsites and same_dates and same_vehicles and same_details:
new_history.delete()
if new_history is not None:
new_history.delete()
return old_booking

# Check difference of dates in booking
Expand Down Expand Up @@ -932,5 +935,5 @@ def daterange(start_date, end_date):


def oracle_integration(date,override):
system = '0019'
system = '0516'
oracle_codes = oracle_parser(date,system,'Marinastay',override=override)
3 changes: 2 additions & 1 deletion mooring/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def render_page(self, request, booking, form, vehicles, show_errors=False):
'concession': Decimal('0.00'),
'child': Decimal('0.00'),
'infant': Decimal('0.00'),
'vessel': entry_fees.vessel if entry_fees else Decimal('0.00'),
'vehicle': entry_fees.vehicle if entry_fees else Decimal('0.00'),
'vehicle_conc': entry_fees.concession if entry_fees else Decimal('0.00'),
'motorcycle': entry_fees.motorbike if entry_fees else Decimal('0.00')
Expand Down Expand Up @@ -231,7 +232,7 @@ def post(self, request, *args, **kwargs):
booking.details['num_infant'] = form.cleaned_data.get('num_infant')

# update vehicle registrations from form
VEHICLE_CHOICES = {'0': 'vehicle', '1': 'concession', '2': 'motorbike'}
VEHICLE_CHOICES = {'0': 'vessel', '1': 'concession', '2': 'motorbike'}
BookingVehicleRego.objects.filter(booking=booking).delete()
for vehicle in vehicles:
BookingVehicleRego.objects.create(
Expand Down