Subversion Repositories SmartDukaan

Rev

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

Rev 3216 Rev 3226
Line 906... Line 906...
906
    order.new_order_id = new_order.id
906
    order.new_order_id = new_order.id
907
    session.commit()
907
    session.commit()
908
    
908
    
909
    return new_order.id
909
    return new_order.id
910
 
910
 
911
def refund_order(order_id):
911
def refund_order(order_id, refunded_by, reason):
912
    """
912
    """
913
    If the order is in SALES_RET_RECEIVED, DOA_CERT_VALID or DOA_CERT_INVALID state, it does the following:
913
    If the order is in SALES_RET_RECEIVED, DOA_CERT_VALID or DOA_CERT_INVALID state, it does the following:
914
        1. Creates a refund request for batch processing.
914
        1. Creates a refund request for batch processing.
915
        2. Creates a return order for the warehouse executive to return the shipped material.
915
        2. Creates a return order for the warehouse executive to return the shipped material.
916
        3. Marks the current order as SALES_RET_REFUNDED, DOA_VALID_REFUNDED or DOA_INVALID_REFUNDED final states.
916
        3. Marks the current order as SALES_RET_REFUNDED, DOA_VALID_REFUNDED or DOA_INVALID_REFUNDED final states.
917
    
917
    
918
    If the order is in SUBMITTED_FOR_PROCESSING or INVENTORY_LOW state, it does the following:
918
    If the order is in SUBMITTED_FOR_PROCESSING or INVENTORY_LOW state, it does the following:
919
        1. Creates a refund request for batch processing.
919
        1. Creates a refund request for batch processing.
-
 
920
        2. Cancels the reservation of the item in the warehouse.
920
        2. Marks the current order as the REFUNDED final state.
921
        3. Marks the current order as the REFUNDED final state.
921
    
922
    
-
 
923
    For all COD orders, if the order is in INIT, SUBMITTED_FOR_PROCESSING or INVENTORY_LOW state, it does the following:
-
 
924
        1. Cancels the reservation of the item in the warehouse.
-
 
925
        2. Marks the current order as CANCELED.
-
 
926
        
-
 
927
    In all cases, it updates the reason for cancellation or refund and the person who performed the action.
-
 
928
     
922
    Returns True if it is successful.
929
    Returns True if it is successful, False otherwise.
923
    
930
    
924
    Throws an exception if the order with the given id couldn't be found.
931
    Throws an exception if the order with the given id couldn't be found.
925
    
932
    
926
    Parameters:
933
    Parameters:
927
     - orderId
934
     - order_id
-
 
935
     - refunded_by
-
 
936
     - reason
928
    """
937
    """
929
    status_transition = {OrderStatus.SALES_RET_RECEIVED : OrderStatus.SALES_RET_REFUNDED,
938
    status_transition = {OrderStatus.SALES_RET_RECEIVED : OrderStatus.SALES_RET_REFUNDED,
930
                         OrderStatus.DOA_CERT_INVALID : OrderStatus.DOA_INVALID_REFUNDED,
939
                         OrderStatus.DOA_CERT_INVALID : OrderStatus.DOA_INVALID_REFUNDED,
931
                         OrderStatus.DOA_CERT_VALID : OrderStatus.DOA_VALID_REFUNDED,
940
                         OrderStatus.DOA_CERT_VALID : OrderStatus.DOA_VALID_REFUNDED,
932
                         OrderStatus.INIT : OrderStatus.CANCELED,
941
                         OrderStatus.INIT : OrderStatus.CANCELED,
Line 936... Line 945...
936
    order = get_order(order_id)
945
    order = get_order(order_id)
937
    
946
    
938
    if order.status not in status_transition.keys():
947
    if order.status not in status_transition.keys():
939
        raise TransactionServiceException(114, "This order can't be refunded")
948
        raise TransactionServiceException(114, "This order can't be refunded")
940
    
949
    
941
    if order.status == OrderStatus.INIT:
950
    if order.cod:
-
 
951
        if order.status in [OrderStatus.INIT, OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.INVENTORY_LOW]:
942
        __update_inventory_reservation(order)
952
            __update_inventory_reservation(order)
943
        order.statusDescription = "Order Cancelled"
953
            order.statusDescription = "Order Cancelled"
944
    elif order.status in [OrderStatus.SALES_RET_RECEIVED, OrderStatus.DOA_CERT_INVALID, OrderStatus.DOA_CERT_VALID] :
954
        elif order.status in [OrderStatus.SALES_RET_RECEIVED, OrderStatus.DOA_CERT_INVALID, OrderStatus.DOA_CERT_VALID] :
945
        __create_return_order(order)
955
            __create_return_order(order)
946
        __create_refund(order)
956
            __create_refund(order)
947
        order.statusDescription = "Order Refunded"
957
            order.statusDescription = "Order Refunded"
-
 
958
    else:
948
    elif order.status in [OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.INVENTORY_LOW]:
959
        if order.status in [OrderStatus.SALES_RET_RECEIVED, OrderStatus.DOA_CERT_INVALID, OrderStatus.DOA_CERT_VALID] :
-
 
960
            __create_return_order(order)
949
        if not order.cod:
961
            __create_refund(order)
-
 
962
            order.statusDescription = "Order Refunded"
-
 
963
        elif order.status in [OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.INVENTORY_LOW]:
950
            __create_cancellation(order)
964
            __create_cancellation(order)
951
        __update_inventory_reservation(order)
965
            __update_inventory_reservation(order)
952
        order.statusDescription = "Order Refunded"
966
            order.statusDescription = "Order Refunded"
953
 
967
 
954
    order.status = status_transition[order.status]
968
    order.status = status_transition[order.status]
955
    order.refund_timestamp = datetime.datetime.now()
969
    order.refund_timestamp = datetime.datetime.now()
-
 
970
    order.refunded_by = refunded_by
-
 
971
    order.refund_reason = reason
956
    
972
    
957
    session.commit()
973
    session.commit()
958
    return True
974
    return True
959
 
975
 
960
def __update_inventory_reservation(order):
976
def __update_inventory_reservation(order):