| Line 1017... |
Line 1017... |
| 1017 |
to_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)
|
1017 |
to_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)
|
| 1018 |
from_datetime = to_datetime - datetime.timedelta(2)
|
1018 |
from_datetime = to_datetime - datetime.timedelta(2)
|
| 1019 |
orders_not_picked_up = Order.query.filter_by(logistics_provider_id = provider_id).filter_by(status=OrderStatus.DOA_PICKUP_CONFIRMED).filter(Order.doa_auth_timestamp >= from_datetime).filter(Order.doa_auth_timestamp <= to_datetime).all()
|
1019 |
orders_not_picked_up = Order.query.filter_by(logistics_provider_id = provider_id).filter_by(status=OrderStatus.DOA_PICKUP_CONFIRMED).filter(Order.doa_auth_timestamp >= from_datetime).filter(Order.doa_auth_timestamp <= to_datetime).all()
|
| 1020 |
return orders_not_picked_up
|
1020 |
return orders_not_picked_up
|
| 1021 |
|
1021 |
|
| 1022 |
def receive_return(order_id):
|
1022 |
def receive_return(order_id, receiveCondition):
|
| 1023 |
order = get_order(order_id)
|
1023 |
order = get_order(order_id)
|
| 1024 |
|
1024 |
|
| 1025 |
# FIXME: For Mahipal warehouse, we need to scan in items for every sales return
|
1025 |
# FIXME: For Mahipal warehouse, we need to scan in items for every sales return
|
| 1026 |
if order.warehouse_id == 7:
|
1026 |
if order.warehouse_id == 7:
|
| 1027 |
try:
|
1027 |
try:
|
| Line 1038... |
Line 1038... |
| 1038 |
except:
|
1038 |
except:
|
| 1039 |
print sys.exc_info()[0]
|
1039 |
print sys.exc_info()[0]
|
| 1040 |
print 'Could not scan in sales return orders'
|
1040 |
print 'Could not scan in sales return orders'
|
| 1041 |
|
1041 |
|
| 1042 |
if order.status in [OrderStatus.DOA_PICKUP_CONFIRMED, OrderStatus.DOA_RETURN_IN_TRANSIT]:
|
1042 |
if order.status in [OrderStatus.DOA_PICKUP_CONFIRMED, OrderStatus.DOA_RETURN_IN_TRANSIT]:
|
| - |
|
1043 |
if receiveCondition == 0:
|
| 1043 |
order.status = OrderStatus.DOA_RECEIVED_PRESTINE
|
1044 |
order.status = OrderStatus.DOA_RECEIVED_PRESTINE
|
| 1044 |
order.statusDescription = "DOA package received"
|
1045 |
order.statusDescription = "DOA package received"
|
| - |
|
1046 |
elif receiveCondition == 1:
|
| - |
|
1047 |
order.status = OrderStatus.DOA_RECEIVED_DAMAGED
|
| - |
|
1048 |
order.statusDescription = "DOA received damaged"
|
| - |
|
1049 |
elif receiveCondition == 2:
|
| - |
|
1050 |
order.status = OrderStatus.DOA_LOST_IN_TRANSIT
|
| - |
|
1051 |
order.statusDescription = "DOA lost in transit"
|
| 1045 |
order.received_return_timestamp = datetime.datetime.now()
|
1052 |
order.received_return_timestamp = datetime.datetime.now()
|
| 1046 |
session.commit()
|
1053 |
session.commit()
|
| 1047 |
elif order.status == OrderStatus.SALES_RETURN_IN_TRANSIT :
|
1054 |
elif order.status == OrderStatus.SALES_RETURN_IN_TRANSIT :
|
| 1048 |
order.status = OrderStatus.SALES_RET_RECEIVED
|
1055 |
order.status = OrderStatus.SALES_RET_RECEIVED
|
| 1049 |
order.statusDescription = "Sales return received"
|
1056 |
order.statusDescription = "Sales return received"
|
| Line 1101... |
Line 1108... |
| 1101 |
new_order = __clone_order(order, False, False)
|
1108 |
new_order = __clone_order(order, False, False)
|
| 1102 |
ret_order = __create_return_order(order)
|
1109 |
ret_order = __create_return_order(order)
|
| 1103 |
order.status = OrderStatus.DOA_VALID_RESHIPPED
|
1110 |
order.status = OrderStatus.DOA_VALID_RESHIPPED
|
| 1104 |
order.statusDescription = "Order Reshipped"
|
1111 |
order.statusDescription = "Order Reshipped"
|
| 1105 |
session.commit()
|
1112 |
session.commit()
|
| - |
|
1113 |
elif order.status == OrderStatus.DOA_RECEIVED_DAMAGED:
|
| - |
|
1114 |
new_order = __clone_order(order, False, False)
|
| - |
|
1115 |
ret_order = __create_return_order(order)
|
| - |
|
1116 |
order.status = OrderStatus.DOA_RESHIPPED_RCVD_DAMAGED
|
| - |
|
1117 |
order.statusDescription = "Order Reshipped Received Damaged"
|
| - |
|
1118 |
session.commit()
|
| - |
|
1119 |
elif order.status == OrderStatus.DOA_LOST_IN_TRANSIT:
|
| - |
|
1120 |
new_order = __clone_order(order, False, False)
|
| - |
|
1121 |
order.status = OrderStatus.DOA_RESHIPPED_LOST_IN_TRANSIT
|
| - |
|
1122 |
order.statusDescription = "Order Reshipped Lost In Transit"
|
| - |
|
1123 |
session.commit()
|
| 1106 |
else:
|
1124 |
else:
|
| 1107 |
raise TransactionServiceException(112, "This order can't be reshipped")
|
1125 |
raise TransactionServiceException(112, "This order can't be reshipped")
|
| 1108 |
|
1126 |
|
| 1109 |
order.reship_timestamp = datetime.datetime.now()
|
1127 |
order.reship_timestamp = datetime.datetime.now()
|
| 1110 |
order.new_order_id = new_order.id
|
1128 |
order.new_order_id = new_order.id
|
| Line 1147... |
Line 1165... |
| 1147 |
if order.cod:
|
1165 |
if order.cod:
|
| 1148 |
logging.info("Refunding COD order with status " + str(order.status))
|
1166 |
logging.info("Refunding COD order with status " + str(order.status))
|
| 1149 |
status_transition = {OrderStatus.SALES_RET_RECEIVED : OrderStatus.SALES_RET_REFUNDED,
|
1167 |
status_transition = {OrderStatus.SALES_RET_RECEIVED : OrderStatus.SALES_RET_REFUNDED,
|
| 1150 |
OrderStatus.DOA_CERT_INVALID : OrderStatus.DOA_INVALID_REFUNDED,
|
1168 |
OrderStatus.DOA_CERT_INVALID : OrderStatus.DOA_INVALID_REFUNDED,
|
| 1151 |
OrderStatus.DOA_CERT_VALID : OrderStatus.DOA_VALID_REFUNDED,
|
1169 |
OrderStatus.DOA_CERT_VALID : OrderStatus.DOA_VALID_REFUNDED,
|
| - |
|
1170 |
OrderStatus.DOA_RECEIVED_DAMAGED : OrderStatus.DOA_REFUNDED_RCVD_DAMAGED,
|
| - |
|
1171 |
OrderStatus.DOA_LOST_IN_TRANSIT : OrderStatus.DOA_REFUNDED_LOST_IN_TRANSIT,
|
| 1152 |
OrderStatus.INIT : OrderStatus.CANCELED,
|
1172 |
OrderStatus.INIT : OrderStatus.CANCELED,
|
| 1153 |
OrderStatus.SUBMITTED_FOR_PROCESSING : OrderStatus.CANCELED,
|
1173 |
OrderStatus.SUBMITTED_FOR_PROCESSING : OrderStatus.CANCELED,
|
| 1154 |
OrderStatus.INVENTORY_LOW : OrderStatus.CANCELED,
|
1174 |
OrderStatus.INVENTORY_LOW : OrderStatus.CANCELED,
|
| 1155 |
OrderStatus.LOW_INV_PO_RAISED : OrderStatus.CANCELED,
|
1175 |
OrderStatus.LOW_INV_PO_RAISED : OrderStatus.CANCELED,
|
| 1156 |
OrderStatus.LOW_INV_REVERSAL_IN_PROCESS : OrderStatus.CANCELED,
|
1176 |
OrderStatus.LOW_INV_REVERSAL_IN_PROCESS : OrderStatus.CANCELED,
|
| Line 1169... |
Line 1189... |
| 1169 |
__create_return_order(order)
|
1189 |
__create_return_order(order)
|
| 1170 |
order.statusDescription = "Order Cancelled"
|
1190 |
order.statusDescription = "Order Cancelled"
|
| 1171 |
elif order.status == OrderStatus.SALES_RET_RECEIVED:
|
1191 |
elif order.status == OrderStatus.SALES_RET_RECEIVED:
|
| 1172 |
__create_return_order(order)
|
1192 |
__create_return_order(order)
|
| 1173 |
order.statusDescription = "Order Returned to origin"
|
1193 |
order.statusDescription = "Order Returned to origin"
|
| 1174 |
elif order.status in [OrderStatus.DOA_CERT_INVALID, OrderStatus.DOA_CERT_VALID] :
|
1194 |
elif order.status in [OrderStatus.DOA_CERT_INVALID, OrderStatus.DOA_CERT_VALID, OrderStatus.DOA_RECEIVED_DAMAGED, OrderStatus.DOA_LOST_IN_TRANSIT] :
|
| 1175 |
__create_return_order(order)
|
1195 |
__create_return_order(order)
|
| 1176 |
__create_refund(order)
|
1196 |
__create_refund(order)
|
| 1177 |
order.statusDescription = "Order Refunded"
|
1197 |
order.statusDescription = "Order Refunded"
|
| 1178 |
elif order.status == OrderStatus.CANCEL_REQUEST_CONFIRMED:
|
1198 |
elif order.status == OrderStatus.CANCEL_REQUEST_CONFIRMED:
|
| 1179 |
if order.previousStatus < OrderStatus.BILLED:
|
1199 |
if order.previousStatus < OrderStatus.BILLED:
|
| Line 1184... |
Line 1204... |
| 1184 |
order.statusDescription = "Order Cancelled on customer request"
|
1204 |
order.statusDescription = "Order Cancelled on customer request"
|
| 1185 |
else:
|
1205 |
else:
|
| 1186 |
status_transition = {OrderStatus.SALES_RET_RECEIVED : OrderStatus.SALES_RET_REFUNDED,
|
1206 |
status_transition = {OrderStatus.SALES_RET_RECEIVED : OrderStatus.SALES_RET_REFUNDED,
|
| 1187 |
OrderStatus.DOA_CERT_INVALID : OrderStatus.DOA_INVALID_REFUNDED,
|
1207 |
OrderStatus.DOA_CERT_INVALID : OrderStatus.DOA_INVALID_REFUNDED,
|
| 1188 |
OrderStatus.DOA_CERT_VALID : OrderStatus.DOA_VALID_REFUNDED,
|
1208 |
OrderStatus.DOA_CERT_VALID : OrderStatus.DOA_VALID_REFUNDED,
|
| - |
|
1209 |
OrderStatus.DOA_RECEIVED_DAMAGED : OrderStatus.DOA_REFUNDED_RCVD_DAMAGED,
|
| - |
|
1210 |
OrderStatus.DOA_LOST_IN_TRANSIT : OrderStatus.DOA_REFUNDED_LOST_IN_TRANSIT,
|
| 1189 |
OrderStatus.SUBMITTED_FOR_PROCESSING : OrderStatus.REFUNDED,
|
1211 |
OrderStatus.SUBMITTED_FOR_PROCESSING : OrderStatus.REFUNDED,
|
| 1190 |
OrderStatus.INVENTORY_LOW : OrderStatus.REFUNDED,
|
1212 |
OrderStatus.INVENTORY_LOW : OrderStatus.REFUNDED,
|
| 1191 |
OrderStatus.LOW_INV_PO_RAISED : OrderStatus.REFUNDED,
|
1213 |
OrderStatus.LOW_INV_PO_RAISED : OrderStatus.REFUNDED,
|
| 1192 |
OrderStatus.LOW_INV_REVERSAL_IN_PROCESS : OrderStatus.REFUNDED,
|
1214 |
OrderStatus.LOW_INV_REVERSAL_IN_PROCESS : OrderStatus.REFUNDED,
|
| 1193 |
OrderStatus.LOW_INV_NOT_AVAILABLE_AT_HOTSPOT : OrderStatus.REFUNDED,
|
1215 |
OrderStatus.LOW_INV_NOT_AVAILABLE_AT_HOTSPOT : OrderStatus.REFUNDED,
|
| Line 1197... |
Line 1219... |
| 1197 |
OrderStatus.PAYMENT_FLAGGED : OrderStatus.PAYMENT_FLAGGED_DENIED
|
1219 |
OrderStatus.PAYMENT_FLAGGED : OrderStatus.PAYMENT_FLAGGED_DENIED
|
| 1198 |
}
|
1220 |
}
|
| 1199 |
if order.status not in status_transition.keys():
|
1221 |
if order.status not in status_transition.keys():
|
| 1200 |
raise TransactionServiceException(114, "This order can't be refunded")
|
1222 |
raise TransactionServiceException(114, "This order can't be refunded")
|
| 1201 |
|
1223 |
|
| 1202 |
if order.status in [OrderStatus.SALES_RET_RECEIVED, OrderStatus.DOA_CERT_INVALID, OrderStatus.DOA_CERT_VALID] :
|
1224 |
if order.status in [OrderStatus.SALES_RET_RECEIVED, OrderStatus.DOA_CERT_INVALID, OrderStatus.DOA_CERT_VALID, OrderStatus.DOA_RECEIVED_DAMAGED, OrderStatus.DOA_LOST_IN_TRANSIT] :
|
| 1203 |
__create_return_order(order)
|
1225 |
__create_return_order(order)
|
| 1204 |
__create_refund(order)
|
1226 |
__create_refund(order)
|
| 1205 |
order.statusDescription = "Order Refunded"
|
1227 |
order.statusDescription = "Order Refunded"
|
| 1206 |
elif order.status 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]:
|
1228 |
elif order.status 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]:
|
| 1207 |
__create_cancellation(order)
|
1229 |
__create_cancellation(order)
|
| Line 1281... |
Line 1303... |
| 1281 |
litem.transfer_price = line_item.transfer_price
|
1303 |
litem.transfer_price = line_item.transfer_price
|
| 1282 |
litem.order = new_order
|
1304 |
litem.order = new_order
|
| 1283 |
|
1305 |
|
| 1284 |
logistics_client = LogisticsClient().get_client()
|
1306 |
logistics_client = LogisticsClient().get_client()
|
| 1285 |
item_id = new_order.lineitems[0].item_id
|
1307 |
item_id = new_order.lineitems[0].item_id
|
| 1286 |
logistics_info = logistics_client.getLogisticsInfo(new_order.customer_pincode, item_id, DeliveryType.PREPAID) #TODO: We should be able to pass another flag to suggest ignoring the inventory situation.
|
1308 |
logistics_info = logistics_client.getLogisticsInfo(new_order.customer_pincode, item_id, is_cod) #TODO: We should be able to pass another flag to suggest ignoring the inventory situation.
|
| 1287 |
logistics_info.deliveryTime = adjust_delivery_time(current_time, logistics_info.deliveryTime)
|
1309 |
logistics_info.deliveryTime = adjust_delivery_time(current_time, logistics_info.deliveryTime)
|
| 1288 |
|
1310 |
|
| 1289 |
new_order.warehouse_id = logistics_info.warehouseId
|
1311 |
new_order.warehouse_id = logistics_info.warehouseId
|
| 1290 |
new_order.logistics_provider_id = logistics_info.providerId
|
1312 |
new_order.logistics_provider_id = logistics_info.providerId
|
| 1291 |
new_order.airwaybill_no = logistics_info.airway_billno
|
1313 |
new_order.airwaybill_no = logistics_info.airway_billno
|