Skip to content

Commit

Permalink
Merge pull request #237 from rayrayndwiga/parkstay_rebase
Browse files Browse the repository at this point in the history
Parkstay rebase: Last changes before go live
  • Loading branch information
dbca-asi committed Oct 20, 2017
2 parents 9e37604 + 6c0d676 commit ed4e425
Show file tree
Hide file tree
Showing 21 changed files with 126 additions and 92 deletions.
2 changes: 1 addition & 1 deletion ledger/payments/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class OracleParserAdmin(admin.ModelAdmin):

@admin.register(models.OracleInterface)
class OracleInterfaceAdmin(admin.ModelAdmin):
list_display = ['activity_name','amount','status','receipt_date']
list_display = ['activity_name','amount','status','receipt_number','receipt_date']

class OracleInterfaceRecipientInline(admin.TabularInline):
model = models.OracleInterfaceRecipient
Expand Down
6 changes: 6 additions & 0 deletions ledger/payments/invoice/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ def payment_amount(self):
'''
return self.__calculate_bpay_payments() + self.__calculate_bpoint_payments() + self.__calculate_cash_payments() - self.__calculate_total_refunds()

@property
def total_payment(self):
''' Total amount paid from bpay,bpoint and cash.
'''
return self.__calculate_bpay_payments() + self.__calculate_bpoint_payments() + self.__calculate_cash_payments()

@property
def refund_amount(self):
return self.__calculate_total_refunds()
Expand Down
2 changes: 1 addition & 1 deletion ledger/payments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class OracleParserInvoice(models.Model):
def increment_receipt_number():
last_interface = OracleInterface.objects.all().order_by('id').last()
if not last_interface:
return 80000
return settings.ORACLE_IMPORT_SEQUENCE
receipt_no = last_interface.receipt_number
new_receipt_no = receipt_no + 1
return new_receipt_no
Expand Down
26 changes: 15 additions & 11 deletions ledger/payments/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,22 +378,25 @@ def generate_trans_csv(system,start,end,region=None,district=None):
bpay = i.bpay_transactions.filter(p_date__gte=start, p_date__lte=end)
# Write out the cash transactions
for c in cash:
cash_info = {
'Created': c.created.strftime('%Y-%m-%d'),
'Payment Method': 'Cash',
'Transaction Type': c.type.lower(),
'Amount': c.amount,
'Approved': 'True',
'Source': c.source,
'Product Names': item_names,
'Product Codes': oracle_codes
}
writer.writerow(cash_info)
if c.type not in ['move_in','move_out']:
cash_info = {
'Created': c.created.strftime('%Y-%m-%d'),
'Invoice': c.invoice.reference,
'Payment Method': 'Cash',
'Transaction Type': c.type.lower(),
'Amount': c.amount,
'Approved': 'True',
'Source': c.source,
'Product Names': item_names,
'Product Codes': oracle_codes
}
writer.writerow(cash_info)
if not district:
# Write out all bpay transactions
for b in bpay:
bpay_info = {
'Created': b.created.strftime('%Y-%m-%d'),
'Invoice': b.crn,
'Payment Method': 'BPAY',
'Transaction Type': b.get_p_instruction_code_display(),
'Amount': b.amount,
Expand All @@ -407,6 +410,7 @@ def generate_trans_csv(system,start,end,region=None,district=None):
for bpt in bpoint:
bpoint_info = {
'Created': bpt.created.strftime('%Y-%m-%d'),
'Invoice': bpt.crn1,
'Payment Method': 'BPOINT',
'Transaction Type': bpt.action.lower(),
'Amount': bpt.amount,
Expand Down
59 changes: 27 additions & 32 deletions ledger/payments/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,16 +251,18 @@ def sendInterfaceParserEmail(trans_date,oracle_codes,system_name,system_id,error
print(traceback.print_exc())
raise e

def addToInterface(date,oracle_codes,system):
def addToInterface(date,oracle_codes,system,override):
try:
dt = datetime.datetime.strptime(date,'%Y-%m-%d')
trans_date = datetime.datetime.strptime(date,'%Y-%m-%d')#.strftime('%d/%m/%Y')
today = datetime.datetime.now().strftime('%Y-%m-%d')
oracle_date = '{}-{}'.format(dt.strftime('%B').upper(),dt.strftime('%y'))
try:
OracleOpenPeriod.objects.get(period_name=oracle_date)
except OracleOpenPeriod.DoesNotExist:
raise ValidationError('There is currently no open period for transactions done on {}'.format(trans_date))
new_codes = {}
if not override:
try:
OracleOpenPeriod.objects.get(period_name=oracle_date)
except OracleOpenPeriod.DoesNotExist:
raise ValidationError('There is currently no open period for transactions done on {}'.format(trans_date))

# Check if the system deducts a percentage and sends to another oracle account code
if system.deduct_percentage and ( not system.percentage or not system.percentage_account_code):
Expand All @@ -276,13 +278,14 @@ def addToInterface(date,oracle_codes,system):
deduction_code = OracleInterface(
receipt_date = trans_date,
activity_name = system.percentage_account_code,
amount = initial_amount - remainder_amount,
amount = D(0.0),
customer_name = system.system_name,
description = k,
comments = '{} GST/{}'.format(k,date),
description = system.percentage_account_code,
comments = '{} GST/{}'.format(system.percentage_account_code,date),
status = 'NEW',
status_date = today
)
deduction_code.save()
for k,v in oracle_codes.items():
if v != 0:
found = OracleAccountCode.objects.filter(active_receivables_activities=k)
Expand All @@ -291,20 +294,9 @@ def addToInterface(date,oracle_codes,system):

if system.deduct_percentage:
initial_amount = D(v)
remainder_amount = ((100 - system.percentage)/ 100) * initial_amount
remainder_amount = ((100 - system.percentage)/ D(100)) * initial_amount

deduction_code.amount += initial_amount - remainder_amount
# Add the deducted amount to the oracle code specified in the system table
OracleInterface.objects.create(
receipt_date = trans_date,
activity_name = system.percentage_account_code,
amount = initial_amount - remainder_amount,
customer_name = system.system_name,
description = k,
comments = '{} GST/{}'.format(k,date),
status = 'NEW',
status_date = today
)
# Add the remainaing amount to the intial oracle account code
OracleInterface.objects.create(
receipt_date = trans_date,
Expand All @@ -316,7 +308,7 @@ def addToInterface(date,oracle_codes,system):
status = 'NEW',
status_date = today
)

new_codes[k] = remainder_amount
else:
OracleInterface.objects.create(
receipt_date = trans_date,
Expand All @@ -328,11 +320,14 @@ def addToInterface(date,oracle_codes,system):
status = 'NEW',
status_date = today
)
if system.deduct_percentage:
new_codes[k] = remainder_amount
if system.deduct_percentage and deduction_code.amount > 0:
deduction_code.save()
new_codes[deduction_code.activity_name] = deduction_code.amount
return new_codes
except:
raise
def oracle_parser(date,system,system_name):
def oracle_parser(date,system,system_name,override=False):
invoices = []
invoice_list = []
oracle_codes = {}
Expand Down Expand Up @@ -453,9 +448,9 @@ def oracle_parser(date,system,system_name):
if can_add:
OracleParserInvoice.objects.create(reference=k,details=json.dumps(v),parser=op)
# Add items to oracle interface table
addToInterface(date,oracle_codes,ois)
new_codes = addToInterface(date,oracle_codes,ois,override)
# Send an email with all the activity codes entered into the interface table
sendInterfaceParserEmail(date,oracle_codes,system_name,system)
sendInterfaceParserEmail(date,new_codes,system_name,system)
return oracle_codes
except Exception as e:
error = traceback.format_exc()
Expand Down Expand Up @@ -650,23 +645,23 @@ def update_payments(invoice_reference):
refunded += new_amount
line.save()
# Check if the whole amount paid on the invoice has been allocated otherwise add to the first line item
if i.payment_amount > paid:
if i.total_payment_amount > paid:
first_item = i.order.lines.first()
# Bpoint
for b in bpoint:
for b in bpoint_transactions:
if b.payment_allocated < b.amount:
if first_item.payment_details['card'].get(str(b.id)):
D(first_item.payment_details['card'][str(b.id)]) + (b.amount - b.payment_allocated)
first_item.payment_details['card'][str(b.id)] = str(D(first_item.payment_details['card'][str(b.id)]) + (b.amount - b.payment_allocated))
# Bpay
for b in bpay:
for b in bpay_transactions:
if b.payment_allocated < b.amount:
if first_item.payment_details['bpay'].get(str(b.id)):
D(first_item.payment_details['bpay'][str(b.id)]) + (b.amount - b.payment_allocated)
first_item.payment_details['card'][str(b.id)] = str(D(first_item.payment_details['bpay'][str(b.id)]) + (b.amount - b.payment_allocated))
# Cash
for b in cash:
for b in cash_transactions.all():
if b.payment_allocated < b.amount:
if first_item.payment_details['cash'].get(str(b.id)):
D(first_item.payment_details['cash'][str(b.id)]) + (b.amount - b.payment_allocated)
first_item.payment_details['card'][str(b.id)] = str(D(first_item.payment_details['cash'][str(b.id)]) + (b.amount - b.payment_allocated))
first_item.save()
except:
print(traceback.print_exc())
Expand Down
1 change: 1 addition & 0 deletions ledger/settings_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,4 @@
}
)
OSCAR_DEFAULT_CURRENCY = 'AUD'
ORACLE_IMPORT_SEQUENCE = env('ORACLE_IMPORT_SEQUENCE',70000)
2 changes: 1 addition & 1 deletion parkstay/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class BookingAdmin(admin.ModelAdmin):
list_display = ('arrival','departure','campground','legacy_id','legacy_name','cost_total')
ordering = ('-arrival',)
search_fileds = ('arrival','departure')
list_filter = ('arrival','departure')
list_filter = ('arrival','departure','campground')
inlines = [BookingInvoiceInline,CampsiteBookingInline]

def has_add_permission(self, request, obj=None):
Expand Down
21 changes: 14 additions & 7 deletions parkstay/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1506,12 +1506,13 @@ def list(self, request, *args, **kwargs):
sql = sql+" and "+ sqlRegion
sqlCount = sqlCount +" and "+ sqlRegion
if arrival:
sqlArrival= ' parkstay_booking.arrival >= \'{}\''.format(arrival)
sqlArrival= ' parkstay_booking.departure > \'{}\''.format(arrival)
sqlCount = sqlCount + " and "+ sqlArrival
sql = sql + " and "+ sqlArrival
if departure:
sql += ' and parkstay_booking.departure <= \'{}\''.format(departure)
sqlCount += ' and parkstay_booking.departure <= \'{}\''.format(departure)
if departure:
sqlDeparture = ' parkstay_booking.arrival <= \'{}\''.format(departure)
sqlCount = sqlCount + ' and ' + sqlDeparture
sql = sql + ' and ' + sqlDeparture
# Search for cancelled bookings
sql += ' and parkstay_booking.is_canceled = \'{}\''.format(canceled)
sqlCount += ' and parkstay_booking.is_canceled = \'{}\''.format(canceled)
Expand Down Expand Up @@ -1568,7 +1569,12 @@ def list(self, request, *args, **kwargs):
bk['lastname'] = booking.details.get('last_name','')
if booking.customer:
bk['email'] = booking.customer.email if booking.customer and booking.customer.email else ""
bk['phone'] = booking.customer.mobile_number if booking.customer and booking.customer.mobile_number else ""
if booking.customer.phone_number:
bk['phone'] = booking.customer.phone_number
elif booking.customer.mobile_number:
bk['phone'] = booking.customer.mobile_number
else:
bk['phone'] = ''
if booking.is_canceled:
bk['campground_site_type'] = ""
else:
Expand Down Expand Up @@ -2064,11 +2070,12 @@ class OracleJob(views.APIView):
def get(self, request, format=None):
try:
data = {
"date":request.GET.get("date")
"date":request.GET.get("date"),
"override": request.GET.get("override")
}
serializer = OracleSerializer(data=data)
serializer.is_valid(raise_exception=True)
utils.oracle_integration(serializer.validated_data['date'].strftime('%Y-%m-%d'))
utils.oracle_integration(serializer.validated_data['date'].strftime('%Y-%m-%d'),serializer.validated_data['override'])
data = {'successful':True}
return Response(data)
except serializers.ValidationError:
Expand Down
2 changes: 1 addition & 1 deletion parkstay/cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def do(self):
outstanding_bookings()

class OracleIntegrationCronJob(CronJobBase):
RUN_AT_TIMES = ['05:00']
RUN_AT_TIMES = ['01:00']

schedule = Schedule(run_at_times=RUN_AT_TIMES)
code = 'parkstay.oracle_integration'
Expand Down
2 changes: 1 addition & 1 deletion parkstay/emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def send_booking_invoice(booking):

def send_booking_confirmation(booking,request):
email_obj = TemplateEmailBase()
email_obj.subject = 'Your booking REF {} at {},{} is confirmed'.format(booking.confirmation_number,booking.campground.name,booking.campground.park.name)
email_obj.subject = 'Your booking {} at {} is confirmed'.format(booking.confirmation_number,booking.campground.name)
email_obj.html_template = 'ps/email/confirmation.html'
email_obj.txt_template = 'ps/email/confirmation.txt'

Expand Down
2 changes: 1 addition & 1 deletion parkstay/frontend/availability/src/availability.vue
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
<select name="gear_type" v-model="gearType" @change="update()">
<option value="tent" v-if="gearTotals.tent">Tent</option>
<option value="campervan" v-if="gearTotals.campervan">Campervan</option>
<option value="caravan" v-if="gearTotals.caravan">Caravan</option>
<option value="caravan" v-if="gearTotals.caravan">Caravan / Camper trailer</option>
</select>
</label>
</div>
Expand Down
12 changes: 6 additions & 6 deletions parkstay/frontend/exploreparks/src/parkfinder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@
<div class="small-12 medium-12 large-12 columns">
<label>Equipment</label>
</div>
<div class="small-12 medium-12 large-3 columns">
<div class="small-12 medium-12 large-4 columns">
<label><input type="radio" name="gear_type" value="all" v-model="gearType" class="show-for-sr" v-on:change="reload()"/><i class="symb RC3"></i> All types</label>
</div>
<div class="small-12 medium-12 large-3 columns">
<div class="small-12 medium-12 large-4 columns">
<label><input type="radio" name="gear_type" value="tent" v-model="gearType" class="show-for-sr" v-on:change="reload()"/><i class="symb RC2"></i> Tent</label>
</div>
<div class="small-12 medium-12 large-3 columns">
<div class="small-12 medium-12 large-4 columns">
<label><input type="radio" name="gear_type" value="campervan" v-model="gearType" class="show-for-sr" v-on:change="reload()"/><i class="symb RV10"></i> Campervan</label>
</div>
<div class="small-12 medium-12 large-3 columns">
<label><input type="radio" name="gear_type" value="caravan" v-model="gearType" class="show-for-sr" v-on:change="reload()"/><i class="symb RC4"></i> Caravan</label>
<div class="small-12 medium-12 large-5 columns">
<label><input type="radio" name="gear_type" value="caravan" v-model="gearType" class="show-for-sr" v-on:change="reload()"/><i class="symb RC4"></i> Caravan / Camper trailer</label>
</div>
</div><div class="row"><div class="small-12 columns">
<hr class="search"/>
Expand Down Expand Up @@ -453,7 +453,7 @@ export default {
el: '#parkfinder',
data: function () {
return {
parkstayUrl: global.parkstayUrl || process.env.PARKSTAY_URL,
parkstayUrl: process.env.PARKSTAY_URL || global.parkstayUrl,
defaultCenter: [13775786.985667605, -2871569.067879858], // [123.75, -24.966],
defaultLayers: [
['dpaw:mapbox_outdoors', {}],
Expand Down
Loading

0 comments on commit ed4e425

Please sign in to comment.