Skip to content

Commit

Permalink
Merge 7cf2c57 into a25f040
Browse files Browse the repository at this point in the history
  • Loading branch information
xzzy committed Oct 4, 2019
2 parents a25f040 + 7cf2c57 commit 4ae61e2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
26 changes: 18 additions & 8 deletions mooring/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4437,8 +4437,14 @@ def post(self, request, *args, **kwargs):
#new_invoice = Invoice.objects.get(order_number=order.number)

for bp_txn in bpoint_trans_split_json:
bpoint_id = BpointTransaction.objects.get(txn_number=bp_txn['txn_number'])
info = {'amount': Decimal('{:.2f}'.format(float(bp_txn['line-amount']))), 'details' : 'Refund via system'}
bpoint_id = None
try:
bpoint_id = BpointTransaction.objects.get(txn_number=bp_txn['txn_number'])
info = {'amount': Decimal('{:.2f}'.format(float(bp_txn['line-amount']))), 'details' : 'Refund via system'}
except Exception as e:
print (e)
info = {'amount': Decimal('{:.2f}'.format('0.00')), 'details' : 'Refund via system'}

refund = None
lines = []
if info['amount'] > 0:
Expand All @@ -4452,18 +4458,22 @@ def post(self, request, *args, **kwargs):
lines.append({'ledger_description':str("Payment Gateway Refund to "+bp_txn['txn_number']),"quantity":1,"price_incl_tax": bpoint_money_to,"oracle_code":str(settings.UNALLOCATED_ORACLE_CODE), 'line_status': 3})
bpoint = BpointTransaction.objects.get(txn_number=bp_txn['txn_number'])
refund = bpoint.refund(info,request.user)
except:
except Exception as e:
print (e)
failed_refund = True
bpoint_failed_amount = Decimal(bp_txn['line-amount'])
lines = []
lines.append({'ledger_description':str("Refund failed for txn "+bp_txn['txn_number']),"quantity":1,"price_incl_tax":bpoint_failed_amount,"oracle_code":str(settings.UNALLOCATED_ORACLE_CODE), 'line_status': 1})
order = utils.allocate_refund_to_invoice(request, booking, lines, invoice_text=None, internal=False, order_total='0.00',user=booking.customer)
new_invoice = Invoice.objects.get(order_number=order.number)
bpoint_refund = BpointTransaction.objects.get(txn_number=refund)
bpoint_refund.crn1 = new_invoice.reference
bpoint_refund.save()
update_payments(new_invoice.reference)


if refund:
bpoint_refund = BpointTransaction.objects.get(txn_number=refund.txn_number)
bpoint_refund.crn1 = new_invoice.reference
bpoint_refund.save()
new_invoice.settlement_date = None
new_invoice.save()
update_payments(new_invoice.reference)

else:
lines = []
Expand Down
9 changes: 6 additions & 3 deletions mooring/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def post(self, request, *args, **kwargs):

new_order = Order.objects.get(basket=basket)
new_invoice = Invoice.objects.get(order_number=new_order.number)
update_payments(new_invoice.reference)
#update_payments(new_invoice.reference)
book_inv, created = BookingInvoice.objects.get_or_create(booking=booking, invoice_reference=new_invoice.reference)

#basket.status = 'Submitted'
Expand Down Expand Up @@ -397,8 +397,8 @@ def post(self, request, *args, **kwargs):
bpoint_refund = BpointTransaction.objects.get(txn_number=refund)
bpoint_refund.crn1 = new_invoice.reference
bpoint_refund.save()
update_payments(invoice.reference)
update_payments(new_invoice.reference)
update_payments(invoice.reference)
update_payments(new_invoice.reference)

invoice.voided = True
invoice.save()
Expand All @@ -414,6 +414,9 @@ def post(self, request, *args, **kwargs):
booking_admission.canceled_by = request.user
booking_admission.save()

update_payments(invoice.reference)
update_payments(new_invoice.reference)

if failed_refund is True:
# Refund Failed Assign Refund amount to allocation pool.
lines = [{'ledger_description':'Refund assigned to unallocated pool',"quantity":1,"price_incl_tax":abs(info['amount']),"oracle_code":settings.UNALLOCATED_ORACLE_CODE, 'line_status': 1}]
Expand Down

0 comments on commit 4ae61e2

Please sign in to comment.