Subversion Repositories SmartDukaan

Rev

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

Rev 4447 Rev 4452
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_RESHIPPED, OrderStatus.CANCELED)))).count()
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()
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 867... Line 867...
867
    session.commit()
867
    session.commit()
868
    return order.doaFlag
868
    return order.doaFlag
869
 
869
 
870
def request_pickup_number(order_id):
870
def request_pickup_number(order_id):
871
    order = get_order(order_id)
871
    order = get_order(order_id)
872
    if order.status != OrderStatus.DELIVERY_SUCCESS and order.status != OrderStatus.DOA_PICKUP_REQUESTED:
872
    if order.status != OrderStatus.DELIVERY_SUCCESS and order.status != OrderStatus.DOA_PICKUP_REQUEST_RAISED:
873
        return False
873
        return False
874
    from_user = 'cnc.center@shop2020.in'
874
    from_user = 'cnc.center@shop2020.in'
875
    from_pwd = '5h0p2o2o'
875
    from_pwd = '5h0p2o2o'
876
    
876
    
877
    subject = "Pickup request from " + order.customer_city
877
    subject = "Pickup request from " + order.customer_city
Line 912... Line 912...
912
                                          'warehouse_address' : warehouse.location,
912
                                          'warehouse_address' : warehouse.location,
913
                                          'warehouse_pin' : warehouse.pincode,
913
                                          'warehouse_pin' : warehouse.pincode,
914
                                          'warehouse_phone': '9971573026'}
914
                                          'warehouse_phone': '9971573026'}
915
        #FIXME Email is hardcoded for bluedart
915
        #FIXME Email is hardcoded for bluedart
916
        mail(from_user, from_pwd, [to_addr, 'sonikap@bluedart.com'], subject, message)
916
        mail(from_user, from_pwd, [to_addr, 'sonikap@bluedart.com'], subject, message)
917
        order.status = OrderStatus.DOA_PICKUP_REQUESTED
917
        order.status = OrderStatus.DOA_PICKUP_REQUEST_RAISED
918
        order.statusDescription = "Pick up requested for DOA"
918
        order.statusDescription = "Pick up requested for DOA"
919
        session.commit()
919
        session.commit()
920
        return True
920
        return True
921
    except Exception as e:
921
    except Exception as e:
922
        print sys.exc_info()[0]
922
        print sys.exc_info()[0]
923
        return False
923
        return False
924
 
924
 
925
def authorize_pickup(order_id, pickup_number):
925
def authorize_pickup(order_id, pickup_number):
926
    order = get_order(order_id)
926
    order = get_order(order_id)
927
    if order.status != OrderStatus.DOA_PICKUP_REQUESTED:
927
    if order.status != OrderStatus.DOA_PICKUP_REQUEST_RAISED:
928
        return False
928
        return False
929
    from_user = 'help@shop2020.in'
929
    from_user = 'help@shop2020.in'
930
    from_pwd = '5h0p2o2o'
930
    from_pwd = '5h0p2o2o'
931
    subject = 'Pickup details'
931
    subject = 'Pickup details'
932
    filename = "/tmp/" +  str(order.id) +".pdf" 
932
    filename = "/tmp/" +  str(order.id) +".pdf" 
Line 965... Line 965...
965
                                         'customer_address' : __get_order_address(order)}
965
                                         'customer_address' : __get_order_address(order)}
966
        print message
966
        print message
967
        __generate_return_advice(order, warehouse, provider, filename)
967
        __generate_return_advice(order, warehouse, provider, filename)
968
        mail(from_user, from_pwd, [to_addr], subject, message, [get_attachment_part(filename)])
968
        mail(from_user, from_pwd, [to_addr], subject, message, [get_attachment_part(filename)])
969
        order.pickupRequestNo = pickup_number
969
        order.pickupRequestNo = pickup_number
970
        order.status = OrderStatus.DOA_RETURN_AUTHORIZED
970
        order.status = OrderStatus.DOA_PICKUP_CONFIRMED
971
        order.statusDescription = "DOA pick up authorized"
971
        order.statusDescription = "DOA pick up confirmed"
972
        order.doa_auth_timestamp = datetime.datetime.now()
972
        order.doa_auth_timestamp = datetime.datetime.now()
973
        session.commit()
973
        session.commit()
974
        return True
974
        return True
975
    except Exception as e:
975
    except Exception as e:
976
        print sys.exc_info()
976
        print sys.exc_info()
Line 981... Line 981...
981
            os.remove(filename)
981
            os.remove(filename)
982
 
982
 
983
def mark_doas_as_picked_up(provider_id, pickup_details):
983
def mark_doas_as_picked_up(provider_id, pickup_details):
984
    for pickupNo, doa_pickup_timestamp in pickup_details.iteritems():
984
    for pickupNo, doa_pickup_timestamp in pickup_details.iteritems():
985
        order = Order.query.filter_by(pickupRequestNo=pickupNo, logistics_provider_id = provider_id).first()
985
        order = Order.query.filter_by(pickupRequestNo=pickupNo, logistics_provider_id = provider_id).first()
986
        if order == None or order.status != OrderStatus.DOA_RETURN_AUTHORIZED:
986
        if order == None or order.status != OrderStatus.DOA_PICKUP_CONFIRMED:
987
            #raise TransactionServiceException(102, "No order found for the awb: " + awb)
987
            #raise TransactionServiceException(102, "No order found for the awb: " + awb)
988
            continue
988
            continue
989
        order.status = OrderStatus.DOA_RETURN_IN_TRANSIT
989
        order.status = OrderStatus.DOA_RETURN_IN_TRANSIT
990
        order.statusDescription = "DOA picked up by Courier Company"
990
        order.statusDescription = "DOA picked up by Courier Company"
991
        order.doa_pickup_timestamp = doa_pickup_timestamp
991
        order.doa_pickup_timestamp = doa_pickup_timestamp
992
    session.commit()
992
    session.commit()
993
 
993
 
994
    current_time = datetime.datetime.now()
994
    current_time = datetime.datetime.now()
995
    to_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)
995
    to_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)
996
    from_datetime = to_datetime - datetime.timedelta(2)
996
    from_datetime = to_datetime - datetime.timedelta(2)
997
    orders_not_picked_up = Order.query.filter_by(logistics_provider_id = provider_id).filter_by(status=OrderStatus.DOA_RETURN_AUTHORIZED).filter(Order.doa_auth_timestamp >= from_datetime).filter(Order.doa_auth_timestamp <= to_datetime).all()
997
    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()
998
    return orders_not_picked_up
998
    return orders_not_picked_up
999
 
999
 
1000
def receive_return(order_id):
1000
def receive_return(order_id):
1001
    order = get_order(order_id)
1001
    order = get_order(order_id)
1002
 
1002
 
Line 1009... Line 1009...
1009
            # Inventory should not be updated for DOA returns 
1009
            # Inventory should not be updated for DOA returns 
1010
            if order.status == OrderStatus.SALES_RETURN_IN_TRANSIT:
1010
            if order.status == OrderStatus.SALES_RETURN_IN_TRANSIT:
1011
                warehouse_client.scanIn(order.id, lineitem.item_number, lineitem.imei_number, ScanType.SALE_RET)
1011
                warehouse_client.scanIn(order.id, lineitem.item_number, lineitem.imei_number, ScanType.SALE_RET)
1012
                catalog_client = CatalogClient().get_client()
1012
                catalog_client = CatalogClient().get_client()
1013
                catalog_client.reduceReservationCount(lineitem.item_id, order.warehouse_id, lineitem.quantity)
1013
                catalog_client.reduceReservationCount(lineitem.item_id, order.warehouse_id, lineitem.quantity)
1014
            elif order.status in [OrderStatus.DOA_RETURN_AUTHORIZED, OrderStatus.DOA_RETURN_IN_TRANSIT]:
1014
            elif order.status in [OrderStatus.DOA_PICKUP_CONFIRMED, OrderStatus.DOA_RETURN_IN_TRANSIT]:
1015
                warehouse_client.scanIn(order.id, lineitem.item_number, lineitem.imei_number, ScanType.DOA_IN)
1015
                warehouse_client.scanIn(order.id, lineitem.item_number, lineitem.imei_number, ScanType.DOA_IN)
1016
        except:
1016
        except:
1017
            print sys.exc_info()[0]
1017
            print sys.exc_info()[0]
1018
            print 'Could not scan in sales return orders'
1018
            print 'Could not scan in sales return orders'
1019
 
1019
 
1020
    if order.status in [OrderStatus.DOA_RETURN_AUTHORIZED, OrderStatus.DOA_RETURN_IN_TRANSIT]:
1020
    if order.status in [OrderStatus.DOA_PICKUP_CONFIRMED, OrderStatus.DOA_RETURN_IN_TRANSIT]:
1021
        order.status = OrderStatus.DOA_RECEIVED
1021
        order.status = OrderStatus.DOA_RECEIVED_PRESTINE
1022
        order.statusDescription = "DOA package received"
1022
        order.statusDescription = "DOA package received"
1023
        order.received_return_timestamp = datetime.datetime.now()
1023
        order.received_return_timestamp = datetime.datetime.now()
1024
        session.commit()
1024
        session.commit()
1025
    elif order.status == OrderStatus.SALES_RETURN_IN_TRANSIT :
1025
    elif order.status == OrderStatus.SALES_RETURN_IN_TRANSIT :
1026
        order.status = OrderStatus.SALES_RET_RECEIVED
1026
        order.status = OrderStatus.SALES_RET_RECEIVED
Line 1031... Line 1031...
1031
        return False
1031
        return False
1032
    return True
1032
    return True
1033
 
1033
 
1034
def validate_doa(order_id, is_valid):
1034
def validate_doa(order_id, is_valid):
1035
    order = get_order(order_id)
1035
    order = get_order(order_id)
1036
    if order.status != OrderStatus.DOA_RECEIVED:
1036
    if order.status != OrderStatus.DOA_RECEIVED_PRESTINE:
1037
        return False
1037
        return False
1038
    if is_valid:
1038
    if is_valid:
1039
        order.status = OrderStatus.DOA_CERT_VALID
1039
        order.status = OrderStatus.DOA_CERT_VALID
1040
        order.statusDescription = "DOA Certificate Valid"
1040
        order.statusDescription = "DOA Certificate Valid"
1041
    else:
1041
    else:
Line 1052... Line 1052...
1052
        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.
1052
        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.
1053
        
1053
        
1054
    If the order is in DOA_CERT_VALID state, it does the following:
1054
    If the order is in DOA_CERT_VALID state, it does the following:
1055
        1. Creates a new order for processing in the SUBMITTED_FOR_PROCESSING state.
1055
        1. Creates a new order for processing in the SUBMITTED_FOR_PROCESSING state.
1056
        2. Creates a return order for the warehouse executive to return the DOA material.
1056
        2. Creates a return order for the warehouse executive to return the DOA material.
1057
        3. Marks the current order as the final DOA_RESHIPPED state.
1057
        3. Marks the current order as the final DOA_VALID_RESHIPPED state.
1058
    
1058
    
1059
    Returns the id of the newly created order.
1059
    Returns the id of the newly created order.
1060
    
1060
    
1061
    Throws an exception if the order with the given id couldn't be found.
1061
    Throws an exception if the order with the given id couldn't be found.
1062
    
1062
    
Line 1076... Line 1076...
1076
        order.statusDescription = "Order Reshipped"
1076
        order.statusDescription = "Order Reshipped"
1077
        session.commit()
1077
        session.commit()
1078
    elif order.status == OrderStatus.DOA_CERT_VALID:
1078
    elif order.status == OrderStatus.DOA_CERT_VALID:
1079
        new_order = __clone_order(order, False, False)
1079
        new_order = __clone_order(order, False, False)
1080
        ret_order = __create_return_order(order)
1080
        ret_order = __create_return_order(order)
1081
        order.status = OrderStatus.DOA_RESHIPPED
1081
        order.status = OrderStatus.DOA_VALID_RESHIPPED
1082
        order.statusDescription = "Order Reshipped"
1082
        order.statusDescription = "Order Reshipped"
1083
        session.commit()
1083
        session.commit()
1084
    else:
1084
    else:
1085
        raise TransactionServiceException(112, "This order can't be reshipped")
1085
        raise TransactionServiceException(112, "This order can't be reshipped")
1086
    
1086