Subversion Repositories SmartDukaan

Rev

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

Rev 4234 Rev 4247
Line 189... Line 189...
189
    transaction.status_message = description
189
    transaction.status_message = description
190
    if new_status == TransactionStatus.FAILED:
190
    if new_status == TransactionStatus.FAILED:
191
        for order in transaction.orders:
191
        for order in transaction.orders:
192
            order.status = OrderStatus.PAYMENT_FAILED
192
            order.status = OrderStatus.PAYMENT_FAILED
193
            order.statusDescription = "Payment Failed"
193
            order.statusDescription = "Payment Failed"
194
    elif new_status == TransactionStatus.AUTHORIZED:
194
    elif new_status == TransactionStatus.AUTHORIZED or new_status == TransactionStatus.FLAGGED:
195
        for order in transaction.orders:
195
        for order in transaction.orders:
-
 
196
            if new_status == TransactionStatus.AUTHORIZED:
196
            order.status = OrderStatus.SUBMITTED_FOR_PROCESSING
197
                order.status = OrderStatus.SUBMITTED_FOR_PROCESSING
197
            order.statusDescription = "Submitted to warehouse"
198
                order.statusDescription = "Submitted to warehouse"
-
 
199
            elif new_status == TransactionStatus.FLAGGED:
-
 
200
                order.status = OrderStatus.PAYMENT_FLAGGED
-
 
201
                order.statusDescription = "Payment flagged by gateway"
198
            order.cod = False
202
            order.cod = False
199
            #After we got payment success, we will set logistics info also 
203
            #After we got payment success, we will set logistics info also 
200
            logistics_client = LogisticsClient().get_client()
204
            logistics_client = LogisticsClient().get_client()
201
            #FIXME line item is only one now. If multiple will come, need to fix.
205
            #FIXME line item is only one now. If multiple will come, need to fix.
202
            item_id = order.lineitems[0].item_id
206
            item_id = order.lineitems[0].item_id
Line 256... Line 260...
256
        if new_status == TransactionStatus.COD_IN_PROCESS:
260
        if new_status == TransactionStatus.COD_IN_PROCESS:
257
            transaction_requiring_extra_processing = TransactionRequiringExtraProcessing()
261
            transaction_requiring_extra_processing = TransactionRequiringExtraProcessing()
258
            transaction_requiring_extra_processing.category = 'COD_VERIFICATION'
262
            transaction_requiring_extra_processing.category = 'COD_VERIFICATION'
259
            transaction_requiring_extra_processing.transaction_id = transaction_id
263
            transaction_requiring_extra_processing.transaction_id = transaction_id
260
            session.commit()
264
            session.commit()
-
 
265
        elif new_status == TransactionStatus.FLAGGED:
-
 
266
            transaction_requiring_extra_processing = TransactionRequiringExtraProcessing()
-
 
267
            transaction_requiring_extra_processing.category = 'PAYMENT_FLAGGED'
-
 
268
            transaction_requiring_extra_processing.transaction_id = transaction_id
-
 
269
            session.commit()
261
    except Exception as e:
270
    except Exception as e:
262
        print "Error inserting transaction Id: " + str(transaction_id) + " due to " + str(e)
271
        print "Error inserting transaction Id: " + str(transaction_id) + " due to " + str(e)
263
 
272
 
264
    return True
273
    return True
265
 
274
 
Line 1056... Line 1065...
1056
                     OrderStatus.DOA_CERT_VALID : OrderStatus.DOA_VALID_REFUNDED,
1065
                     OrderStatus.DOA_CERT_VALID : OrderStatus.DOA_VALID_REFUNDED,
1057
                     OrderStatus.INIT : OrderStatus.CANCELED,
1066
                     OrderStatus.INIT : OrderStatus.CANCELED,
1058
                     OrderStatus.SUBMITTED_FOR_PROCESSING : OrderStatus.CANCELED,
1067
                     OrderStatus.SUBMITTED_FOR_PROCESSING : OrderStatus.CANCELED,
1059
                     OrderStatus.INVENTORY_LOW : OrderStatus.CANCELED,
1068
                     OrderStatus.INVENTORY_LOW : OrderStatus.CANCELED,
1060
                     OrderStatus.ACCEPTED : OrderStatus.CANCELED,
1069
                     OrderStatus.ACCEPTED : OrderStatus.CANCELED,
1061
                     OrderStatus.BILLED : OrderStatus.CANCELED
1070
                     OrderStatus.BILLED : OrderStatus.CANCELED,
-
 
1071
                     OrderStatus.CANCEL_REQUEST_CONFIRMED : OrderStatus.CANCELLED_ON_CUSTOMER_REQUEST
1062
                     }
1072
                     }
1063
        if order.status not in status_transition.keys():
1073
        if order.status not in status_transition.keys():
1064
            raise TransactionServiceException(114, "This order can't be refunded")
1074
            raise TransactionServiceException(114, "This order can't be refunded")
1065
    
1075
    
1066
        if order.status < OrderStatus.BILLED:
1076
        if order.status < OrderStatus.BILLED:
Line 1074... Line 1084...
1074
            order.statusDescription = "Order Returned to origin"
1084
            order.statusDescription = "Order Returned to origin"
1075
        elif order.status in [OrderStatus.DOA_CERT_INVALID, OrderStatus.DOA_CERT_VALID] :
1085
        elif order.status in [OrderStatus.DOA_CERT_INVALID, OrderStatus.DOA_CERT_VALID] :
1076
            __create_return_order(order)
1086
            __create_return_order(order)
1077
            __create_refund(order)
1087
            __create_refund(order)
1078
            order.statusDescription = "Order Refunded"
1088
            order.statusDescription = "Order Refunded"
-
 
1089
        elif order.status == OrderStatus.CANCEL_REQUEST_CONFIRMED:
-
 
1090
            if order.previousStatus  < OrderStatus.BILLED:
-
 
1091
                __update_inventory_reservation(order)
-
 
1092
                order.statusDescription = "Order Cancelled on customer request"
-
 
1093
            elif order.previousStatus == OrderStatus.BILLED:
-
 
1094
                __create_return_order(order)
-
 
1095
                order.statusDescription = "Order Cancelled on customer request"
1079
    else:
1096
    else:
1080
        status_transition = {OrderStatus.SALES_RET_RECEIVED : OrderStatus.SALES_RET_REFUNDED,
1097
        status_transition = {OrderStatus.SALES_RET_RECEIVED : OrderStatus.SALES_RET_REFUNDED,
1081
                     OrderStatus.DOA_CERT_INVALID : OrderStatus.DOA_INVALID_REFUNDED,
1098
                     OrderStatus.DOA_CERT_INVALID : OrderStatus.DOA_INVALID_REFUNDED,
1082
                     OrderStatus.DOA_CERT_VALID : OrderStatus.DOA_VALID_REFUNDED,
1099
                     OrderStatus.DOA_CERT_VALID : OrderStatus.DOA_VALID_REFUNDED,
1083
                     OrderStatus.SUBMITTED_FOR_PROCESSING : OrderStatus.REFUNDED,
1100
                     OrderStatus.SUBMITTED_FOR_PROCESSING : OrderStatus.REFUNDED,
1084
                     OrderStatus.INVENTORY_LOW : OrderStatus.REFUNDED,
1101
                     OrderStatus.INVENTORY_LOW : OrderStatus.REFUNDED,
1085
                     OrderStatus.ACCEPTED : OrderStatus.REFUNDED,
1102
                     OrderStatus.ACCEPTED : OrderStatus.REFUNDED,
1086
                     OrderStatus.BILLED : OrderStatus.REFUNDED
1103
                     OrderStatus.BILLED : OrderStatus.REFUNDED,
-
 
1104
                     OrderStatus.CANCEL_REQUEST_CONFIRMED : OrderStatus.CANCELLED_ON_CUSTOMER_REQUEST,
-
 
1105
                     OrderStatus.PAYMENT_FLAGGED : OrderStatus.PAYMENT_FLAGGED_DENIED
1087
                     }
1106
                     }
1088
        if order.status not in status_transition.keys():
1107
        if order.status not in status_transition.keys():
1089
            raise TransactionServiceException(114, "This order can't be refunded")
1108
            raise TransactionServiceException(114, "This order can't be refunded")
1090
    
1109
    
1091
        if order.status in [OrderStatus.SALES_RET_RECEIVED, OrderStatus.DOA_CERT_INVALID, OrderStatus.DOA_CERT_VALID] :
1110
        if order.status in [OrderStatus.SALES_RET_RECEIVED, OrderStatus.DOA_CERT_INVALID, OrderStatus.DOA_CERT_VALID] :
Line 1094... Line 1113...
1094
            order.statusDescription = "Order Refunded"
1113
            order.statusDescription = "Order Refunded"
1095
        elif order.status in [OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.INVENTORY_LOW]:
1114
        elif order.status in [OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.INVENTORY_LOW]:
1096
            __create_cancellation(order)
1115
            __create_cancellation(order)
1097
            __update_inventory_reservation(order)
1116
            __update_inventory_reservation(order)
1098
            order.statusDescription = "Order Refunded"
1117
            order.statusDescription = "Order Refunded"
-
 
1118
        elif order.status == OrderStatus.CANCEL_REQUEST_CONFIRMED:
-
 
1119
            if order.previousStatus  < OrderStatus.BILLED:
-
 
1120
                __create_refund(order)
-
 
1121
                __update_inventory_reservation(order)
-
 
1122
                order.statusDescription = "Order Cancelled on customer request"
-
 
1123
            elif order.previousStatus == OrderStatus.BILLED:
-
 
1124
                __create_return_order(order)
-
 
1125
                __create_refund(order)
-
 
1126
                order.statusDescription = "Order Cancelled on customer request"
-
 
1127
        elif order.status == OrderStatus.PAYMENT_FLAGGED:
-
 
1128
            __create_refund(order)
-
 
1129
            __update_inventory_reservation(order)
-
 
1130
            order.statusDescription = "Order Cancelled due to payment flagged"
1099
 
1131
 
1100
    order.status = status_transition[order.status]
1132
    order.status = status_transition[order.status]
1101
    order.refund_timestamp = datetime.datetime.now()
1133
    order.refund_timestamp = datetime.datetime.now()
1102
    order.refunded_by = refunded_by
1134
    order.refunded_by = refunded_by
1103
    order.refund_reason = reason
1135
    order.refund_reason = reason
Line 1477... Line 1509...
1477
                quantity = quantity + item_wise_risky_orders_count[lineitem.item_id]
1509
                quantity = quantity + item_wise_risky_orders_count[lineitem.item_id]
1478
            
1510
            
1479
            item_wise_risky_orders_count[lineitem.item_id] = quantity
1511
            item_wise_risky_orders_count[lineitem.item_id] = quantity
1480
    return item_wise_risky_orders_count
1512
    return item_wise_risky_orders_count
1481
 
1513
 
-
 
1514
def mark_order_cancellation_request_received(orderId):
-
 
1515
    """
-
 
1516
    Mark order as cancellation request received. If customer sends request of cancellation of
-
 
1517
    a particular order, this method will be called. It will just change status of the order
-
 
1518
    depending on its current status. It also records the previous status, so that we can move
-
 
1519
    back to that status if cancellation request is denied.
-
 
1520
 
-
 
1521
    Parameters:
-
 
1522
     - orderId
-
 
1523
    """
-
 
1524
    status_transition = {OrderStatus.INIT : OrderStatus.CANCEL_REQUEST_RECEIVED,
-
 
1525
             OrderStatus.SUBMITTED_FOR_PROCESSING : OrderStatus.CANCEL_REQUEST_RECEIVED,
-
 
1526
             OrderStatus.INVENTORY_LOW : OrderStatus.CANCEL_REQUEST_RECEIVED,
-
 
1527
             OrderStatus.ACCEPTED : OrderStatus.CANCEL_REQUEST_RECEIVED,
-
 
1528
             OrderStatus.BILLED : OrderStatus.CANCEL_REQUEST_RECEIVED,
-
 
1529
             OrderStatus.PAYMENT_FLAGGED : OrderStatus.CANCEL_REQUEST_RECEIVED
-
 
1530
             }
-
 
1531
    if order.status not in status_transition.keys():
-
 
1532
        raise TransactionServiceException(114, "This order can't be considered for cancellation")
-
 
1533
 
-
 
1534
    order = get_order(orderId)
-
 
1535
    order.previousStatus = order.status
-
 
1536
    order.status = OrderStatus.CANCEL_REQUEST_RECEIVED
-
 
1537
    order.statusDescription = "Cancellation request received from user"
-
 
1538
    session.commit()
-
 
1539
    
-
 
1540
def mark_order_as_payment_flag_removed(orderId):
-
 
1541
    """
-
 
1542
    If we and/or payment has decided to accept the order, this method needs to be called.
-
 
1543
    Changed order status and payment status
-
 
1544
 
-
 
1545
    Parameters:
-
 
1546
     - orderId
-
 
1547
    """
-
 
1548
    order = get_order(orderId)
-
 
1549
    order.status = OrderStatus.SUBMITTED_FOR_PROCESSING
-
 
1550
    order.statusDescription = "Submitted to warehouse"
-
 
1551
    session.commit()
-
 
1552
    
-
 
1553
def mark_order_cancellation_request_denied(orderId):
-
 
1554
    """
-
 
1555
    If we decide to not to cancel order, we will move the order ro previous status.
-
 
1556
    
-
 
1557
    Parameters:
-
 
1558
     - orderId
-
 
1559
    """
-
 
1560
    order = get_order(orderId)
-
 
1561
    order.status = order.previousStatus
-
 
1562
    order.previousStatus = None
-
 
1563
    order.statusDescription = "Cancellation request denied"
-
 
1564
    session.commit()
-
 
1565
    
-
 
1566
def mark_order_cancellation_request_confirmed(orderId):
-
 
1567
    """
-
 
1568
    If we decide to to cancel order, CRM will call this method to move the status of order to
-
 
1569
    cancellation request confirmed. After this OM will be able to cancel the order.
-
 
1570
 
-
 
1571
    Parameters:
-
 
1572
     - orderId
-
 
1573
    """
-
 
1574
    order = get_order(orderId)
-
 
1575
    order.status = OrderStatus.CANCEL_REQUEST_CONFIRMED
-
 
1576
    order.statusDescription = "Cancellation request confirmed"
-
 
1577
    session.commit()
-
 
1578
    
-
 
1579
            
1482
def close_session():
1580
def close_session():
1483
    if session.is_active:
1581
    if session.is_active:
1484
        print "session is active. closing it."
1582
        print "session is active. closing it."
1485
        session.close()
1583
        session.close()
1486
 
1584