Subversion Repositories SmartDukaan

Rev

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

Rev 3553 Rev 3578
Line 50... Line 50...
50
 
50
 
51
ORDER_STATUS_TO_USER_TRUST_LEVEL_DELTA_DICT = {
51
ORDER_STATUS_TO_USER_TRUST_LEVEL_DELTA_DICT = {
52
        OrderStatus.SALES_RET_RESHIPPED     :  3,
52
        OrderStatus.SALES_RET_RESHIPPED     :  3,
53
        OrderStatus.SALES_RETURN_IN_TRANSIT : -5,
53
        OrderStatus.SALES_RETURN_IN_TRANSIT : -5,
54
        OrderStatus.DELIVERY_SUCCESS        :  1,
54
        OrderStatus.DELIVERY_SUCCESS        :  1,
55
        OrderStatus.DOA_CERT_INVALID        : -5,
55
        OrderStatus.DOA_CERT_INVALID        : -5
56
}
56
}
57
 
57
 
58
def get_new_transaction():
58
def get_new_transaction():
59
    transaction = Transaction()
59
    transaction = Transaction()
60
    transaction.createdOn = datetime.datetime.now()
60
    transaction.createdOn = datetime.datetime.now()
Line 480... Line 480...
480
def change_order_status(self, orderId, status, description):
480
def change_order_status(self, orderId, status, description):
481
    order = get_order(orderId)
481
    order = get_order(orderId)
482
    order.status = status
482
    order.status = status
483
    order.statusDescription = description
483
    order.statusDescription = description
484
    session.commit()
484
    session.commit()
-
 
485
    update_trust_level(order)
-
 
486
    return True
485
 
487
 
-
 
488
def update_trust_level(order):
486
    try:
489
    try:
487
        trust_level_delta = compute_trust_level_delta(order)
490
        trust_level_delta = 0
-
 
491
        if order.cod == True:
-
 
492
            trust_level_delta = ORDER_STATUS_TO_USER_TRUST_LEVEL_DELTA_DICT.get(order.status, 0)
-
 
493
 
488
        if (trust_level_delta != 0):
494
        if (trust_level_delta != 0):
489
            user_client = UserClient().get_client()
495
            user_client = UserClient().get_client()
490
            user_client.increaseTrustLevel(order.customer_id, trust_level_delta)
496
            user_client.increaseTrustLevel(order.customer_id, trust_level_delta)
491
    except Exception as e:
497
    except Exception as e:
492
        print e
498
        print e
493
 
499
 
494
    return True
500
    return True
495
 
501
 
496
def compute_trust_level_delta(order):
-
 
497
    trust_level_delta = 0
-
 
498
 
-
 
499
    if order.cod == True:
-
 
500
        trust_level_delta = ORDER_STATUS_TO_USER_TRUST_LEVEL_DELTA_DICT.get(order.status, 0)
-
 
501
 
-
 
502
    return trust_level_delta
-
 
503
 
-
 
504
def verify_order(self, orderId):
502
def verify_order(self, orderId):
505
    logging.info("Verifying order no: " + str(orderId))
503
    logging.info("Verifying order no: " + str(orderId))
506
    order = get_order(orderId)
504
    order = get_order(orderId)
507
    if order.status == OrderStatus.INIT:
505
    if order.status == OrderStatus.INIT:
508
        order.status = OrderStatus.SUBMITTED_FOR_PROCESSING
506
        order.status = OrderStatus.SUBMITTED_FOR_PROCESSING
Line 659... Line 657...
659
            continue
657
            continue
660
            #raise TransactionServiceException(103, "No order found for the awb:" + awb)
658
            #raise TransactionServiceException(103, "No order found for the awb:" + awb)
661
        order.status = OrderStatus.DELIVERY_SUCCESS
659
        order.status = OrderStatus.DELIVERY_SUCCESS
662
        order.statusDescription = "Order delivered"
660
        order.statusDescription = "Order delivered"
663
        order.delivery_timestamp, order.receiver = detail.split('|')
661
        order.delivery_timestamp, order.receiver = detail.split('|')
-
 
662
        update_trust_level(order)
664
    session.commit()
663
    session.commit()
665
 
664
 
666
def mark_orders_as_failed(provider_id, returned_orders):
665
def mark_orders_as_failed(provider_id, returned_orders):
667
    for awb, detail in returned_orders.iteritems():
666
    for awb, detail in returned_orders.iteritems():
668
        order = Order.query.filter_by(airwaybill_no=awb, logistics_provider_id = provider_id).first()
667
        order = Order.query.filter_by(airwaybill_no=awb, logistics_provider_id = provider_id).first()
Line 670... Line 669...
670
            continue
669
            continue
671
            #raise TransactionServiceException(103, "No order found for the awb:" + awb)
670
            #raise TransactionServiceException(103, "No order found for the awb:" + awb)
672
        order.status = OrderStatus.SALES_RETURN_IN_TRANSIT
671
        order.status = OrderStatus.SALES_RETURN_IN_TRANSIT
673
        order.delivery_timestamp, reason = detail.split('|')
672
        order.delivery_timestamp, reason = detail.split('|')
674
        order.statusDescription = "Order Returned to Origin:" + reason
673
        order.statusDescription = "Order Returned to Origin:" + reason
-
 
674
        update_trust_level(order)
675
    session.commit()
675
    session.commit()
676
 
676
 
677
def update_non_delivery_reason(provider_id, undelivered_orders):
677
def update_non_delivery_reason(provider_id, undelivered_orders):
678
    for awb, reason in undelivered_orders.iteritems():
678
    for awb, reason in undelivered_orders.iteritems():
679
        order = Order.query.filter_by(airwaybill_no=awb, logistics_provider_id = provider_id).first()
679
        order = Order.query.filter_by(airwaybill_no=awb, logistics_provider_id = provider_id).first()
Line 913... Line 913...
913
        order.status = OrderStatus.DOA_CERT_VALID
913
        order.status = OrderStatus.DOA_CERT_VALID
914
        order.statusDescription = "DOA Certificate Valid"
914
        order.statusDescription = "DOA Certificate Valid"
915
    else:
915
    else:
916
        order.status = OrderStatus.DOA_CERT_INVALID
916
        order.status = OrderStatus.DOA_CERT_INVALID
917
        order.statusDescription = "DOA Certificate Invalid"
917
        order.statusDescription = "DOA Certificate Invalid"
-
 
918
        update_trust_level(order)
918
    session.commit()
919
    session.commit()
919
    return True
920
    return True
920
 
921
 
921
def reship_order(order_id):
922
def reship_order(order_id):
922
    """
923
    """
Line 940... Line 941...
940
    if order.status == OrderStatus.SALES_RET_RECEIVED:
941
    if order.status == OrderStatus.SALES_RET_RECEIVED:
941
        new_order = __clone_order(order, True)
942
        new_order = __clone_order(order, True)
942
        order.status = OrderStatus.SALES_RET_RESHIPPED
943
        order.status = OrderStatus.SALES_RET_RESHIPPED
943
        order.statusDescription = "Order Reshipped"
944
        order.statusDescription = "Order Reshipped"
944
        session.commit()
945
        session.commit()
-
 
946
        update_trust_level(order)
945
    elif order.status == OrderStatus.DOA_CERT_INVALID:
947
    elif order.status == OrderStatus.DOA_CERT_INVALID:
946
        new_order = __clone_order(order, True)
948
        new_order = __clone_order(order, True)
947
        order.status = OrderStatus.DOA_INVALID_RESHIPPED
949
        order.status = OrderStatus.DOA_INVALID_RESHIPPED
948
        order.statusDescription = "Order Reshipped"
950
        order.statusDescription = "Order Reshipped"
949
        session.commit()
951
        session.commit()