Subversion Repositories SmartDukaan

Rev

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

Rev 11653 Rev 11655
Line 557... Line 557...
557
    datas = []
557
    datas = []
558
    for line in lines:
558
    for line in lines:
559
        datas.append(line[0])
559
        datas.append(line[0])
560
    return datas
560
    return datas
561
 
561
 
562
def insure_item_common(cart, line, toInsure, insurerType):
562
def insure_item(itemId, cartId, toInsure, insurerType):
-
 
563
    cart = Cart.get_by(id = cartId)
-
 
564
    line = None
-
 
565
    for cartLine in cart.lines:
-
 
566
        if(cartLine.item_id == itemId):
-
 
567
            line = cartLine
-
 
568
            break
-
 
569
        
-
 
570
    if not line:
-
 
571
        print("Error : No line found for cartId : " + cartId + " and itemId : " + itemId)
-
 
572
        return False
-
 
573
    
563
    try:
574
    try:
564
        if toInsure:
575
        if toInsure:
565
            csc = CatalogClient().get_client()
576
            csc = CatalogClient().get_client()
566
            item = csc.getItem(itemId)
577
            item = csc.getItem(itemId)
567
            insurerId = csc.getPrefferedInsurerForItem(itemId,insurerType)
578
            insurerId = csc.getPrefferedInsurerForItem(itemId,insurerType)
Line 597... Line 608...
597
        print("Error : Unable to insure")
608
        print("Error : Unable to insure")
598
        print("insurerId : " + str(insurerId) + " ItemId : " + str(itemId) + " CartId : " + str(cartId))
609
        print("insurerId : " + str(insurerId) + " ItemId : " + str(itemId) + " CartId : " + str(cartId))
599
        return False
610
        return False
600
    
611
    
601
    return True
612
    return True
602
    
-
 
603
def insure_item(itemId, cartId, toInsure, insurerType):
-
 
604
    cart = Cart.get_by(id = cartId)
-
 
605
    line = None
-
 
606
    for cartLine in cart.lines:
-
 
607
        if(cartLine.item_id == itemId):
-
 
608
            line = cartLine
-
 
609
            break
-
 
610
        
-
 
611
    if not line:
-
 
612
        print("Error : No line found for cartId : " + cartId + " and itemId : " + itemId)
-
 
613
        return False
-
 
614
    
-
 
615
 
613
 
616
def cancel_insurance(cartId):
614
def cancel_insurance(cartId):
617
    try:
615
    try:
618
        cart = Cart.get_by(id = cartId)
616
        cart = Cart.get_by(id = cartId)
619
        for cartLine in cart.lines:
617
        for cartLine in cart.lines:
Line 653... Line 651...
653
    except:
651
    except:
654
        print("Error : Unable to get insurance details for addressId : " + str(addressId))
652
        print("Error : Unable to get insurance details for addressId : " + str(addressId))
655
        return False
653
        return False
656
    return True
654
    return True
657
 
655
 
658
def validate_cart_plus(cartId, source_id):
656
def validate_cart_plus(cart_id, source_id):
659
    inventory_client = CatalogClient().get_client()
-
 
660
    logistics_client = LogisticsClient().get_client()
-
 
661
    promotion_client = PromotionClient().get_client()
-
 
662
    retval = ""
-
 
663
    emival = ""
-
 
664
    # No need to validate duplicate items since there are only two ways
-
 
665
    # to add items to a cart and both of them check whether the item being
-
 
666
    # added is a duplicate of an already existing item.
-
 
667
    found_cart = cart = Cart.get_by(id=cartId)
-
 
668
    cart_lines = cart.lines
-
 
669
    customer_pincode = None
-
 
670
    current_time = datetime.datetime.now()
-
 
671
    if cart.pickupStoreId :
-
 
672
        store = logistics_client.getPickupStore(cart.pickupStoreId)
-
 
673
        customer_pincode = store.pin
-
 
674
    if cart.address_id != None and customer_pincode == None:
-
 
675
        address = Address.get_by(id=cart.address_id)
-
 
676
        customer_pincode = address.pin
-
 
677
    if not customer_pincode:
-
 
678
        user = User.get_by(active_cart_id = cartId)
-
 
679
        default_address_id = user.default_address_id
-
 
680
        if default_address_id:
-
 
681
            address = Address.get_by(id = default_address_id)
-
 
682
            customer_pincode = address.pin
-
 
683
    if not customer_pincode:
-
 
684
        #FIXME should not be hard coded. May be we can pick from config server.
-
 
685
        customer_pincode = "110001"
-
 
686
    cart.total_price = 0
-
 
687
    for line in cart_lines:
-
 
688
        old_estimate = line.estimate
-
 
689
        item_id = line.item_id
-
 
690
        item = inventory_client.getItemForSource(item_id, source_id)
-
 
691
        item_shipping_info = inventory_client.isActive(item_id) 
-
 
692
        if item_shipping_info.isActive:
-
 
693
            if item_shipping_info.isRisky and item_shipping_info.quantity < line.quantity:
-
 
694
                line.quantity = 1
-
 
695
                retval = "Try adding a smaller quantity of " + item.brand + " " + item.modelNumber + " (" + item.color + ")"
-
 
696
            
-
 
697
            line.actual_price = item.sellingPrice 
-
 
698
            cart.total_price = cart.total_price + (line.actual_price * line.quantity)
-
 
699
            try:
-
 
700
                item_delivery_estimate = logistics_client.getLogisticsEstimation(item_id, customer_pincode, DeliveryType.PREPAID).deliveryTime
-
 
701
            except LogisticsServiceException:
-
 
702
                item_delivery_estimate = -1
-
 
703
                #TODO Use the exception clause to set the retval appropriately
-
 
704
            except :
-
 
705
                item_delivery_estimate = -1
-
 
706
            if old_estimate != item_delivery_estimate:
-
 
707
                line.estimate = item_delivery_estimate
-
 
708
                cart.updated_on = current_time
-
 
709
        else:
-
 
710
            line.delete()
-
 
711
    if cart.checked_out_on is not None:
-
 
712
        if cart.updated_on > cart.checked_out_on:
-
 
713
            cart.checked_out_on = None
-
 
714
    session.commit()
-
 
715
    
-
 
716
    cart = Cart.get_by(id=cartId)
-
 
717
    cart_lines = cart.lines
-
 
718
    for line in cart_lines :
-
 
719
        if line.insurer > 0 :
-
 
720
            insure_item(line.item_id, cartId, True, InsurerType._NAMES_TO_VALUES.get("DEVICE"))
-
 
721
        if line.dataProtectionInsurer > 0:
-
 
722
            insure_item(line.item_id, cartId, True, InsurerType._NAMES_TO_VALUES.get("DATA"))
-
 
723
    if cart.coupon_code is not None:
-
 
724
        try:
657
    try:
725
            updated_cart = promotion_client.applyCoupon(cart.coupon_code, cart.id)
-
 
726
            if updated_cart.message is not None:
-
 
727
                emival = updated_cart.message
658
        cart_messages = validate_cart(cart_id, source_id)
728
        except PromotionException as ex:
-
 
729
            remove_coupon(cart.id)
-
 
730
            retval = ex.message
-
 
731
    
-
 
732
    return [retval, emival]
-
 
733
        found_cart = Cart.get_by(id=cartId)
659
        found_cart = Cart.get_by(id=cart_id)
734
        pincode = "110001"
660
        pincode = "110001"
735
        default_address_id = User.get_by(active_cart_id = cart_id).default_address_id
661
        default_address_id = User.get_by(active_cart_id = cart_id).default_address_id
736
        
662
        
737
        default_address = None
663
        default_address = None
738
        if found_cart.address_id is not None and found_cart.address_id > 0:
664
        if found_cart.address_id is not None and found_cart.address_id > 0: