Subversion Repositories SmartDukaan

Rev

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

Rev 19420 Rev 19421
Line 8... Line 8...
8
from shop2020.clients.CatalogClient import CatalogClient
8
from shop2020.clients.CatalogClient import CatalogClient
9
from shop2020.clients.InventoryClient import InventoryClient
9
from shop2020.clients.InventoryClient import InventoryClient
10
from shop2020.logistics.service.impl import DataService
10
from shop2020.logistics.service.impl import DataService
11
from shop2020.logistics.service.impl.DataService import Awb, AwbUpdate, Provider, \
11
from shop2020.logistics.service.impl.DataService import Awb, AwbUpdate, Provider, \
12
    DeliveryEstimate, WarehouseAllocation, PublicHolidays, \
12
    DeliveryEstimate, WarehouseAllocation, PublicHolidays, \
13
    ServiceableLocationDetails, PickupStore, Locations
13
    ServiceableLocationDetails, PickupStore, Locations, ProviderCosting
14
from shop2020.thriftpy.logistics.ttypes import LogisticsServiceException, \
14
from shop2020.thriftpy.logistics.ttypes import LogisticsServiceException, \
15
    DeliveryType, LogisticsLocationInfo, LocationInfo, ProviderInfo
15
    DeliveryType, LogisticsLocationInfo, LocationInfo, ProviderInfo, DeliveryEstimateAndCosting
16
from shop2020.thriftpy.model.v1.inventory.ttypes import Warehouse, BillingType, \
16
from shop2020.thriftpy.model.v1.inventory.ttypes import Warehouse, BillingType, \
17
    WarehouseType
17
    WarehouseType
18
from shop2020.utils.Utils import log_entry, to_py_date, to_java_date
18
from shop2020.utils.Utils import log_entry, to_py_date, to_java_date
19
from sqlalchemy.sql import or_
19
from sqlalchemy.sql import or_
20
import datetime
20
import datetime
Line 32... Line 32...
32
serviceable_location_cache = {}
32
serviceable_location_cache = {}
33
delivery_estimate_cache = {}
33
delivery_estimate_cache = {}
34
warehouse_location_cache = {}
34
warehouse_location_cache = {}
35
location_state={}
35
location_state={}
36
state_locations = {}
36
state_locations = {}
-
 
37
provider_costing_sheet = {}
-
 
38
DELHIVERY = 3
37
 
39
 
38
#pincode location map is ab
40
#pincode location map is ab
39
#{'110001':{1:{"sameState":False, "providerInfo":{1:(1,1), 2:(1,1)}}},}
41
#{'110001':{1:{"sameState":False, "providerInfo":{1:(1,1), 2:(1,1)}}},}
40
pincode_locations = {}
42
pincode_locations = {}
41
#{(dest_pin, provider):(otgAvailable,providerCodLimit, websiteCodLimit, storeCodLimit, providerPrepaidLimit)} 
43
#{(dest_pin, provider):(otgAvailable,providerCodLimit, websiteCodLimit, storeCodLimit, providerPrepaidLimit)} 
Line 69... Line 71...
69
    __cache_warehouse_locations()
71
    __cache_warehouse_locations()
70
    __cache_serviceable_location_details_table()
72
    __cache_serviceable_location_details_table()
71
    __cache_delivery_estimate_table()
73
    __cache_delivery_estimate_table()
72
    __cache_locations()
74
    __cache_locations()
73
    __cache_pincode_estimates()    
75
    __cache_pincode_estimates()    
-
 
76
    __cache_courier_costing_table()
74
    close_session()
77
    close_session()
75
    print "Done cache population at: " + str(datetime.datetime.now())
78
    print "Done cache population at: " + str(datetime.datetime.now())
76
 
79
 
77
def __cache_locations():
80
def __cache_locations():
78
    locations = Locations.query.all()
81
    locations = Locations.query.all()
Line 106... Line 109...
106
 
109
 
107
def __cache_delivery_estimate_table():
110
def __cache_delivery_estimate_table():
108
    delivery_estimates = DeliveryEstimate.query.all()
111
    delivery_estimates = DeliveryEstimate.query.all()
109
    for delivery_estimate in delivery_estimates:
112
    for delivery_estimate in delivery_estimates:
110
        delivery_estimate_cache[delivery_estimate.destination_pin, delivery_estimate.provider_id, delivery_estimate.warehouse_location]\
113
        delivery_estimate_cache[delivery_estimate.destination_pin, delivery_estimate.provider_id, delivery_estimate.warehouse_location]\
111
        =delivery_estimate.delivery_time, delivery_estimate.delivery_delay
114
        =delivery_estimate.delivery_time, delivery_estimate.delivery_delay, delivery_estimate.providerZoneCode
112
 
115
 
113
def __cache_serviceable_location_details_table():
116
def __cache_serviceable_location_details_table():
114
    serviceable_locations = ServiceableLocationDetails.query.filter(or_("exp!=0","cod!=0"))
117
    serviceable_locations = ServiceableLocationDetails.query.filter(or_("exp!=0","cod!=0"))
115
    for serviceable_location in serviceable_locations:
118
    for serviceable_location in serviceable_locations:
116
        try:
119
        try:
Line 128... Line 131...
128
def __cache_warehouse_locations():
131
def __cache_warehouse_locations():
129
    client = InventoryClient().get_client()
132
    client = InventoryClient().get_client()
130
    #client.getAllWarehouses(True)
133
    #client.getAllWarehouses(True)
131
    for warehouse in client.getAllWarehouses(True):
134
    for warehouse in client.getAllWarehouses(True):
132
        warehouse_location_cache[warehouse.billingWarehouseId]=warehouse.logisticsLocation
135
        warehouse_location_cache[warehouse.billingWarehouseId]=warehouse.logisticsLocation
-
 
136
        
-
 
137
def __cache_courier_costing_table():
-
 
138
    allCostings = ProviderCosting.query.all()
-
 
139
    for costing in allCostings:
-
 
140
        if provider_costing_sheet.has_key(costing.provider_id):
-
 
141
            costingMap = provider_costing_sheet.get(costing.provider_id)
-
 
142
            costingMap[costing.zoneCode] = costing
-
 
143
            provider_costing_sheet[costing.provider_id] = costingMap
-
 
144
        else:
-
 
145
            costingMap = {}
-
 
146
            costingMap[costing.zoneCode] = costing
-
 
147
            provider_costing_sheet[costing.provider_id] = costingMap
-
 
148
    
133
 
149
 
134
def get_provider(provider_id):
150
def get_provider(provider_id):
135
    provider =  Provider.get_by(id=provider_id)
151
    provider =  Provider.get_by(id=provider_id)
136
    return provider
152
    return provider
137
 
153
 
Line 487... Line 503...
487
        deliveryEstimate = DeliveryEstimate.get_by(provider_id = logisticsLocationInfo.providerId, destination_pin = logisticsLocationInfo.pinCode, warehouse_location = logisticsLocationInfo.warehouseId) 
503
        deliveryEstimate = DeliveryEstimate.get_by(provider_id = logisticsLocationInfo.providerId, destination_pin = logisticsLocationInfo.pinCode, warehouse_location = logisticsLocationInfo.warehouseId) 
488
        if deliveryEstimate:
504
        if deliveryEstimate:
489
            deliveryEstimate.warehouse_location= logisticsLocationInfo.warehouseId
505
            deliveryEstimate.warehouse_location= logisticsLocationInfo.warehouseId
490
            deliveryEstimate.delivery_time= logisticsLocationInfo.deliveryTime
506
            deliveryEstimate.delivery_time= logisticsLocationInfo.deliveryTime
491
            deliveryEstimate.delivery_delay= logisticsLocationInfo.delivery_delay
507
            deliveryEstimate.delivery_delay= logisticsLocationInfo.delivery_delay
-
 
508
            deliveryEstimate.providerZoneCode = logisticsLocationInfo.zoneCode
492
        else:
509
        else:
493
            deliveryEstimate = DeliveryEstimate()
510
            deliveryEstimate = DeliveryEstimate()
494
            deliveryEstimate.destination_pin= logisticsLocationInfo.pinCode
511
            deliveryEstimate.destination_pin= logisticsLocationInfo.pinCode
495
            deliveryEstimate.provider = provider
512
            deliveryEstimate.provider = provider
496
            deliveryEstimate.warehouse_location= logisticsLocationInfo.warehouseId
513
            deliveryEstimate.warehouse_location= logisticsLocationInfo.warehouseId
497
            deliveryEstimate.delivery_time= logisticsLocationInfo.deliveryTime
514
            deliveryEstimate.delivery_time= logisticsLocationInfo.deliveryTime
498
            deliveryEstimate.delivery_delay= logisticsLocationInfo.delivery_delay
515
            deliveryEstimate.delivery_delay= logisticsLocationInfo.delivery_delay
-
 
516
            deliveryEstimate.providerZoneCode = logisticsLocationInfo.zoneCode
499
    session.commit()
517
    session.commit()
500
 
518
 
501
#End:- Added by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013             
519
#End:- Added by Manish Sharma for Multiple Pincode Updation on 05-Jul-2013             
502
            
520
            
503
def get_first_delivery_estimate_for_wh_location(pincode, whLocation):
521
def get_first_delivery_estimate_for_wh_location(pincode, whLocation):
Line 538... Line 556...
538
        awb.is_available = False
556
        awb.is_available = False
539
        session.commit()
557
        session.commit()
540
        return awb.awb_number
558
        return awb.awb_number
541
    except:
559
    except:
542
        raise LogisticsServiceException(103, "Unable to get an AWB for the given Provider: " + str(providerId))
560
        raise LogisticsServiceException(103, "Unable to get an AWB for the given Provider: " + str(providerId))
543
        
-
 
544
561
 
-
 
562
def get_costing_and_delivery_estimate_for_pincode(pincode, transactionAmount, isCod, weight, billingWarehouseId):
-
 
563
    deliveryEstimate = {}
-
 
564
    logsiticsCosting = {}
-
 
565
    providerCostingMap = {}
-
 
566
    serviceability = {}
-
 
567
    
-
 
568
    for providerId in serviceable_location_cache.keys():
-
 
569
        if serviceable_location_cache.has_key(providerId) and serviceable_location_cache.get(providerId).has_key(pincode):
-
 
570
            dest_code, exp, iscod, otgAvailable, websiteCodLimit, storeCodLimit, providerPrepaidLimit = serviceable_location_cache.get(providerId).get(pincode)
-
 
571
            if isCod and iscod:
-
 
572
                serviceability[providerId] = serviceable_location_cache.get(providerId).get(pincode)
-
 
573
            elif isCod and not iscod:
-
 
574
                continue
-
 
575
            else:
-
 
576
                serviceability[providerId] = serviceable_location_cache.get(providerId).get(pincode)
-
 
577
                
-
 
578
    warehouse_location = warehouse_location_cache.get(billingWarehouseId)
-
 
579
    if warehouse_location is None:
-
 
580
        warehouse_location = 0
-
 
581
    
-
 
582
    noCostFoundCount = 0
-
 
583
    if len(serviceability)>0:
-
 
584
        for providerId, serviceableDetails in serviceability.items():
-
 
585
            delivery_time = delivery_estimate_cache[pincode, providerId, warehouse_location][0]
-
 
586
            delivery_delay = delivery_estimate_cache[pincode, providerId, warehouse_location][1]
-
 
587
            zoneCode = delivery_estimate_cache[pincode, providerId, warehouse_location][2]
-
 
588
            sla = delivery_time + delivery_delay
-
 
589
            if deliveryEstimate.has_key(sla):
-
 
590
                estimate = deliveryEstimate.get(sla)
-
 
591
                estimate.append(providerId)
-
 
592
                deliveryEstimate[sla] = estimate
-
 
593
            else:
-
 
594
                estimate = []
-
 
595
                estimate.append(providerId)
-
 
596
                deliveryEstimate[sla] = estimate
-
 
597
            
-
 
598
            logisticsCost = 0
-
 
599
            codCollectionCharges = 0    
-
 
600
            logisticsCostObj = None 
-
 
601
            if provider_costing_sheet.has_key(providerId) and provider_costing_sheet.get(providerId).has_key(zoneCode):
-
 
602
                logisticsCostObj = provider_costing_sheet.get(providerId).get(zoneCode)
-
 
603
                logisticsCost = logisticsCostObj.initialLogisticsCost
-
 
604
                if weight > logisticsCostObj.initialWeightUpperLimit:
-
 
605
                    additionalWeight = weight-logisticsCostObj.initialWeightUpperLimit
-
 
606
                    additionalCostMultiplier = additionalWeight/logisticsCostObj.additionalUnitWeight
-
 
607
                    additionalCost = additionalCostMultiplier*logisticsCostObj.additionalUnitLogisticsCost
-
 
608
                    logisticsCost = logisticsCost + additionalCost
-
 
609
                if isCod:
-
 
610
                    if logisticsCostObj.codCollectionFactor:
-
 
611
                        codCollectionCharges = max(logisticsCostObj.minimumCodCollectionCharges, transactionAmount*logisticsCostObj.codCollectionFactor)
-
 
612
                        logisticsCost = logisticsCost + max(logisticsCostObj.minimumCodCollectionCharges, transactionAmount*logisticsCostObj.codCollectionFactor)
-
 
613
                    else:
-
 
614
                        codCollectionCharges = logisticsCostObj.minimumCodCollectionCharges
-
 
615
                        logisticsCost = logisticsCost + logisticsCostObj.minimumCodCollectionCharges
-
 
616
                        
-
 
617
                if logsiticsCosting.has_key(logisticsCost):
-
 
618
                    costingList = logsiticsCosting.get(logisticsCost)
-
 
619
                    costingList.append(providerId)
-
 
620
                    logsiticsCosting[logisticsCost] = costingList
-
 
621
                else:
-
 
622
                    costingList = []
-
 
623
                    costingList.append(providerId)
-
 
624
                    logsiticsCosting[logisticsCost] = costingList
-
 
625
                    
-
 
626
                providerCostingMap[providerId] = [logisticsCost,codCollectionCharges]
-
 
627
            else:
-
 
628
                noCostFoundCount = noCostFoundCount +1
-
 
629
                continue
-
 
630
    else:
-
 
631
        raise LogisticsServiceException(101, "No provider assigned for pincode: " + str(pincode))
-
 
632
        
-
 
633
    
-
 
634
    if noCostFoundCount == len(serviceability):
-
 
635
        raise LogisticsServiceException(101, "No Costing Found for this pincode: " + str(pincode) +" for any of the provider")
-
 
636
    
-
 
637
    allSla = sorted(deliveryEstimate.keys())
-
 
638
    if len(allSla)==1:
-
 
639
        allEligibleProviders = deliveryEstimate.get(allSla[0])
-
 
640
        if len(allEligibleProviders)==1:
-
 
641
            costingDetails = providerCostingMap.get(allEligibleProviders[0])
-
 
642
            delEstCostObj = DeliveryEstimateAndCosting()
-
 
643
            delEstCostObj.logistics_provider_id = allEligibleProviders[0]
-
 
644
            delEstCostObj.pincode = pincode
-
 
645
            delEstCostObj.deliveryTime = delivery_estimate_cache[pincode, allEligibleProviders[0], warehouse_location][0]
-
 
646
            delEstCostObj.delivery_delay = delivery_estimate_cache[pincode, allEligibleProviders[0], warehouse_location][1]
-
 
647
            delEstCostObj.codAllowed = serviceability[allEligibleProviders[0]][2]
-
 
648
            delEstCostObj.otgAvailable = serviceability[allEligibleProviders[0]][3]
-
 
649
            delEstCostObj.logisticsCost = costingDetails[0]-costingDetails[1]
-
 
650
            delEstCostObj.codCollectionCharges = costingDetails[1]
-
 
651
            return delEstCostObj
-
 
652
        else:
-
 
653
            costingListOrder = []
-
 
654
            for providerId in allEligibleProviders:
-
 
655
                costingDetails = providerCostingMap.get(allEligibleProviders[0])
-
 
656
                if costingDetails[0] not in costingListOrder:
-
 
657
                    costingListOrder.append(costingDetails[0])
-
 
658
                
-
 
659
            if DELHIVERY in allEligibleProviders:
-
 
660
                delihiveryCosting = providerCostingMap.get(DELHIVERY)
-
 
661
                considerCost = min(min(costingListOrder)+10, delihiveryCosting[0])
-
 
662
                if considerCost == delihiveryCosting[0]:
-
 
663
                    delEstCostObj = DeliveryEstimateAndCosting()
-
 
664
                    delEstCostObj.logistics_provider_id = DELHIVERY
-
 
665
                    delEstCostObj.pincode = pincode
-
 
666
                    delEstCostObj.deliveryTime = delivery_estimate_cache[pincode, DELHIVERY, warehouse_location][0]
-
 
667
                    delEstCostObj.delivery_delay = delivery_estimate_cache[pincode, DELHIVERY, warehouse_location][1]
-
 
668
                    delEstCostObj.codAllowed = serviceability[DELHIVERY][2]
-
 
669
                    delEstCostObj.otgAvailable = serviceability[DELHIVERY][3]
-
 
670
                    delEstCostObj.logisticsCost = delihiveryCosting[0]-delihiveryCosting[1]
-
 
671
                    delEstCostObj.codCollectionCharges = delihiveryCosting[1]
-
 
672
                    return delEstCostObj
-
 
673
                else:
-
 
674
                    considerCost = considerCost -10
-
 
675
                    eligibleProviders = logsiticsCosting.get(considerCost)
-
 
676
                    costingDetails = providerCostingMap.get(eligibleProviders[0])
-
 
677
                    delEstCostObj = DeliveryEstimateAndCosting()
-
 
678
                    delEstCostObj.logistics_provider_id = eligibleProviders[0]
-
 
679
                    delEstCostObj.pincode = pincode
-
 
680
                    delEstCostObj.deliveryTime = delivery_estimate_cache[pincode, eligibleProviders[0], warehouse_location][0]
-
 
681
                    delEstCostObj.delivery_delay = delivery_estimate_cache[pincode, eligibleProviders[0], warehouse_location][1]
-
 
682
                    delEstCostObj.codAllowed = serviceability[eligibleProviders[0]][2]
-
 
683
                    delEstCostObj.otgAvailable = serviceability[eligibleProviders[0]][3]
-
 
684
                    delEstCostObj.logisticsCost = costingDetails[0]-costingDetails[1]
-
 
685
                    delEstCostObj.codCollectionCharges = costingDetails[1]
-
 
686
                    return delEstCostObj
-
 
687
            else:
-
 
688
                costingListOrder = sorted(costingListOrder)
-
 
689
                eligibleProviders = logsiticsCosting.get(costingListOrder[0])
-
 
690
                costingDetails = providerCostingMap.get(eligibleProviders[0])
-
 
691
                delEstCostObj = DeliveryEstimateAndCosting()
-
 
692
                delEstCostObj.logistics_provider_id = eligibleProviders[0]
-
 
693
                delEstCostObj.pincode = pincode
-
 
694
                delEstCostObj.deliveryTime = delivery_estimate_cache[pincode, eligibleProviders[0], warehouse_location][0]
-
 
695
                delEstCostObj.delivery_delay = delivery_estimate_cache[pincode, eligibleProviders[0], warehouse_location][1]
-
 
696
                delEstCostObj.codAllowed = serviceability[eligibleProviders[0]][2]
-
 
697
                delEstCostObj.otgAvailable = serviceability[eligibleProviders[0]][3]
-
 
698
                delEstCostObj.logisticsCost = costingDetails[0]-costingDetails[1]
-
 
699
                delEstCostObj.codCollectionCharges = costingDetails[1]
-
 
700
                return delEstCostObj
-
 
701
    
-
 
702
    else:
-
 
703
        if allSla[1]-allSla[0]!=1:
-
 
704
            allEligibleProviders = deliveryEstimate.get(allSla[0])
-
 
705
            if len(allEligibleProviders)==1:
-
 
706
                costingDetails = providerCostingMap.get(allEligibleProviders[0])
-
 
707
                delEstCostObj = DeliveryEstimateAndCosting()
-
 
708
                delEstCostObj.logistics_provider_id = allEligibleProviders[0]
-
 
709
                delEstCostObj.pincode = pincode
-
 
710
                delEstCostObj.deliveryTime = delivery_estimate_cache[pincode, allEligibleProviders[0], warehouse_location][0]
-
 
711
                delEstCostObj.delivery_delay = delivery_estimate_cache[pincode, allEligibleProviders[0], warehouse_location][1]
-
 
712
                delEstCostObj.codAllowed = serviceability[allEligibleProviders[0]][2]
-
 
713
                delEstCostObj.otgAvailable = serviceability[allEligibleProviders[0]][3]
-
 
714
                delEstCostObj.logisticsCost = costingDetails[0]-costingDetails[1]
-
 
715
                delEstCostObj.codCollectionCharges = costingDetails[1]
-
 
716
                return delEstCostObj
-
 
717
            else:
-
 
718
                costingListOrder = []
-
 
719
                for providerId in allEligibleProviders:
-
 
720
                    costingDetails = providerCostingMap.get(allEligibleProviders[0])
-
 
721
                    if costingDetails[0] not in costingListOrder:
-
 
722
                        costingListOrder.append(costingDetails[0])
-
 
723
                    
-
 
724
                if DELHIVERY in allEligibleProviders:
-
 
725
                    delihiveryCosting = providerCostingMap.get(DELHIVERY)
-
 
726
                    considerCost = min(min(costingListOrder)+10, delihiveryCosting[0])
-
 
727
                    if considerCost == delihiveryCosting[0]:
-
 
728
                        delEstCostObj = DeliveryEstimateAndCosting()
-
 
729
                        delEstCostObj.logistics_provider_id = DELHIVERY
-
 
730
                        delEstCostObj.pincode = pincode
-
 
731
                        delEstCostObj.deliveryTime = delivery_estimate_cache[pincode, DELHIVERY, warehouse_location][0]
-
 
732
                        delEstCostObj.delivery_delay = delivery_estimate_cache[pincode, DELHIVERY, warehouse_location][1]
-
 
733
                        delEstCostObj.codAllowed = serviceability[DELHIVERY][2]
-
 
734
                        delEstCostObj.otgAvailable = serviceability[DELHIVERY][3]
-
 
735
                        delEstCostObj.logisticsCost = delihiveryCosting[0]-delihiveryCosting[1]
-
 
736
                        delEstCostObj.codCollectionCharges = delihiveryCosting[1]
-
 
737
                        return delEstCostObj
-
 
738
                    else:
-
 
739
                        considerCost = considerCost -10
-
 
740
                        eligibleProviders = logsiticsCosting.get(considerCost)
-
 
741
                        costingDetails = providerCostingMap.get(eligibleProviders[0])
-
 
742
                        delEstCostObj = DeliveryEstimateAndCosting()
-
 
743
                        delEstCostObj.logistics_provider_id = eligibleProviders[0]
-
 
744
                        delEstCostObj.pincode = pincode
-
 
745
                        delEstCostObj.deliveryTime = delivery_estimate_cache[pincode, eligibleProviders[0], warehouse_location][0]
-
 
746
                        delEstCostObj.delivery_delay = delivery_estimate_cache[pincode, eligibleProviders[0], warehouse_location][1]
-
 
747
                        delEstCostObj.codAllowed = serviceability[eligibleProviders[0]][2]
-
 
748
                        delEstCostObj.otgAvailable = serviceability[eligibleProviders[0]][3]
-
 
749
                        delEstCostObj.logisticsCost = costingDetails[0]-costingDetails[1]
-
 
750
                        delEstCostObj.codCollectionCharges = costingDetails[1]
-
 
751
                        return delEstCostObj
-
 
752
                else:
-
 
753
                    costingListOrder = sorted(costingListOrder)
-
 
754
                    eligibleProviders = logsiticsCosting.get(costingListOrder[0])
-
 
755
                    costingDetails = providerCostingMap.get(eligibleProviders[0])
-
 
756
                    delEstCostObj = DeliveryEstimateAndCosting()
-
 
757
                    delEstCostObj.logistics_provider_id = eligibleProviders[0]
-
 
758
                    delEstCostObj.pincode = pincode
-
 
759
                    delEstCostObj.deliveryTime = delivery_estimate_cache[pincode, eligibleProviders[0], warehouse_location][0]
-
 
760
                    delEstCostObj.delivery_delay = delivery_estimate_cache[pincode, eligibleProviders[0], warehouse_location][1]
-
 
761
                    delEstCostObj.codAllowed = serviceability[eligibleProviders[0]][2]
-
 
762
                    delEstCostObj.otgAvailable = serviceability[eligibleProviders[0]][3]
-
 
763
                    delEstCostObj.logisticsCost = costingDetails[0]-costingDetails[1]
-
 
764
                    delEstCostObj.codCollectionCharges = costingDetails[1]
-
 
765
                    return delEstCostObj
-
 
766
        
-
 
767
        else:
-
 
768
            allEligibleProviders = deliveryEstimate.get(allSla[0])
-
 
769
            secondBestEligibleProviders = deliveryEstimate.get(allSla[1])
-
 
770
            for providerId in secondBestEligibleProviders:
-
 
771
                allEligibleProviders.append(providerId)
-
 
772
                
-
 
773
            costingListOrder = []
-
 
774
            for providerId in allEligibleProviders:
-
 
775
                costingDetails = providerCostingMap.get(allEligibleProviders[0])
-
 
776
                if costingDetails[0] not in costingListOrder:
-
 
777
                    costingListOrder.append(costingDetails[0])
-
 
778
                
-
 
779
            if DELHIVERY in allEligibleProviders:
-
 
780
                delihiveryCosting = providerCostingMap.get(DELHIVERY)
-
 
781
                considerCost = min(min(costingListOrder)+10, delihiveryCosting[0])
-
 
782
                if considerCost == delihiveryCosting[0]:
-
 
783
                    delEstCostObj = DeliveryEstimateAndCosting()
-
 
784
                    delEstCostObj.logistics_provider_id = DELHIVERY
-
 
785
                    delEstCostObj.pincode = pincode
-
 
786
                    delEstCostObj.deliveryTime = delivery_estimate_cache[pincode, DELHIVERY, warehouse_location][0]
-
 
787
                    delEstCostObj.delivery_delay = delivery_estimate_cache[pincode, DELHIVERY, warehouse_location][1]
-
 
788
                    delEstCostObj.codAllowed = serviceability[DELHIVERY][2]
-
 
789
                    delEstCostObj.otgAvailable = serviceability[DELHIVERY][3]
-
 
790
                    delEstCostObj.logisticsCost = delihiveryCosting[0]-delihiveryCosting[1]
-
 
791
                    delEstCostObj.codCollectionCharges = delihiveryCosting[1]
-
 
792
                    return delEstCostObj
-
 
793
                else:
-
 
794
                    considerCost = considerCost -10
-
 
795
                    eligibleProviders = logsiticsCosting.get(considerCost)
-
 
796
                    costingDetails = providerCostingMap.get(eligibleProviders[0])
-
 
797
                    delEstCostObj = DeliveryEstimateAndCosting()
-
 
798
                    delEstCostObj.logistics_provider_id = eligibleProviders[0]
-
 
799
                    delEstCostObj.pincode = pincode
-
 
800
                    delEstCostObj.deliveryTime = delivery_estimate_cache[pincode, eligibleProviders[0], warehouse_location][0]
-
 
801
                    delEstCostObj.delivery_delay = delivery_estimate_cache[pincode, eligibleProviders[0], warehouse_location][1]
-
 
802
                    delEstCostObj.codAllowed = serviceability[eligibleProviders[0]][2]
-
 
803
                    delEstCostObj.otgAvailable = serviceability[eligibleProviders[0]][3]
-
 
804
                    delEstCostObj.logisticsCost = costingDetails[0]-costingDetails[1]
-
 
805
                    delEstCostObj.codCollectionCharges = costingDetails[1]
-
 
806
                    return delEstCostObj
-
 
807
            else:
-
 
808
                costingListOrder = sorted(costingListOrder)
-
 
809
                eligibleProviders = logsiticsCosting.get(costingListOrder[0])
-
 
810
                costingDetails = providerCostingMap.get(eligibleProviders[0])
-
 
811
                delEstCostObj = DeliveryEstimateAndCosting()
-
 
812
                delEstCostObj.logistics_provider_id = eligibleProviders[0]
-
 
813
                delEstCostObj.pincode = pincode
-
 
814
                delEstCostObj.deliveryTime = delivery_estimate_cache[pincode, eligibleProviders[0], warehouse_location][0]
-
 
815
                delEstCostObj.delivery_delay = delivery_estimate_cache[pincode, eligibleProviders[0], warehouse_location][1]
-
 
816
                delEstCostObj.codAllowed = serviceability[eligibleProviders[0]][2]
-
 
817
                delEstCostObj.otgAvailable = serviceability[eligibleProviders[0]][3]
-
 
818
                delEstCostObj.logisticsCost = costingDetails[0]-costingDetails[1]
-
 
819
                delEstCostObj.codCollectionCharges = costingDetails[1]
-
 
820
                return delEstCostObj
-
 
821