| Line 927... |
Line 927... |
| 927 |
- orderId
|
927 |
- orderId
|
| 928 |
"""
|
928 |
"""
|
| 929 |
status_transition = {OrderStatus.SALES_RET_RECEIVED : OrderStatus.SALES_RET_REFUNDED,
|
929 |
status_transition = {OrderStatus.SALES_RET_RECEIVED : OrderStatus.SALES_RET_REFUNDED,
|
| 930 |
OrderStatus.DOA_CERT_INVALID : OrderStatus.DOA_INVALID_REFUNDED,
|
930 |
OrderStatus.DOA_CERT_INVALID : OrderStatus.DOA_INVALID_REFUNDED,
|
| 931 |
OrderStatus.DOA_CERT_VALID : OrderStatus.DOA_VALID_REFUNDED,
|
931 |
OrderStatus.DOA_CERT_VALID : OrderStatus.DOA_VALID_REFUNDED,
|
| 932 |
OrderStatus.INIT : OrderStatus.REFUNDED,
|
932 |
OrderStatus.INIT : OrderStatus.CANCELED,
|
| 933 |
OrderStatus.SUBMITTED_FOR_PROCESSING : OrderStatus.REFUNDED,
|
933 |
OrderStatus.SUBMITTED_FOR_PROCESSING : OrderStatus.REFUNDED,
|
| 934 |
OrderStatus.INVENTORY_LOW : OrderStatus.REFUNDED
|
934 |
OrderStatus.INVENTORY_LOW : OrderStatus.REFUNDED
|
| 935 |
}
|
935 |
}
|
| 936 |
order = get_order(order_id)
|
936 |
order = get_order(order_id)
|
| 937 |
|
937 |
|
| 938 |
if order.status not in status_transition.keys():
|
938 |
if order.status not in status_transition.keys():
|
| 939 |
raise TransactionServiceException(114, "This order can't be refunded")
|
939 |
raise TransactionServiceException(114, "This order can't be refunded")
|
| 940 |
|
940 |
|
| - |
|
941 |
order.status = status_transition[order.status]
|
| - |
|
942 |
order.statusDescription = "Order Refunded"
|
| - |
|
943 |
|
| 941 |
if order.status == OrderStatus.INIT:
|
944 |
if order.status == OrderStatus.INIT:
|
| 942 |
__update_inventory_reservation(order)
|
945 |
__update_inventory_reservation(order)
|
| - |
|
946 |
order.statusDescription = "Order Cancelled"
|
| 943 |
elif order.status in [OrderStatus.SALES_RET_RECEIVED, OrderStatus.DOA_CERT_INVALID, OrderStatus.DOA_CERT_VALID] :
|
947 |
elif order.status in [OrderStatus.SALES_RET_RECEIVED, OrderStatus.DOA_CERT_INVALID, OrderStatus.DOA_CERT_VALID] :
|
| 944 |
__create_return_order(order)
|
948 |
__create_return_order(order)
|
| 945 |
__create_refund(order)
|
949 |
__create_refund(order)
|
| 946 |
elif order.status in [OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.INVENTORY_LOW]:
|
950 |
elif order.status in [OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.INVENTORY_LOW]:
|
| - |
|
951 |
if not order.cod:
|
| 947 |
__create_cancellation(order)
|
952 |
__create_cancellation(order)
|
| 948 |
__update_inventory_reservation(order)
|
953 |
__update_inventory_reservation(order)
|
| 949 |
|
954 |
|
| 950 |
order.status = status_transition[order.status]
|
- |
|
| 951 |
order.statusDescription = "Refunded"
|
- |
|
| 952 |
order.refund_timestamp = datetime.datetime.now()
|
955 |
order.refund_timestamp = datetime.datetime.now()
|
| 953 |
session.commit()
|
956 |
session.commit()
|
| 954 |
return True
|
957 |
return True
|
| 955 |
|
958 |
|
| 956 |
def __update_inventory_reservation(order):
|
959 |
def __update_inventory_reservation(order):
|
| - |
|
960 |
'''
|
| - |
|
961 |
Reduce the reservation count for all line items of the given order.
|
| - |
|
962 |
'''
|
| 957 |
try:
|
963 |
try:
|
| 958 |
#Reduce the reservation count for all lineitems.
|
- |
|
| 959 |
catalog_client = CatalogClient().get_client()
|
964 |
catalog_client = CatalogClient().get_client()
|
| 960 |
for lineitem in order.lineitems:
|
965 |
for lineitem in order.lineitems:
|
| 961 |
catalog_client.reduceReservationCount(lineitem.item_id, order.warehouse_id, lineitem.quantity);
|
966 |
catalog_client.reduceReservationCount(lineitem.item_id, order.warehouse_id, lineitem.quantity);
|
| 962 |
except:
|
967 |
except:
|
| 963 |
print "Unable to reduce reservation count"
|
968 |
print "Unable to reduce reservation count"
|