Skip to content

Commit

Permalink
Merge daea039 into 645a4d0
Browse files Browse the repository at this point in the history
  • Loading branch information
FatemehMoghadam authored May 25, 2018
2 parents 645a4d0 + daea039 commit db31724
Show file tree
Hide file tree
Showing 11 changed files with 170 additions and 45 deletions.
6 changes: 4 additions & 2 deletions parkstay/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1621,6 +1621,8 @@ def list(self, request, *args, **kwargs):
bk['lastname'] = booking.details.get('last_name','')
if booking.override_reason:
bk['override_reason'] = booking.override_reason.text
if booking.override_price:
discount = booking.discount
if not booking.paid:
bk['payment_callback_url'] = '/api/booking/{}/payment_callback.json'.format(booking.id)
if booking.customer:
Expand Down Expand Up @@ -1743,7 +1745,7 @@ def create(self, request, format=None):
def update(self, request, *args, **kwargs):
try:
http_status = status.HTTP_200_OK

instance = self.get_object()
start_date = datetime.strptime(request.data['arrival'],'%d/%m/%Y').date()
end_date = datetime.strptime(request.data['departure'],'%d/%m/%Y').date()
Expand Down Expand Up @@ -1875,7 +1877,7 @@ def booking_checkout_status(self, request, *args, **kwargs):

@detail_route(methods=['GET'])
def history(self, request, *args, **kwargs):
http_status = status.HTTP_200_OK
http_status = status.HTTP_200_OK
try:
history = self.get_object().history.all()
data = BookingHistorySerializer(history,many=True).data
Expand Down
40 changes: 33 additions & 7 deletions parkstay/frontend/parkstay/src/components/booking/addbooking.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,20 @@
<div class="col-sm-12">
<div v-show="booking.campsites.length > 0" >
<div class="column table-scroll">
<table class="hover table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%" name="campsite" v-model="selected_campsite">
<table class="hover table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%" name="campsite" v-model="selected_campsite">
<thead>
<tr>
<th class="site">Campsite</th>
<th class="numBook">Sites to book</th>
<th class="form-group">Campsite</th>
<th >Sites to book
<input class="checkbox" type="checkbox" v-model="selected_campsite" @click="selectAll">
</th>
</tr>
</thead>
<tbody><template v-for="campsite in booking.campsites">
<tr>
<td class="site"> {{campsite.name}} - {{campsite.type}}</td>
<td class="numBook">
<input type="checkbox" v-model="campsite.is_selected" @change="updatePrices()">
<td class="form-group"> {{campsite.name}} - {{campsite.type}}</td>
<td>
<input class="checkbox" type="checkbox" :value="campsite.id" v-model="campsite.is_selected" @change="updatePrices()">
</td>
</tr></template>
</tbody>
Expand Down Expand Up @@ -121,7 +123,7 @@
</thead>
<tbody><template v-for="c in booking.campsite_classes">
<tr>
<td class="site"> {{c.name}} <span v-if="c.class"> - {{ classes[c.class] }}</span></td>
<td class="site"> {{c.name}} </td>
<td class="book"> {{ c.campsites.length }} available </td>
<td class="numBook">
<input type="number" min="1" v-bind:max="c.campsites.length" name="campsite-type" class="form-control" v-model="c.selected_campsite_class" @change="updatePrices()">
Expand Down Expand Up @@ -557,6 +559,30 @@ export default {
}
},
methods:{
selectAll: function() {
//let vm = this;
this.is_selected=[];
this.booking.campsites.forEach((el) => {
this.is_selected.push(el.id)
})
// for (var campsite in this.booking.campsites){
// this.is_selected.push(this.booking.campsites[campsite].id);
// }
// var results = [];
// if (vm.booking_type == vm.booking_types.CAMPSITE) {
// return vm.booking.campsites.forEach(function(el){
// for (var i in el.selected_campsite) {
// results.push(el.is_selected);
// }
// });
// return results;
// }
},
fetchSites:function () {
let vm =this;
if (vm.booking_type == vm.booking_types.CAMPSITE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ export default {
arrivalPicker: {},
departurePicker: {},
campsite_classes: [],
selected_campsite: '',
selected_campsite: [],
booking_type: "campsite",
initialised: false,
fetchingSites: false,
Expand Down Expand Up @@ -397,6 +397,7 @@ export default {
updatePrices: function() {
let vm = this;
var campsite_ids = vm.selected_campsite;
console.log(vm.selected_campsite)
vm.booking.price = 0;
if (vm.selected_campsite) {
if (vm.booking.arrival && vm.booking.departure) {
Expand Down
18 changes: 17 additions & 1 deletion parkstay/frontend/parkstay/src/components/booking/history.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<span><strong>Campground</strong> : {{booking.campground_name}}</span>
</div>
<div class="col-sm-8">
<span><strong>Camp Site (Type)</strong> : {{booking.campground_site_type}}</span>
<label>Camp Site (Type): {{CampSiteType}} </label>
</div>
</div>
<div class="row" style="margin-top:10px;">
Expand Down Expand Up @@ -194,6 +194,22 @@ export default {
}
},
computed: {
CampSiteType: function(){
var results = {};
for (var i = 0; i < this.booking.campground_site_type.length; i++) {
if (results[this.booking.campground_site_type[i].type] == undefined) {
results[this.booking.campground_site_type[i].type] = 0;
}
results[this.booking.campground_site_type[i].type] += 1;
}
var resultList = [];
for (var index in results) {
resultList.push(`${results[index]}x ${index}`);
}
var resultString = resultList.join(", ");
return resultString;
}
},
watch:{
booking_id(){
Expand Down
20 changes: 20 additions & 0 deletions parkstay/migrations/0048_auto_20180429_1556.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-04-29 07:56
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('parkstay', '0047_auto_20180322_1618'),
]

operations = [
migrations.AlterField(
model_name='booking',
name='override_price',
field=models.DecimalField(decimal_places=2, default='0.00', max_digits=8),
),
]
25 changes: 25 additions & 0 deletions parkstay/migrations/0049_auto_20180517_1405.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.8 on 2018-05-17 06:05
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('parkstay', '0048_auto_20180429_1556'),
]

operations = [
migrations.AddField(
model_name='bookinghistory',
name='override_price',
field=models.DecimalField(blank=True, decimal_places=2, max_digits=8, null=True),
),
migrations.AlterField(
model_name='booking',
name='override_price',
field=models.DecimalField(blank=True, decimal_places=2, max_digits=8, null=True),
),
]
19 changes: 19 additions & 0 deletions parkstay/migrations/0050_remove_bookinghistory_override_price.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.8 on 2018-05-17 07:24
from __future__ import unicode_literals

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('parkstay', '0049_auto_20180517_1405'),
]

operations = [
migrations.RemoveField(
model_name='bookinghistory',
name='override_price',
),
]
29 changes: 23 additions & 6 deletions parkstay/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,10 @@ def first_campsite_list(self):
for item in cbs:
first_campsite_list.append(item.campsite)
return first_campsite_list

@property
def discount(self):
return (self.cost_total - self.override_price)

@property
def editable(self):
Expand Down Expand Up @@ -1085,12 +1089,25 @@ def __check_payment_status(self):

if amount == 0:
return 'unpaid'
if self.cost_total < amount:
return 'over_paid'
elif self.cost_total > amount:
return 'partially_paid'
else:return "paid"

# if self.cost_total < amount:
# return 'over_paid'
# elif self.cost_total > amount:
# return 'partially_paid'
# else:return "paid"

if self.override_price:
if self.override_price < amount:
return 'over_paid'
elif self.override_price > amount:
return 'partially_paid'
else:return "paid"
else:
if self.cost_total < amount:
return 'over_paid'
elif self.cost_total > amount:
return 'partially_paid'
else:return "paid"

def __check_refund_status(self):
invoices = []
amount = D('0.0')
Expand Down
2 changes: 1 addition & 1 deletion parkstay/static/parkstay/js/parkstay.js

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions parkstay/static/parkstay/js/vendor.js

Large diffs are not rendered by default.

19 changes: 9 additions & 10 deletions parkstay/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ def create_booking_by_site(sites_qs, start_date, end_date, num_adult=0, num_conc
raise ValidationError('Number of people is less than the minimum allowed for the selected campsite(s)')

# Create a new temporary booking with an expiry timestamp (default 20mins)
updated_cost_total = cost_total
if override_price is not None:
updated_cost_total = cost_total - override_price
# updated_cost_total = cost_total
# if override_price is not None:
# updated_cost_total = cost_total - override_price

booking = Booking.objects.create(
booking_type=3,
Expand All @@ -140,8 +140,8 @@ def create_booking_by_site(sites_qs, start_date, end_date, num_adult=0, num_conc
'num_child': num_child,
'num_infant': num_infant
},
cost_total = updated_cost_total,
override_price = Decimal(override_price) if (override_price is not None) else 0,
cost_total = cost_total,
override_price = Decimal(override_price) if (override_price is not None) else None,
override_reason = override_reason,
overridden_by = overridden_by,
expiry_time=timezone.now()+timedelta(seconds=settings.BOOKING_TIMEOUT),
Expand All @@ -156,7 +156,7 @@ def create_booking_by_site(sites_qs, start_date, end_date, num_adult=0, num_conc
date=start_date+timedelta(days=i),
booking=booking
)

# On success, return the temporary booking
return booking

Expand Down Expand Up @@ -216,7 +216,6 @@ def get_campsite_availability(campsites_qs, start_date, end_date):
# prefill all slots as 'open'
duration = (end_date-start_date).days
results = {site.pk: {start_date+timedelta(days=i): ['open', ] for i in range(duration)} for site in campsites_qs}

# strike out existing bookings
for b in bookings_qs:
results[b.campsite.pk][b.date][0] = 'closed' if b.booking_type == 2 else 'booked'
Expand Down Expand Up @@ -564,17 +563,16 @@ def price_or_lineitems(request,booking,campsite_list,lines=True,old_booking=None
price = Decimal(park_entry_rate[k]) * v.count()
total_price += price

# Override price if required
# Create line item for Override price
if booking.override_price is not None:
if booking.override_reason is not None:
reason = booking.override_reason
invoice_lines.append({
'ledger_description': '{}'.format(reason.text),
'quantity': 1,
'price_incl_tax': str(total_price - booking.override_price),
'price_incl_tax': str(total_price - booking.discount),
'oracle_code': booking.campground.oracle_code
})
total_price = booking.override_price

if lines:
return invoice_lines
Expand Down Expand Up @@ -619,6 +617,7 @@ def create_temp_bookingupdate(request,arrival,departure,booking_details,old_book
num_infant= booking_details['num_infant'],
cost_total = total_price,
customer = old_booking.customer,
override_price=old_booking.override_price,
updating_booking = True
)
# Move all the vehicles to the new booking
Expand Down

0 comments on commit db31724

Please sign in to comment.