Skip to content

Commit

Permalink
Merge 376af7b into 645a4d0
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonc86 committed May 25, 2018
2 parents 645a4d0 + 376af7b commit e9bfa50
Show file tree
Hide file tree
Showing 14 changed files with 164 additions and 33 deletions.
20 changes: 20 additions & 0 deletions ledger/basket/migrations/0013_auto_20180524_1323.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-05-24 05:23
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('basket', '0012_auto_20170920_1618'),
]

operations = [
migrations.AlterField(
model_name='line',
name='price_excl_tax',
field=models.DecimalField(decimal_places=12, max_digits=22, null=True, verbose_name='Price excl. Tax'),
),
]
1 change: 1 addition & 0 deletions ledger/basket/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class Line(CoreAbstractLine):
line_reference = SlugField(_("Line Reference"), max_length=128, db_index=True,blank=True,null=True)
ledger_description = models.TextField(blank=True,null=True)
oracle_code = models.CharField("Oracle Code",max_length=50,null=True,blank=True)
price_excl_tax = models.DecimalField(_('Price excl. Tax'), decimal_places=12, max_digits=22,null=True)


def __str__(self):
Expand Down
4 changes: 2 additions & 2 deletions ledger/checkout/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def validate_id(self, value):
class CheckoutCustomProductSerializer(serializers.Serializer):
ledger_description = serializers.CharField()
quantity = serializers.IntegerField(min_value=1,default=1)
price_excl_tax = serializers.DecimalField(max_digits=8, decimal_places=2, default=0)
price_incl_tax = serializers.DecimalField(max_digits=8, decimal_places=2, default=0)
price_excl_tax = serializers.DecimalField(max_digits=22, decimal_places=12, default=0)
price_incl_tax = serializers.DecimalField(max_digits=12, decimal_places=2, default=0)


class VoucherSerializer(serializers.Serializer):
Expand Down
2 changes: 1 addition & 1 deletion ledger/checkout/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def get_last_check(self):

def calculate_excl_gst(amount):
result = D(100.0)/ D(100 + settings.LEDGER_GST) * D(amount)
return result.quantize(D('0.01'), ROUND_HALF_DOWN)
return result


def createBasket(product_list, owner, system, vouchers=None, force_flush=True):
Expand Down
7 changes: 4 additions & 3 deletions ledger/payments/pdf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os

from io import BytesIO
from oscar.templatetags.currency_filters import currency
from reportlab.lib import enums
from reportlab.lib.pagesizes import A4
from reportlab.platypus import BaseDocTemplate, PageTemplate, Frame, Paragraph, Spacer, Table, TableStyle, ListFlowable, \
Expand Down Expand Up @@ -258,9 +259,9 @@ def _create_invoice(invoice_buffer, invoice):
val,
Paragraph(item.description, s),
item.quantity,
'${}'.format(item.unit_price_excl_tax),
'${}'.format(item.line_price_before_discounts_incl_tax-item.line_price_before_discounts_excl_tax),
'${}'.format(item.line_price_before_discounts_incl_tax)
currency(item.unit_price_excl_tax),
currency(item.line_price_before_discounts_incl_tax-item.line_price_before_discounts_excl_tax),
currency(item.line_price_before_discounts_incl_tax)
]
)
val += 1
Expand Down
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
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.

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 e9bfa50

Please sign in to comment.