| Line 4619... |
Line 4619... |
| 4619 |
'''
|
4619 |
'''
|
| 4620 |
except MultipleResultsFound:
|
4620 |
except MultipleResultsFound:
|
| 4621 |
unprocessed_awbs[awb] = "Multiple orders were found for the given AWB:" + awb
|
4621 |
unprocessed_awbs[awb] = "Multiple orders were found for the given AWB:" + awb
|
| 4622 |
continue
|
4622 |
continue
|
| 4623 |
'''
|
4623 |
'''
|
| 4624 |
if len(orders) ==1:
|
4624 |
order = orders[0]
|
| - |
|
4625 |
|
| - |
|
4626 |
if order.cod_reconciliation_timestamp:
|
| - |
|
4627 |
#This order has been processed already! This may be a re-run. Let's allow other orders to be processed.
|
| 4625 |
order = orders[0]
|
4628 |
continue
|
| 4626 |
|
4629 |
|
| 4627 |
if order.cod_reconciliation_timestamp:
|
- |
|
| 4628 |
#This order has been processed already! This may be a re-run. Let's allow other orders to be processed.
|
- |
|
| 4629 |
continue
|
- |
|
| 4630 |
|
- |
|
| 4631 |
if order.status < OrderStatus.DELIVERY_SUCCESS:
|
4630 |
if order.status < OrderStatus.DELIVERY_SUCCESS:
|
| 4632 |
#Order has not been delivered yet. No way we can receive the payment.
|
4631 |
#Order has not been delivered yet. No way we can receive the payment.
|
| 4633 |
unprocessed_awbs[awb] = "Payment has been received for order: " + str(order.id) + " before delivery reconciliation"
|
4632 |
unprocessed_awbs[awb] = "Payment has been received for order: " + str(order.id) + " before it has been delivered"
|
| 4634 |
continue
|
- |
|
| 4635 |
|
- |
|
| 4636 |
##As per ticket #743 if amount difference less than 0.5 we should reconcile
|
- |
|
| 4637 |
if abs(amount - order.net_payable_amount) > 0.5:
|
- |
|
| 4638 |
#Received amount is less than or more than the order amount. Mustn't let the user proceed.
|
- |
|
| 4639 |
unprocessed_awbs[awb] = "Payment of Rs. " + str(amount) + " has been received against the total value of Rs. " + str(order.net_payable_amount) + " for order: " + str(order.id)
|
- |
|
| 4640 |
continue
|
- |
|
| 4641 |
|
- |
|
| 4642 |
try:
|
- |
|
| 4643 |
payment_client = PaymentClient().get_client()
|
- |
|
| 4644 |
payment_client.partiallyCapturePayment(order.transaction.id, amount, xferBy, xferTxnId, xferDate)
|
- |
|
| 4645 |
except Exception:
|
- |
|
| 4646 |
unprocessed_awbs[awb] = "We were unable to partially capture payment for order id " + str(order.id) + ", AWB: " + awb
|
- |
|
| 4647 |
continue
|
4633 |
continue
|
| 4648 |
|
- |
|
| 4649 |
#Payment has been recorded now. We can update the order peacefully.
|
- |
|
| 4650 |
remittance = CodCourierPaymentRemittance()
|
- |
|
| 4651 |
remittance.airwayBillNo = awb
|
- |
|
| 4652 |
remittance.collectionReference = xferTxnId
|
- |
|
| 4653 |
remittance.amount = amount
|
- |
|
| 4654 |
remittance.settledAt = to_py_date(xferDate)
|
- |
|
| 4655 |
remittance.provider_id = order.logistics_provider_id
|
- |
|
| 4656 |
order.cod_reconciliation_timestamp = datetime.datetime.now()
|
- |
|
| 4657 |
session.commit()
|
- |
|
| 4658 |
|
4634 |
|
| 4659 |
if len(orders) > 1:
|
- |
|
| 4660 |
totalOrdersAmount = 0
|
- |
|
| 4661 |
logisticsProviderId = orders[0].logistics_provider_id
|
- |
|
| 4662 |
logistics_client = LogisticsClient().get_client()
|
- |
|
| 4663 |
provider = logistics_client.getProvider(logisticsProviderId)
|
4635 |
##As per ticket #743 if amount difference less than 0.5 we should reconcile
|
| 4664 |
|
- |
|
| 4665 |
if provider.groupShipmentAllowed:
|
4636 |
if abs(amount - order.net_payable_amount) > 0.5:
|
| 4666 |
for order in orders:
|
- |
|
| 4667 |
totalOrdersAmount = totalOrdersAmount + order.net_payable_amount
|
4637 |
#Received amount is less than or more than the order amount. Mustn't let the user proceed.
|
| 4668 |
|
- |
|
| 4669 |
if abs(amount - (totalOrdersAmount)) > 0.5:
|
- |
|
| 4670 |
unprocessed_awbs[awb] = "Payment of Rs. " + str(amount) + " has been received against the total value of Rs. " + str(totalOrdersAmount) + " for Master Order Id: " + orders[0].logisticsTransactionId
|
4638 |
unprocessed_awbs[awb] = "Payment of Rs. " + str(amount) + " has been received against the total value of Rs. " + str(order.net_payable_amount) + " for order: " + str(order.id)
|
| 4671 |
continue
|
4639 |
continue
|
| - |
|
4640 |
|
| 4672 |
try:
|
4641 |
try:
|
| 4673 |
payment_client = PaymentClient().get_client()
|
4642 |
payment_client = PaymentClient().get_client()
|
| 4674 |
payment_client.partiallyCapturePayment(orders[0].transaction.id, amount, xferBy, xferTxnId, xferDate)
|
4643 |
payment_client.partiallyCapturePayment(order.transaction.id, amount, xferBy, xferTxnId, xferDate)
|
| 4675 |
except Exception:
|
4644 |
except Exception:
|
| 4676 |
unprocessed_awbs[awb] = "We were unable to partially capture payment for master order id " + orders[0].logisticsTransactionId + ", AWB: " + awb
|
4645 |
unprocessed_awbs[awb] = "We were unable to partially capture payment for order id " + str(order.id) + ", AWB: " + awb
|
| 4677 |
continue
|
4646 |
continue
|
| 4678 |
|
4647 |
|
| 4679 |
for order in orders:
|
- |
|
| 4680 |
order.cod_reconciliation_timestamp = datetime.datetime.now()
|
4648 |
#Payment has been recorded now. We can update the order peacefully.
|
| 4681 |
remittance = CodCourierPaymentRemittance()
|
4649 |
remittance = CodCourierPaymentRemittance()
|
| 4682 |
remittance.airwayBillNo = awb
|
4650 |
remittance.airwayBillNo = awb
|
| 4683 |
remittance.collectionReference = xferTxnId
|
4651 |
remittance.collectionReference = xferTxnId
|
| 4684 |
remittance.amount = amount
|
4652 |
remittance.amount = amount
|
| 4685 |
remittance.settledAt = datetime.datetime.strptime(xferDate, "%Y/%m/%d")
|
4653 |
remittance.settledAt = to_py_date(xferDate)
|
| 4686 |
remittance.provider_id = order.logistics_provider_id
|
4654 |
remittance.provider_id = order.logistics_provider_id
|
| 4687 |
session.commit()
|
4655 |
for order in orders:
|
| 4688 |
else:
|
- |
|
| 4689 |
unprocessed_awbs[awb] = "Multiple orders were found for the given AWB:" + awb
|
4656 |
order.cod_reconciliation_timestamp = datetime.datetime.now()
|
| 4690 |
continue
|
4657 |
session.commit()
|
| 4691 |
|
4658 |
|
| 4692 |
return unprocessed_awbs
|
4659 |
return unprocessed_awbs
|
| 4693 |
|
4660 |
|
| 4694 |
def get_transactions_requiring_extra_processing(category):
|
4661 |
def get_transactions_requiring_extra_processing(category):
|
| 4695 |
"""
|
4662 |
"""
|