Subversion Repositories SmartDukaan

Rev

Rev 4488 | Rev 4501 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4488 Rev 4495
Line 911... Line 911...
911
    session.commit()
911
    session.commit()
912
    return True
912
    return True
913
    
913
    
914
def request_pickup_number(order_id):
914
def request_pickup_number(order_id):
915
    order = get_order(order_id)
915
    order = get_order(order_id)
916
    if order.status != OrderStatus.DELIVERY_SUCCESS and order.status != OrderStatus.DOA_PICKUP_REQUEST_RAISED:
916
    if order.status != OrderStatus.DELIVERY_SUCCESS and order.status != OrderStatus.DOA_REQUEST_AUTHORIZED and order.status != OrderStatus.RET_REQUEST_AUTHORIZED:
917
        return False
917
        return False
918
    from_user = 'cnc.center@shop2020.in'
918
    from_user = 'cnc.center@shop2020.in'
919
    from_pwd = '5h0p2o2o'
919
    from_pwd = '5h0p2o2o'
920
    
920
    
921
    subject = "Pickup request from " + order.customer_city
921
    subject = "Pickup request from " + order.customer_city
Line 956... Line 956...
956
                                          'warehouse_address' : warehouse.location,
956
                                          'warehouse_address' : warehouse.location,
957
                                          'warehouse_pin' : warehouse.pincode,
957
                                          'warehouse_pin' : warehouse.pincode,
958
                                          'warehouse_phone': '9971573026'}
958
                                          'warehouse_phone': '9971573026'}
959
        #FIXME Email is hardcoded for bluedart
959
        #FIXME Email is hardcoded for bluedart
960
        mail(from_user, from_pwd, [to_addr, 'sonikap@bluedart.com'], subject, message)
960
        mail(from_user, from_pwd, [to_addr, 'sonikap@bluedart.com'], subject, message)
-
 
961
        if order.status == OrderStatus.RET_REQUEST_AUTHORIZED:
-
 
962
            order.status = OrderStatus.RET_PICKUP_REQUEST_RAISED
-
 
963
            order.statusDescription = "Pick up requested for RETURN"
-
 
964
        else:
961
        order.status = OrderStatus.DOA_PICKUP_REQUEST_RAISED
965
            order.status = OrderStatus.DOA_PICKUP_REQUEST_RAISED
962
        order.statusDescription = "Pick up requested for DOA"
966
            order.statusDescription = "Pick up requested for DOA"
963
        session.commit()
967
        session.commit()
964
        return True
968
        return True
965
    except Exception as e:
969
    except Exception as e:
966
        print sys.exc_info()[0]
970
        print sys.exc_info()[0]
967
        return False
971
        return False
968
 
972
 
969
def authorize_pickup(order_id, pickup_number):
973
def authorize_pickup(order_id, pickup_number):
970
    order = get_order(order_id)
974
    order = get_order(order_id)
971
    if order.status != OrderStatus.DOA_PICKUP_REQUEST_RAISED:
975
    if order.status not in [OrderStatus.DOA_PICKUP_REQUEST_RAISED, OrderStatus.RET_PICKUP_REQUEST_RAISED]:
972
        return False
976
        return False
973
    from_user = 'help@shop2020.in'
977
    from_user = 'help@shop2020.in'
974
    from_pwd = '5h0p2o2o'
978
    from_pwd = '5h0p2o2o'
975
    subject = 'Pickup details'
979
    subject = 'Pickup details'
976
    filename = "/tmp/" +  str(order.id) +".pdf" 
980
    filename = "/tmp/" +  str(order.id) +".pdf" 
Line 986... Line 990...
986
        today = date.today().strftime("%d-%B-%Y (%A)")
990
        today = date.today().strftime("%d-%B-%Y (%A)")
987
 
991
 
988
        raw_message = '''
992
        raw_message = '''
989
        Dear Mr. %(customer_name)s,
993
        Dear Mr. %(customer_name)s,
990
 
994
 
991
        In reference to the return of order ID %(order_id)d. We request you to kindly pack the box properly with bubble wrap, and send it along with the original "DOA" certificate and the invoice.
995
        In reference to the return of order ID %(order_id)d. We request you to kindly pack the box properly with bubble wrap, and send it along with the original "DOA" certificate (in case of DOA) and the invoice.
992
        Take a printout of the attachment in this mail which contains the delivery address and paste it on the packed parcel.
996
        Take a printout of the attachment in this mail which contains the delivery address and paste it on the packed parcel.
993
        We have instructed %(provider_name)s to pick up the material from the below mentioned address on %(date)s. %(provider_name)s pickup request number is %(pickup_request_no)s. Kindly keep the parcel ready.
997
        We have instructed %(provider_name)s to pick up the material from the below mentioned address on %(date)s. %(provider_name)s pickup request number is %(pickup_request_no)s. Kindly keep the parcel ready.
994
 
998
 
995
        Pickup will happen from the below mentioned address:-
999
        Pickup will happen from the below mentioned address:-
996
 
1000
 
Line 1009... Line 1013...
1009
                                         'customer_address' : __get_order_address(order)}
1013
                                         'customer_address' : __get_order_address(order)}
1010
        print message
1014
        print message
1011
        __generate_return_advice(order, warehouse, provider, filename)
1015
        __generate_return_advice(order, warehouse, provider, filename)
1012
        mail(from_user, from_pwd, [to_addr], subject, message, [get_attachment_part(filename)])
1016
        mail(from_user, from_pwd, [to_addr], subject, message, [get_attachment_part(filename)])
1013
        order.pickupRequestNo = pickup_number
1017
        order.pickupRequestNo = pickup_number
-
 
1018
        if order.status == OrderStatus.RET_PICKUP_REQUEST_RAISED:
-
 
1019
            order.status = OrderStatus.RET_PICKUP_CONFIRMED
-
 
1020
            order.statusDescription = "RETURN pick up confirmed"
-
 
1021
        else:
1014
        order.status = OrderStatus.DOA_PICKUP_CONFIRMED
1022
            order.status = OrderStatus.DOA_PICKUP_CONFIRMED
1015
        order.statusDescription = "DOA pick up confirmed"
1023
            order.statusDescription = "DOA pick up confirmed"
1016
        order.doa_auth_timestamp = datetime.datetime.now()
1024
        order.doa_auth_timestamp = datetime.datetime.now()
1017
        session.commit()
1025
        session.commit()
1018
        return True
1026
        return True
1019
    except Exception as e:
1027
    except Exception as e:
1020
        print sys.exc_info()
1028
        print sys.exc_info()
Line 1071... Line 1079...
1071
        elif receiveCondition == 2:
1079
        elif receiveCondition == 2:
1072
            order.status = OrderStatus.DOA_LOST_IN_TRANSIT
1080
            order.status = OrderStatus.DOA_LOST_IN_TRANSIT
1073
            order.statusDescription = "DOA lost in transit"
1081
            order.statusDescription = "DOA lost in transit"
1074
        order.received_return_timestamp = datetime.datetime.now()
1082
        order.received_return_timestamp = datetime.datetime.now()
1075
        session.commit()
1083
        session.commit()
-
 
1084
    elif order.status in [OrderStatus.RET_PICKUP_CONFIRMED, OrderStatus.RET_RETURN_IN_TRANSIT]:
-
 
1085
        if receiveCondition == 0:
-
 
1086
            order.status = OrderStatus.RET_RECEIVED_PRESTINE
-
 
1087
            order.statusDescription = "RETURN package received"
-
 
1088
        elif receiveCondition == 1:
-
 
1089
            order.status = OrderStatus.RET_RECEIVED_DAMAGED
-
 
1090
            order.statusDescription = "RETURN received damaged"
-
 
1091
        elif receiveCondition == 2:
-
 
1092
            order.status = OrderStatus.RET_LOST_IN_TRANSIT
-
 
1093
            order.statusDescription = "RETURN lost in transit"
-
 
1094
        order.received_return_timestamp = datetime.datetime.now()
-
 
1095
        session.commit()
1076
    elif order.status == OrderStatus.RTO_IN_TRANSIT :
1096
    elif order.status == OrderStatus.RTO_IN_TRANSIT :
1077
        if receiveCondition == 0:
1097
        if receiveCondition == 0:
1078
            order.status = OrderStatus.RTO_RECEIVED_PRESTINE
1098
            order.status = OrderStatus.RTO_RECEIVED_PRESTINE
1079
            order.statusDescription = "RTO package received"
1099
            order.statusDescription = "RTO package received"
1080
        elif receiveCondition == 1:
1100
        elif receiveCondition == 1:
Line 1101... Line 1121...
1101
        order.statusDescription = "DOA Certificate Invalid"
1121
        order.statusDescription = "DOA Certificate Invalid"
1102
        update_trust_level(order)
1122
        update_trust_level(order)
1103
    session.commit()
1123
    session.commit()
1104
    return True
1124
    return True
1105
 
1125
 
-
 
1126
def validate_return_product(order_id, is_usable):
-
 
1127
    order = get_order(order_id)
-
 
1128
    if order.status != OrderStatus.RET_RECEIVED_PRESTINE:
-
 
1129
        return False
-
 
1130
    if is_usable:
-
 
1131
        order.status = OrderStatus.RET_PRODUCT_USABLE
-
 
1132
        order.statusDescription = "Return product usable"
-
 
1133
    else:
-
 
1134
        order.status = OrderStatus.RET_PRODUCT_UNUSABLE
-
 
1135
        order.statusDescription = "Return product unusable"
-
 
1136
        update_trust_level(order)
-
 
1137
    session.commit()
-
 
1138
    return True
-
 
1139
 
1106
def reship_order(order_id):
1140
def reship_order(order_id):
1107
    """
1141
    """
1108
    If the order is in RTO_RECEIVED_PRESTINE or DOA_CERT_INVALID state, it does the following:
1142
    If the order is in RTO_RECEIVED_PRESTINE or DOA_CERT_INVALID state, it does the following:
1109
        1. Creates a new order for processing in the BILLED state. All billing information is saved.
1143
        1. Creates a new order for processing in the BILLED state. All billing information is saved.
1110
        2. Marks the current order as one of the final states RTO_RESHIPPED and DOA_INVALID_RESHIPPED depending on what state the order started in.
1144
        2. Marks the current order as one of the final states RTO_RESHIPPED and DOA_INVALID_RESHIPPED depending on what state the order started in.
Line 1159... Line 1193...
1159
    elif order.status == OrderStatus.DOA_LOST_IN_TRANSIT:
1193
    elif order.status == OrderStatus.DOA_LOST_IN_TRANSIT:
1160
        new_order = __clone_order(order, False, False)
1194
        new_order = __clone_order(order, False, False)
1161
        order.status = OrderStatus.DOA_RESHIPPED_LOST_IN_TRANSIT
1195
        order.status = OrderStatus.DOA_RESHIPPED_LOST_IN_TRANSIT
1162
        order.statusDescription = "Order Reshipped Lost In Transit"
1196
        order.statusDescription = "Order Reshipped Lost In Transit"
1163
        session.commit()
1197
        session.commit()
-
 
1198
    elif order.status == OrderStatus.RET_PRODUCT_UNUSABLE:
-
 
1199
        new_order = __clone_order(order, True, False)
-
 
1200
        order.status = OrderStatus.RET_PRODUCT_UNUSABLE_RESHIPPED
-
 
1201
        order.statusDescription = "Order Reshipped"
-
 
1202
        session.commit()
-
 
1203
    elif order.status == OrderStatus.RET_PRODUCT_USABLE:
-
 
1204
        new_order = __clone_order(order, False, False)
-
 
1205
        ret_order = __create_return_order(order)
-
 
1206
        order.status = OrderStatus.RET_PRODUCT_USABLE_RESHIPPED
-
 
1207
        order.statusDescription = "Order Reshipped"
-
 
1208
        session.commit()
-
 
1209
    elif order.status == OrderStatus.RET_RECEIVED_DAMAGED:
-
 
1210
        new_order = __clone_order(order, False, False)
-
 
1211
        ret_order = __create_return_order(order)
-
 
1212
        order.status = OrderStatus.RET_RESHIPPED_RCVD_DAMAGED
-
 
1213
        order.statusDescription = "Order Reshipped Received Damaged"
-
 
1214
        session.commit()
-
 
1215
    elif order.status == OrderStatus.RET_LOST_IN_TRANSIT:
-
 
1216
        new_order = __clone_order(order, False, False)
-
 
1217
        order.status = OrderStatus.RET_RESHIPPED_LOST_IN_TRANSIT
-
 
1218
        order.statusDescription = "Order Reshipped Lost In Transit"
-
 
1219
        session.commit()
1164
    else:
1220
    else:
1165
        raise TransactionServiceException(112, "This order can't be reshipped")
1221
        raise TransactionServiceException(112, "This order can't be reshipped")
1166
    
1222
    
1167
    order.reship_timestamp = datetime.datetime.now()
1223
    order.reship_timestamp = datetime.datetime.now()
1168
    order.new_order_id = new_order.id
1224
    order.new_order_id = new_order.id
Line 1209... Line 1265...
1209
                     OrderStatus.RTO_LOST_IN_TRANSIT : OrderStatus.RTO_LOST_IN_TRANSIT_REFUNDED,
1265
                     OrderStatus.RTO_LOST_IN_TRANSIT : OrderStatus.RTO_LOST_IN_TRANSIT_REFUNDED,
1210
                     OrderStatus.DOA_CERT_INVALID : OrderStatus.DOA_INVALID_REFUNDED,
1266
                     OrderStatus.DOA_CERT_INVALID : OrderStatus.DOA_INVALID_REFUNDED,
1211
                     OrderStatus.DOA_CERT_VALID : OrderStatus.DOA_VALID_REFUNDED,
1267
                     OrderStatus.DOA_CERT_VALID : OrderStatus.DOA_VALID_REFUNDED,
1212
                     OrderStatus.DOA_RECEIVED_DAMAGED : OrderStatus.DOA_REFUNDED_RCVD_DAMAGED,
1268
                     OrderStatus.DOA_RECEIVED_DAMAGED : OrderStatus.DOA_REFUNDED_RCVD_DAMAGED,
1213
                     OrderStatus.DOA_LOST_IN_TRANSIT : OrderStatus.DOA_REFUNDED_LOST_IN_TRANSIT,
1269
                     OrderStatus.DOA_LOST_IN_TRANSIT : OrderStatus.DOA_REFUNDED_LOST_IN_TRANSIT,
-
 
1270
                     OrderStatus.RET_PRODUCT_UNUSABLE : OrderStatus.RET_PRODUCT_UNUSABLE_REFUNDED,
-
 
1271
                     OrderStatus.RET_PRODUCT_USABLE : OrderStatus.RET_PRODUCT_USABLE_REFUNDED,
-
 
1272
                     OrderStatus.RET_RECEIVED_DAMAGED : OrderStatus.RET_REFUNDED_RCVD_DAMAGED,
-
 
1273
                     OrderStatus.RET_LOST_IN_TRANSIT : OrderStatus.RET_REFUNDED_LOST_IN_TRANSIT,
1214
                     OrderStatus.INIT : OrderStatus.CANCELED,
1274
                     OrderStatus.INIT : OrderStatus.CANCELED,
1215
                     OrderStatus.SUBMITTED_FOR_PROCESSING : OrderStatus.CANCELED,
1275
                     OrderStatus.SUBMITTED_FOR_PROCESSING : OrderStatus.CANCELED,
1216
                     OrderStatus.INVENTORY_LOW : OrderStatus.CANCELED,
1276
                     OrderStatus.INVENTORY_LOW : OrderStatus.CANCELED,
1217
                     OrderStatus.LOW_INV_PO_RAISED : OrderStatus.CANCELED,
1277
                     OrderStatus.LOW_INV_PO_RAISED : OrderStatus.CANCELED,
1218
                     OrderStatus.LOW_INV_REVERSAL_IN_PROCESS : OrderStatus.CANCELED,
1278
                     OrderStatus.LOW_INV_REVERSAL_IN_PROCESS : OrderStatus.CANCELED,
Line 1234... Line 1294...
1234
            __create_return_order(order)
1294
            __create_return_order(order)
1235
            order.statusDescription = "RTO Refunded"
1295
            order.statusDescription = "RTO Refunded"
1236
        elif order.status in [OrderStatus.DOA_CERT_INVALID, OrderStatus.DOA_CERT_VALID, OrderStatus.DOA_RECEIVED_DAMAGED, OrderStatus.DOA_LOST_IN_TRANSIT] :
1296
        elif order.status in [OrderStatus.DOA_CERT_INVALID, OrderStatus.DOA_CERT_VALID, OrderStatus.DOA_RECEIVED_DAMAGED, OrderStatus.DOA_LOST_IN_TRANSIT] :
1237
            __create_return_order(order)
1297
            __create_return_order(order)
1238
            __create_refund(order)
1298
            __create_refund(order)
-
 
1299
            order.statusDescription = "DOA Refunded"
-
 
1300
        elif order.status in [OrderStatus.RET_PRODUCT_UNUSABLE, OrderStatus.RET_PRODUCT_USABLE, OrderStatus.RET_RECEIVED_DAMAGED, OrderStatus.RET_LOST_IN_TRANSIT] :
-
 
1301
            __create_return_order(order)
-
 
1302
            __create_refund(order)
1239
            order.statusDescription = "Order Refunded"
1303
            order.statusDescription = "Return Refunded"
1240
        elif order.status == OrderStatus.CANCEL_REQUEST_CONFIRMED:
1304
        elif order.status == OrderStatus.CANCEL_REQUEST_CONFIRMED:
1241
            if order.previousStatus  < OrderStatus.BILLED:
1305
            if order.previousStatus  < OrderStatus.BILLED:
1242
                __update_inventory_reservation(order)
1306
                __update_inventory_reservation(order)
1243
                order.statusDescription = "Order Cancelled on customer request"
1307
                order.statusDescription = "Order Cancelled on customer request"
1244
            elif order.previousStatus == OrderStatus.BILLED:
1308
            elif order.previousStatus == OrderStatus.BILLED:
Line 1250... Line 1314...
1250
                     OrderStatus.RTO_LOST_IN_TRANSIT : OrderStatus.RTO_LOST_IN_TRANSIT_REFUNDED,
1314
                     OrderStatus.RTO_LOST_IN_TRANSIT : OrderStatus.RTO_LOST_IN_TRANSIT_REFUNDED,
1251
                     OrderStatus.DOA_CERT_INVALID : OrderStatus.DOA_INVALID_REFUNDED,
1315
                     OrderStatus.DOA_CERT_INVALID : OrderStatus.DOA_INVALID_REFUNDED,
1252
                     OrderStatus.DOA_CERT_VALID : OrderStatus.DOA_VALID_REFUNDED,
1316
                     OrderStatus.DOA_CERT_VALID : OrderStatus.DOA_VALID_REFUNDED,
1253
                     OrderStatus.DOA_RECEIVED_DAMAGED : OrderStatus.DOA_REFUNDED_RCVD_DAMAGED,
1317
                     OrderStatus.DOA_RECEIVED_DAMAGED : OrderStatus.DOA_REFUNDED_RCVD_DAMAGED,
1254
                     OrderStatus.DOA_LOST_IN_TRANSIT : OrderStatus.DOA_REFUNDED_LOST_IN_TRANSIT,
1318
                     OrderStatus.DOA_LOST_IN_TRANSIT : OrderStatus.DOA_REFUNDED_LOST_IN_TRANSIT,
-
 
1319
                     OrderStatus.RET_PRODUCT_UNUSABLE : OrderStatus.RET_PRODUCT_UNUSABLE_REFUNDED,
-
 
1320
                     OrderStatus.RET_PRODUCT_USABLE : OrderStatus.RET_PRODUCT_USABLE_REFUNDED,
-
 
1321
                     OrderStatus.RET_RECEIVED_DAMAGED : OrderStatus.RET_REFUNDED_RCVD_DAMAGED,
-
 
1322
                     OrderStatus.RET_LOST_IN_TRANSIT : OrderStatus.RET_REFUNDED_LOST_IN_TRANSIT,
1255
                     OrderStatus.SUBMITTED_FOR_PROCESSING : OrderStatus.REFUNDED,
1323
                     OrderStatus.SUBMITTED_FOR_PROCESSING : OrderStatus.REFUNDED,
1256
                     OrderStatus.INVENTORY_LOW : OrderStatus.REFUNDED,
1324
                     OrderStatus.INVENTORY_LOW : OrderStatus.REFUNDED,
1257
                     OrderStatus.LOW_INV_PO_RAISED : OrderStatus.REFUNDED,
1325
                     OrderStatus.LOW_INV_PO_RAISED : OrderStatus.REFUNDED,
1258
                     OrderStatus.LOW_INV_REVERSAL_IN_PROCESS : OrderStatus.REFUNDED,
1326
                     OrderStatus.LOW_INV_REVERSAL_IN_PROCESS : OrderStatus.REFUNDED,
1259
                     OrderStatus.LOW_INV_NOT_AVAILABLE_AT_HOTSPOT : OrderStatus.REFUNDED,
1327
                     OrderStatus.LOW_INV_NOT_AVAILABLE_AT_HOTSPOT : OrderStatus.REFUNDED,
Line 1263... Line 1331...
1263
                     OrderStatus.PAYMENT_FLAGGED : OrderStatus.PAYMENT_FLAGGED_DENIED
1331
                     OrderStatus.PAYMENT_FLAGGED : OrderStatus.PAYMENT_FLAGGED_DENIED
1264
                     }
1332
                     }
1265
        if order.status not in status_transition.keys():
1333
        if order.status not in status_transition.keys():
1266
            raise TransactionServiceException(114, "This order can't be refunded")
1334
            raise TransactionServiceException(114, "This order can't be refunded")
1267
    
1335
    
1268
        if order.status in [OrderStatus.RTO_RECEIVED_PRESTINE, OrderStatus.RTO_RECEIVED_DAMAGED, OrderStatus.RTO_LOST_IN_TRANSIT, OrderStatus.DOA_CERT_INVALID, OrderStatus.DOA_CERT_VALID, OrderStatus.DOA_RECEIVED_DAMAGED, OrderStatus.DOA_LOST_IN_TRANSIT] :
1336
        if order.status in [OrderStatus.RTO_RECEIVED_PRESTINE, OrderStatus.RTO_RECEIVED_DAMAGED, OrderStatus.RTO_LOST_IN_TRANSIT] :
1269
            __create_return_order(order)
1337
            __create_return_order(order)
1270
            __create_refund(order)
1338
            __create_refund(order)
-
 
1339
            order.statusDescription = "RTO Refunded"
-
 
1340
        elif order.status in [OrderStatus.DOA_CERT_INVALID, OrderStatus.DOA_CERT_VALID, OrderStatus.DOA_RECEIVED_DAMAGED, OrderStatus.DOA_LOST_IN_TRANSIT] :
-
 
1341
            __create_return_order(order)
-
 
1342
            __create_refund(order)
-
 
1343
            order.statusDescription = "DOA Refunded"
-
 
1344
        elif order.status in [OrderStatus.RET_PRODUCT_UNUSABLE, OrderStatus.RET_PRODUCT_USABLE, OrderStatus.RET_RECEIVED_DAMAGED, OrderStatus.RET_LOST_IN_TRANSIT] :
-
 
1345
            __create_return_order(order)
-
 
1346
            __create_refund(order)
1271
            order.statusDescription = "Order Refunded"
1347
            order.statusDescription = "Return Refunded"
1272
        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]:
1348
        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]:
1273
            __create_cancellation(order)
1349
            __create_cancellation(order)
1274
            __update_inventory_reservation(order)
1350
            __update_inventory_reservation(order)
1275
            order.statusDescription = "Order Refunded"
1351
            order.statusDescription = "Order Refunded"
1276
        elif order.status == OrderStatus.CANCEL_REQUEST_CONFIRMED:
1352
        elif order.status == OrderStatus.CANCEL_REQUEST_CONFIRMED: