Subversion Repositories SmartDukaan

Rev

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

Rev 20123 Rev 20167
Line 3948... Line 3948...
3948
        
3948
        
3949
    order.status = status_transition[order.status]
3949
    order.status = status_transition[order.status]
3950
    order.refund_timestamp = datetime.datetime.now()
3950
    order.refund_timestamp = datetime.datetime.now()
3951
    order.refunded_by = refunded_by
3951
    order.refunded_by = refunded_by
3952
    order.refund_reason = reason
3952
    order.refund_reason = reason
-
 
3953
    #to re evaluate the shipping charge if any order is being cancelled.
-
 
3954
    _revaluate_shiping(order_id)
3953
    session.commit()
3955
    session.commit()
3954
    return True
3956
    return True
3955
 
3957
 
-
 
3958
def _revaluate_shiping(orderId):
-
 
3959
    orders = Order.get_by(id = orderId)
-
 
3960
    totalCartVal=0
-
 
3961
    totalshippingCost=0
-
 
3962
    if orders:
-
 
3963
        ordersList = get_orders_for_transaction(orders.transaction_id, orders.customer_id)
-
 
3964
        for order in ordersList:
-
 
3965
            if order.status == OrderStatus.CANCELLED_DUE_TO_LOW_INVENTORY or order.shipping_timestamp is not None:
-
 
3966
                return
-
 
3967
            
-
 
3968
            if order.status not in [OrderStatus.COD_VERIFICATION_FAILED,OrderStatus.CANCELLED_ON_CUSTOMER_REQUEST,OrderStatus.CANCELLED_DUE_TO_LOW_INVENTORY]:
-
 
3969
                for line in order.lineitems:
-
 
3970
                    totalCartVal = totalCartVal+line.total_price
-
 
3971
                
-
 
3972
        if totalCartVal < 500 and totalCartVal>0:
-
 
3973
            totalshippingCost = 100
-
 
3974
        elif totalCartVal >=500 and totalCartVal<1000:
-
 
3975
            totalshippingCost = 50
-
 
3976
            
-
 
3977
        shippingCostInOrders=0
-
 
3978
        shipUpdateOrder= None
-
 
3979
        if totalshippingCost > 0:
-
 
3980
            for order in ordersList:
-
 
3981
                if order.status not in [OrderStatus.COD_VERIFICATION_FAILED,OrderStatus.CANCELLED_ON_CUSTOMER_REQUEST,OrderStatus.CANCELLED_DUE_TO_LOW_INVENTORY]:
-
 
3982
                    for line in order.lineitems:
-
 
3983
                        order.shippingCost = round((line.total_price*totalshippingCost)/totalCartVal, 0)
-
 
3984
                    
-
 
3985
                    shippingCostInOrders = shippingCostInOrders + order.shippingCost
-
 
3986
                    if shipUpdateOrder is None:
-
 
3987
                        shipUpdateOrder = order
-
 
3988
                        
-
 
3989
            if shipUpdateOrder is not None:
-
 
3990
                diff = totalshippingCost - shippingCostInOrders
-
 
3991
                if diff>0:
-
 
3992
                    shipUpdateOrder.shippingCost = shipUpdateOrder.shippingCost + diff
-
 
3993
            
-
 
3994
            
-
 
3995
 
3956
def __update_inventory_reservation(order):
3996
def __update_inventory_reservation(order):
3957
    '''
3997
    '''
3958
    Reduce the reservation count for all line items of the given order.
3998
    Reduce the reservation count for all line items of the given order.
3959
    '''
3999
    '''
3960
    try:
4000
    try: