Subversion Repositories SmartDukaan

Rev

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

Rev 4479 Rev 4484
Line 57... Line 57...
57
 
57
 
58
PAGE_HEIGHT=defaultPageSize[1]
58
PAGE_HEIGHT=defaultPageSize[1]
59
PAGE_WIDTH=defaultPageSize[0]
59
PAGE_WIDTH=defaultPageSize[0]
60
 
60
 
61
ORDER_STATUS_TO_USER_TRUST_LEVEL_DELTA_DICT = {
61
ORDER_STATUS_TO_USER_TRUST_LEVEL_DELTA_DICT = {
62
        OrderStatus.SALES_RET_RESHIPPED     :  3,
62
        OrderStatus.RTO_RESHIPPED     :  3,
63
        OrderStatus.SALES_RETURN_IN_TRANSIT : -5,
63
        OrderStatus.RTO_IN_TRANSIT : -5,
64
        OrderStatus.DELIVERY_SUCCESS        :  1,
64
        OrderStatus.DELIVERY_SUCCESS        :  1,
65
        OrderStatus.DOA_CERT_INVALID        : -5
65
        OrderStatus.DOA_CERT_INVALID        : -5
66
}
66
}
67
 
67
 
68
def get_new_transaction():
68
def get_new_transaction():
Line 772... Line 772...
772
    for awb, detail in returned_orders.iteritems():
772
    for awb, detail in returned_orders.iteritems():
773
        order = Order.query.filter_by(airwaybill_no=awb, logistics_provider_id = provider_id).first()
773
        order = Order.query.filter_by(airwaybill_no=awb, logistics_provider_id = provider_id).first()
774
        if order == None or order.status not in [OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST]:
774
        if order == None or order.status not in [OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST]:
775
            continue
775
            continue
776
            #raise TransactionServiceException(103, "No order found for the awb:" + awb)
776
            #raise TransactionServiceException(103, "No order found for the awb:" + awb)
777
        order.status = OrderStatus.SALES_RETURN_IN_TRANSIT
777
        order.status = OrderStatus.RTO_IN_TRANSIT
778
        order.delivery_timestamp, reason = detail.split('|')
778
        order.delivery_timestamp, reason = detail.split('|')
779
        order.statusDescription = "Order Returned to Origin:" + reason
779
        order.statusDescription = "Order Returned to Origin:" + reason
780
        update_trust_level(order)
780
        update_trust_level(order)
781
    session.commit()
781
    session.commit()
782
 
782
 
Line 819... Line 819...
819
def get_valid_order_count():
819
def get_valid_order_count():
820
    '''
820
    '''
821
    Returns the number of orders which we processed. The reshipped orders are not
821
    Returns the number of orders which we processed. The reshipped orders are not
822
    counted since there'll always be a new compensating order present.
822
    counted since there'll always be a new compensating order present.
823
    '''
823
    '''
824
    return Order.query.filter(Order.status >= OrderStatus.SUBMITTED_FOR_PROCESSING).filter(not_(Order.status.in_((OrderStatus.SALES_RET_RESHIPPED, OrderStatus.DOA_INVALID_RESHIPPED, OrderStatus.DOA_VALID_RESHIPPED, OrderStatus.CANCELED)))).count()
824
    return Order.query.filter(Order.status >= OrderStatus.SUBMITTED_FOR_PROCESSING).filter(not_(Order.status.in_((OrderStatus.RTO_RESHIPPED, OrderStatus.DOA_INVALID_RESHIPPED, OrderStatus.DOA_VALID_RESHIPPED, OrderStatus.CANCELED)))).count()
825
 
825
 
826
def get_cust_count_with_successful_txn():
826
def get_cust_count_with_successful_txn():
827
    '''
827
    '''
828
    Returns the number of distinct customers who have done successful transactions.
828
    Returns the number of distinct customers who have done successful transactions.
829
    It uses the sqlalchemy func module to construct an efficient query.
829
    It uses the sqlalchemy func module to construct an efficient query.
Line 1027... Line 1027...
1027
        try:
1027
        try:
1028
            warehouse_client = WarehouseClient().get_client()
1028
            warehouse_client = WarehouseClient().get_client()
1029
            lineitem = order.lineitems[0]
1029
            lineitem = order.lineitems[0]
1030
 
1030
 
1031
            # Inventory should not be updated for DOA returns 
1031
            # Inventory should not be updated for DOA returns 
1032
            if order.status == OrderStatus.SALES_RETURN_IN_TRANSIT:
1032
            if order.status == OrderStatus.RTO_IN_TRANSIT:
1033
                warehouse_client.scanIn(order.id, lineitem.item_number, lineitem.imei_number, ScanType.SALE_RET)
1033
                warehouse_client.scanIn(order.id, lineitem.item_number, lineitem.imei_number, ScanType.SALE_RET)
1034
                catalog_client = CatalogClient().get_client()
1034
                catalog_client = CatalogClient().get_client()
1035
                catalog_client.reduceReservationCount(lineitem.item_id, order.warehouse_id, lineitem.quantity)
1035
                catalog_client.reduceReservationCount(lineitem.item_id, order.warehouse_id, lineitem.quantity)
1036
            elif order.status in [OrderStatus.DOA_PICKUP_CONFIRMED, OrderStatus.DOA_RETURN_IN_TRANSIT]:
1036
            elif order.status in [OrderStatus.DOA_PICKUP_CONFIRMED, OrderStatus.DOA_RETURN_IN_TRANSIT]:
1037
                warehouse_client.scanIn(order.id, lineitem.item_number, lineitem.imei_number, ScanType.DOA_IN)
1037
                warehouse_client.scanIn(order.id, lineitem.item_number, lineitem.imei_number, ScanType.DOA_IN)
Line 1049... Line 1049...
1049
        elif receiveCondition == 2:
1049
        elif receiveCondition == 2:
1050
            order.status = OrderStatus.DOA_LOST_IN_TRANSIT
1050
            order.status = OrderStatus.DOA_LOST_IN_TRANSIT
1051
            order.statusDescription = "DOA lost in transit"
1051
            order.statusDescription = "DOA lost in transit"
1052
        order.received_return_timestamp = datetime.datetime.now()
1052
        order.received_return_timestamp = datetime.datetime.now()
1053
        session.commit()
1053
        session.commit()
1054
    elif order.status == OrderStatus.SALES_RETURN_IN_TRANSIT :
1054
    elif order.status == OrderStatus.RTO_IN_TRANSIT :
1055
        order.status = OrderStatus.SALES_RET_RECEIVED
1055
        order.status = OrderStatus.RTO_RECEIVED_PRESTINE
1056
        order.statusDescription = "Sales return received"
1056
        order.statusDescription = "Sales return received"
1057
        order.received_return_timestamp = datetime.datetime.now()
1057
        order.received_return_timestamp = datetime.datetime.now()
1058
        session.commit()
1058
        session.commit()
1059
    else:
1059
    else:
1060
        return False
1060
        return False
Line 1074... Line 1074...
1074
    session.commit()
1074
    session.commit()
1075
    return True
1075
    return True
1076
 
1076
 
1077
def reship_order(order_id):
1077
def reship_order(order_id):
1078
    """
1078
    """
1079
    If the order is in SALES_RET_RECEIVED or DOA_CERT_INVALID state, it does the following:
1079
    If the order is in RTO_RECEIVED_PRESTINE or DOA_CERT_INVALID state, it does the following:
1080
        1. Creates a new order for processing in the BILLED state. All billing information is saved.
1080
        1. Creates a new order for processing in the BILLED state. All billing information is saved.
1081
        2. Marks the current order as one of the final states SALES_RET_RESHIPPED and DOA_INVALID_RESHIPPED depending on what state the order started in.
1081
        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.
1082
        
1082
        
1083
    If the order is in DOA_CERT_VALID state, it does the following:
1083
    If the order is in DOA_CERT_VALID state, it does the following:
1084
        1. Creates a new order for processing in the SUBMITTED_FOR_PROCESSING state.
1084
        1. Creates a new order for processing in the SUBMITTED_FOR_PROCESSING state.
1085
        2. Creates a return order for the warehouse executive to return the DOA material.
1085
        2. Creates a return order for the warehouse executive to return the DOA material.
1086
        3. Marks the current order as the final DOA_VALID_RESHIPPED state.
1086
        3. Marks the current order as the final DOA_VALID_RESHIPPED state.
Line 1091... Line 1091...
1091
    
1091
    
1092
    Parameters:
1092
    Parameters:
1093
     - orderId
1093
     - orderId
1094
    """
1094
    """
1095
    order = get_order(order_id)
1095
    order = get_order(order_id)
1096
    if order.status == OrderStatus.SALES_RET_RECEIVED:
1096
    if order.status == OrderStatus.RTO_RECEIVED_PRESTINE:
1097
        new_order = __clone_order(order, True, order.cod)
1097
        new_order = __clone_order(order, True, order.cod)
1098
        order.status = OrderStatus.SALES_RET_RESHIPPED
1098
        order.status = OrderStatus.RTO_RESHIPPED
1099
        order.statusDescription = "Order Reshipped"
1099
        order.statusDescription = "Order Reshipped"
1100
        session.commit()
1100
        session.commit()
1101
        update_trust_level(order)
1101
        update_trust_level(order)
1102
    elif order.status == OrderStatus.DOA_CERT_INVALID:
1102
    elif order.status == OrderStatus.DOA_CERT_INVALID:
1103
        new_order = __clone_order(order, True, False)
1103
        new_order = __clone_order(order, True, False)
Line 1130... Line 1130...
1130
    
1130
    
1131
    return new_order.id
1131
    return new_order.id
1132
 
1132
 
1133
def refund_order(order_id, refunded_by, reason):
1133
def refund_order(order_id, refunded_by, reason):
1134
    """
1134
    """
1135
    If the order is in SALES_RET_RECEIVED, DOA_CERT_VALID or DOA_CERT_INVALID state, it does the following:
1135
    If the order is in RTO_RECEIVED_PRESTINE, DOA_CERT_VALID or DOA_CERT_INVALID state, it does the following:
1136
        1. Creates a refund request for batch processing.
1136
        1. Creates a refund request for batch processing.
1137
        2. Creates a return order for the warehouse executive to return the shipped material.
1137
        2. Creates a return order for the warehouse executive to return the shipped material.
1138
        3. Marks the current order as SALES_RET_REFUNDED, DOA_VALID_REFUNDED or DOA_INVALID_REFUNDED final states.
1138
        3. Marks the current order as RTO_REFUNDED, DOA_VALID_REFUNDED or DOA_INVALID_REFUNDED final states.
1139
    
1139
    
1140
    If the order is in SUBMITTED_FOR_PROCESSING or INVENTORY_LOW state, it does the following:
1140
    If the order is in SUBMITTED_FOR_PROCESSING or INVENTORY_LOW state, it does the following:
1141
        1. Creates a refund request for batch processing.
1141
        1. Creates a refund request for batch processing.
1142
        2. Cancels the reservation of the item in the warehouse.
1142
        2. Cancels the reservation of the item in the warehouse.
1143
        3. Marks the current order as the REFUNDED final state.
1143
        3. Marks the current order as the REFUNDED final state.
Line 1162... Line 1162...
1162
    
1162
    
1163
    
1163
    
1164
    
1164
    
1165
    if order.cod:
1165
    if order.cod:
1166
        logging.info("Refunding COD order with status " + str(order.status))
1166
        logging.info("Refunding COD order with status " + str(order.status))
1167
        status_transition = {OrderStatus.SALES_RET_RECEIVED : OrderStatus.SALES_RET_REFUNDED,
1167
        status_transition = {OrderStatus.RTO_RECEIVED_PRESTINE : OrderStatus.RTO_REFUNDED,
1168
                     OrderStatus.DOA_CERT_INVALID : OrderStatus.DOA_INVALID_REFUNDED,
1168
                     OrderStatus.DOA_CERT_INVALID : OrderStatus.DOA_INVALID_REFUNDED,
1169
                     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,
1170
                     OrderStatus.DOA_RECEIVED_DAMAGED : OrderStatus.DOA_REFUNDED_RCVD_DAMAGED,
1171
                     OrderStatus.DOA_LOST_IN_TRANSIT : OrderStatus.DOA_REFUNDED_LOST_IN_TRANSIT,
1171
                     OrderStatus.DOA_LOST_IN_TRANSIT : OrderStatus.DOA_REFUNDED_LOST_IN_TRANSIT,
1172
                     OrderStatus.INIT : OrderStatus.CANCELED,
1172
                     OrderStatus.INIT : OrderStatus.CANCELED,
Line 1186... Line 1186...
1186
            __update_inventory_reservation(order)
1186
            __update_inventory_reservation(order)
1187
            order.statusDescription = "Order Cancelled"
1187
            order.statusDescription = "Order Cancelled"
1188
        elif order.status == OrderStatus.BILLED:
1188
        elif order.status == OrderStatus.BILLED:
1189
            __create_return_order(order)
1189
            __create_return_order(order)
1190
            order.statusDescription = "Order Cancelled"
1190
            order.statusDescription = "Order Cancelled"
1191
        elif order.status == OrderStatus.SALES_RET_RECEIVED:
1191
        elif order.status == OrderStatus.RTO_RECEIVED_PRESTINE:
1192
            __create_return_order(order)
1192
            __create_return_order(order)
1193
            order.statusDescription = "Order Returned to origin"
1193
            order.statusDescription = "Order Returned to origin"
1194
        elif order.status in [OrderStatus.DOA_CERT_INVALID, OrderStatus.DOA_CERT_VALID, OrderStatus.DOA_RECEIVED_DAMAGED, OrderStatus.DOA_LOST_IN_TRANSIT] :
1194
        elif order.status in [OrderStatus.DOA_CERT_INVALID, OrderStatus.DOA_CERT_VALID, OrderStatus.DOA_RECEIVED_DAMAGED, OrderStatus.DOA_LOST_IN_TRANSIT] :
1195
            __create_return_order(order)
1195
            __create_return_order(order)
1196
            __create_refund(order)
1196
            __create_refund(order)
Line 1201... Line 1201...
1201
                order.statusDescription = "Order Cancelled on customer request"
1201
                order.statusDescription = "Order Cancelled on customer request"
1202
            elif order.previousStatus == OrderStatus.BILLED:
1202
            elif order.previousStatus == OrderStatus.BILLED:
1203
                __create_return_order(order)
1203
                __create_return_order(order)
1204
                order.statusDescription = "Order Cancelled on customer request"
1204
                order.statusDescription = "Order Cancelled on customer request"
1205
    else:
1205
    else:
1206
        status_transition = {OrderStatus.SALES_RET_RECEIVED : OrderStatus.SALES_RET_REFUNDED,
1206
        status_transition = {OrderStatus.RTO_RECEIVED_PRESTINE : OrderStatus.RTO_REFUNDED,
1207
                     OrderStatus.DOA_CERT_INVALID : OrderStatus.DOA_INVALID_REFUNDED,
1207
                     OrderStatus.DOA_CERT_INVALID : OrderStatus.DOA_INVALID_REFUNDED,
1208
                     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,
1209
                     OrderStatus.DOA_RECEIVED_DAMAGED : OrderStatus.DOA_REFUNDED_RCVD_DAMAGED,
1210
                     OrderStatus.DOA_LOST_IN_TRANSIT : OrderStatus.DOA_REFUNDED_LOST_IN_TRANSIT,
1210
                     OrderStatus.DOA_LOST_IN_TRANSIT : OrderStatus.DOA_REFUNDED_LOST_IN_TRANSIT,
1211
                     OrderStatus.SUBMITTED_FOR_PROCESSING : OrderStatus.REFUNDED,
1211
                     OrderStatus.SUBMITTED_FOR_PROCESSING : OrderStatus.REFUNDED,
Line 1219... Line 1219...
1219
                     OrderStatus.PAYMENT_FLAGGED : OrderStatus.PAYMENT_FLAGGED_DENIED
1219
                     OrderStatus.PAYMENT_FLAGGED : OrderStatus.PAYMENT_FLAGGED_DENIED
1220
                     }
1220
                     }
1221
        if order.status not in status_transition.keys():
1221
        if order.status not in status_transition.keys():
1222
            raise TransactionServiceException(114, "This order can't be refunded")
1222
            raise TransactionServiceException(114, "This order can't be refunded")
1223
    
1223
    
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] :
1224
        if order.status in [OrderStatus.RTO_RECEIVED_PRESTINE, OrderStatus.DOA_CERT_INVALID, OrderStatus.DOA_CERT_VALID, OrderStatus.DOA_RECEIVED_DAMAGED, OrderStatus.DOA_LOST_IN_TRANSIT] :
1225
            __create_return_order(order)
1225
            __create_return_order(order)
1226
            __create_refund(order)
1226
            __create_refund(order)
1227
            order.statusDescription = "Order Refunded"
1227
            order.statusDescription = "Order Refunded"
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]:
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]:
1229
            __create_cancellation(order)
1229
            __create_cancellation(order)