Skip to content

Commit

Permalink
Merge e17d226 into a25f040
Browse files Browse the repository at this point in the history
  • Loading branch information
xzzy committed Oct 4, 2019
2 parents a25f040 + e17d226 commit 1eeb7d3
Show file tree
Hide file tree
Showing 6 changed files with 136 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
2 changes: 2 additions & 0 deletions mooring/emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def sendHtmlEmail(to,subject,context,template,cc,bcc,from_email,template_group,a
# Main Email Template Style ( body template is populated in the center
if template_group == 'rottnest':
main_template = get_template('mooring/email/base_email-rottnest.html').render(Context(context))
elif template_group == 'system-oim':
main_template = get_template('mooring/email/base_email-oim.html').render(Context(context))
else:
main_template = get_template('mooring/email/base_email2.html').render(Context(context))

Expand Down
64 changes: 64 additions & 0 deletions mooring/management/commands/check_oracle_bpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from django.core.management.base import BaseCommand
from django.utils import timezone
from mooring.models import GlobalSettings, MooringAreaGroup
from ledger.payments.bpoint.models import BpointTransaction, BpointToken
from ledger.payments.models import Invoice,OracleInterface,CashTransaction
from oscar.apps.order.models import Order
from django.core.exceptions import ValidationError
from django.conf import settings
from decimal import *
from mooring.emails import sendHtmlEmail
import json

from datetime import timedelta, datetime

class Command(BaseCommand):
help = 'Check BPOINT Settlement dates with oracle Invoice Settlement dates to ensure totals match.'

def handle(self, *args, **options):
bpoint_total = Decimal('0.00')
oracle_total = Decimal('0.00')
invoice_total = Decimal('0.00')
today = datetime.today()# - timedelta(days=3)
system = settings.PS_PAYMENT_SYSTEM_ID
system = system.replace('S','0')
print (system)
try:
print ("Calculation Bpoint Transaction Total")
bpoint_trans = BpointTransaction.objects.filter(settlement_date=today, crn1__istartswith=system)
for i in bpoint_trans:
if i.action == 'payment':
bpoint_total = bpoint_total + Decimal(i.amount)
if i.action == 'refund':
bpoint_total = bpoint_total - Decimal(i.amount)


print (bpoint_total)
print ("Calculation Invoice Settlemnt Oracle Totals")

invoices = Invoice.objects.filter(settlement_date=today)
for i in invoices:
#print (i.reference)
invoice_total = invoice_total + Decimal(i.amount)
#print (i.order)
for ol in Order.objects.get(number=i.order_number).lines.all():
for order_total in ol.payment_details['order']:
oracle_total = oracle_total + Decimal(ol.payment_details['order'][order_total])
#print (Decimal(ol.payment_details['order'][order_total]))
#print (oracle_total)
print ("ORACLE TOTAL")
print (oracle_total)
print (invoice_total)

if bpoint_total != oracle_total:
raise ValidationError("Bpoint and Oracle Totals do not match. Bpoint Total: "+str(oracle_total)+" Oracle Total: "+str(invoice_total))
except Exception as e:
print ("Error: Sending Email Notification: "+settings.NOTIFICATION_EMAIL)
context = {
'error_report' : str(e)
}

sendHtmlEmail([settings.NOTIFICATION_EMAIL],"[MOORING] oracle and bpoint total mistatch",context,'mooring/email/oracle_bpoint.html',None,None,settings.EMAIL_FROM,'system-oim',attachments=None)



Loading

0 comments on commit 1eeb7d3

Please sign in to comment.