| Line 3342... |
Line 3342... |
| 3342 |
- reason
|
3342 |
- reason
|
| 3343 |
"""
|
3343 |
"""
|
| 3344 |
logging.info("Refunding order id: " + str(order_id))
|
3344 |
logging.info("Refunding order id: " + str(order_id))
|
| 3345 |
order = get_order(order_id)
|
3345 |
order = get_order(order_id)
|
| 3346 |
|
3346 |
|
| 3347 |
#if this order is from store and a new order for it has already been reshipped then
|
- |
|
| 3348 |
#this order cannot be refunded.
|
- |
|
| 3349 |
if order.source == 2 and order.new_order_id:
|
- |
|
| 3350 |
raise TransactionServiceException(112, "This order should be marked reship")
|
- |
|
| 3351 |
if order.source == 6 or order.source ==7:
|
- |
|
| 3352 |
#Add more order statuses
|
- |
|
| 3353 |
if order.status == OrderStatus.RTO_RECEIVED_PRESTINE:
|
- |
|
| 3354 |
order.statusDescription = "RTO Refunded"
|
- |
|
| 3355 |
order.status = OrderStatus.RTO_REFUNDED
|
- |
|
| 3356 |
order.refund_timestamp = datetime.datetime.now()
|
- |
|
| 3357 |
order.refunded_by = refunded_by
|
- |
|
| 3358 |
order.refund_reason = reason
|
- |
|
| 3359 |
session.commit()
|
- |
|
| 3360 |
return True
|
- |
|
| 3361 |
|
- |
|
| 3362 |
|
- |
|
| 3363 |
if order.cod:
|
3347 |
if order.cod:
|
| 3364 |
logging.info("Refunding COD order with status " + str(order.status))
|
3348 |
logging.info("Refunding COD order with status " + str(order.status))
|
| 3365 |
status_transition = refund_status_transition
|
3349 |
status_transition = refund_status_transition
|
| 3366 |
if order.status not in status_transition.keys():
|
3350 |
if order.status not in status_transition.keys():
|
| 3367 |
raise TransactionServiceException(114, "This order can't be refunded")
|
3351 |
raise TransactionServiceException(114, "This order can't be refunded")
|
| Line 3490... |
Line 3474... |
| 3490 |
elif order.status == OrderStatus.CANCEL_REQUEST_CONFIRMED:
|
3474 |
elif order.status == OrderStatus.CANCEL_REQUEST_CONFIRMED:
|
| 3491 |
if order.previousStatus in [OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.INVENTORY_LOW, OrderStatus.LOW_INV_PO_RAISED, OrderStatus.LOW_INV_REVERSAL_IN_PROCESS, OrderStatus.LOW_INV_NOT_AVAILABLE_AT_HOTSPOT, OrderStatus.PAYMENT_FLAGGED, OrderStatus.ACCEPTED]:
|
3475 |
if order.previousStatus in [OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.INVENTORY_LOW, OrderStatus.LOW_INV_PO_RAISED, OrderStatus.LOW_INV_REVERSAL_IN_PROCESS, OrderStatus.LOW_INV_NOT_AVAILABLE_AT_HOTSPOT, OrderStatus.PAYMENT_FLAGGED, OrderStatus.ACCEPTED]:
|
| 3492 |
__update_inventory_reservation(order, refund=True)
|
3476 |
__update_inventory_reservation(order, refund=True)
|
| 3493 |
order.statusDescription = "Order Cancelled on customer request"
|
3477 |
order.statusDescription = "Order Cancelled on customer request"
|
| 3494 |
elif order.previousStatus == OrderStatus.BILLED:
|
3478 |
elif order.previousStatus == OrderStatus.BILLED:
|
| 3495 |
__create_return_order(order)
|
- |
|
| 3496 |
__create_refund(order, order.wallet_amount, 'Order #{0} Cancelled on customer request'.format(order.id))
|
3479 |
__create_refund(order, order.wallet_amount, 'Order #{0} Cancelled on customer request'.format(order.id))
|
| - |
|
3480 |
order.logisticsTransactionId = None
|
| - |
|
3481 |
order.billing_timestamp = None
|
| - |
|
3482 |
order.invoice_number = None
|
| 3497 |
order.statusDescription = "Order Cancelled on customer request"
|
3483 |
order.statusDescription = "Order Cancelled on customer request"
|
| 3498 |
order.received_return_timestamp = datetime.datetime.now()
|
- |
|
| 3499 |
|
3484 |
|
| 3500 |
elif order.status == OrderStatus.PAYMENT_FLAGGED:
|
3485 |
elif order.status == OrderStatus.PAYMENT_FLAGGED:
|
| 3501 |
__update_inventory_reservation(order, refund=True)
|
3486 |
__update_inventory_reservation(order, refund=True)
|
| 3502 |
order.statusDescription = "Order Cancelled due to payment flagged"
|
3487 |
order.statusDescription = "Order Cancelled due to payment flagged"
|
| 3503 |
|
3488 |
|
| 3504 |
if order.transaction.payment_option == capitalFloatPayMethod and order.status in [OrderStatus.PAYMENT_FLAGGED, OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.INVENTORY_LOW, OrderStatus.LOW_INV_PO_RAISED, OrderStatus.LOW_INV_REVERSAL_IN_PROCESS, OrderStatus.LOW_INV_NOT_AVAILABLE_AT_HOTSPOT, OrderStatus.ACCEPTED, OrderStatus.CANCEL_REQUEST_CONFIRMED]:
|
- |
|
| 3505 |
total_amount = order.total_amount + order.shippingCost - order.gvAmount
|
- |
|
| 3506 |
shipping_id = str(order.id)
|
- |
|
| 3507 |
if order.logisticsTransactionId is not None:
|
- |
|
| 3508 |
shipping_id = order.logisticsTransactionId
|
- |
|
| 3509 |
creditObj = __creditHistoryObj(order.customer_id, 1, order.transaction.id, total_amount, CreditTxnType.BLOCKED_REVERSED, shipping_id)
|
- |
|
| 3510 |
creditTxns = []
|
- |
|
| 3511 |
creditTxns.append(creditObj)
|
- |
|
| 3512 |
try:
|
- |
|
| 3513 |
process_credit_transaction(order.transaction.id, order.customer_id, 1, creditTxns)
|
- |
|
| 3514 |
except:
|
- |
|
| 3515 |
traceback.print_exc()
|
- |
|
| 3516 |
session.rollback()
|
- |
|
| 3517 |
return False
|
- |
|
| 3518 |
|
- |
|
| 3519 |
# For orders that are cancelled after being billed, we need to scan in the scanned out
|
3489 |
# For orders that are cancelled after being billed, we need to scan in the scanned out
|
| 3520 |
# inventory item and change availability accordingly
|
3490 |
# inventory item and change availability accordingly
|
| 3521 |
inventoryClient = InventoryClient().get_client()
|
3491 |
inventoryClient = InventoryClient().get_client()
|
| 3522 |
warehouse = inventoryClient.getWarehouse(order.warehouse_id)
|
3492 |
warehouse = inventoryClient.getWarehouse(order.warehouse_id)
|
| 3523 |
if warehouse.billingType == BillingType.OURS or warehouse.billingType == BillingType.OURS_EXTERNAL:
|
3493 |
if warehouse.billingType == BillingType.OURS or warehouse.billingType == BillingType.OURS_EXTERNAL:
|