Subversion Repositories SmartDukaan

Rev

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

Rev 5624 Rev 5692
Line 20... Line 20...
20
warehouse_allocation_cache = {}
20
warehouse_allocation_cache = {}
21
serviceable_location_cache = {}
21
serviceable_location_cache = {}
22
delivery_estimate_cache = {}
22
delivery_estimate_cache = {}
23
ncr_pincodes = ['110001','110002','110003','110004','110005','110006','110007','110008','110009','110010','110011','110012','110013','110014','110015',\
23
ncr_pincodes = ['110001','110002','110003','110004','110005','110006','110007','110008','110009','110010','110011','110012','110013','110014','110015',\
24
                '110016','110017','110018','110019','110020','110021','110022','110023','110024','110025','110026','110027','110028','110029','110030',\
24
                '110016','110017','110018','110019','110020','110021','110022','110023','110024','110025','110026','110027','110028','110029','110030',\
25
                '110031','110032','110033','110034','110035','110038','110041','110044','110045','110046','110047','110048','110049','110051','110052',\
25
                '110031','110032','110033','110034','110035','110037','110038','110041','110042','110044','110045','110046','110047','110048','110049',\
26
                '110053','110054','110055','110056','110057','110058','110059','110060','110061','110062','110063','110064','110065','110066','110067',\
26
                '110051','110052','110053','110054','110055','110056','110057','110058','110059','110060','110061','110062','110063','110064','110065',\
27
                '110068','110070','110071','110074','110075','110076','110078','110081','110082','110083','110084','110085','110086','110087','110088',\
27
                '110066','110067','110068','110070','110071','110074','110075','110076','110078','110081','110082','110083','110084','110085','110086',\
28
                '110089','110091','110092','110093','110094','110095','110096','110101','110103','110104','110105','110106','110107','110108','110109',\
28
                '110087','110088','110089','110091','110092','110093','110094','110095','110096','110101','110103','110104','110105','110106','110107',\
29
                '110110','110112','110113','110114','110115','110116','110117','110118','110119','110120','110122','110124','110125','110301','110302',\
29
                '110108','110109','110110','110112','110113','110114','110115','110116','110117','110118','110119','110120','110122','110124','110125',\
30
                '110501','110502','110503','110504','110505','110510','110511','110512','110601','110602','110603','110604','110605','110606','110607',\
30
                '110301','110302','110501','110502','110503','110504','110505','110510','110511','110512','110601','110602','110603','110604','110605',\
31
                '110608','110609','122001','122002','122003','122005','122006','122008','122009','122010','122015','122017','201010','201011','201012',\
31
                '110606','110607','110608','110609','121001','121002','121003','121004','121005','121006','121007','121008','121009','122001','122002',\
32
                '201014','201301','201302','201303','201304','201305','201306','201307','201309','201310','201311']
-
 
33
 
-
 
34
chennai_pincodes = ['600001','600002','600003','600004','600005','600006','600007','600008','600009','600010','600011','600012','600013','600014',\
-
 
35
                    '600015','600016','600017','600018','600019','600020','600021','600022','600023','600024','600025','600026','600027','600028',\
-
 
36
                    '600029','600030','600031','600032','600033','600034','600035','600036','600037','600038','600039','600040','600041','600042',\
-
 
37
                    '600043','600044','600045','600046','600047','600049','600050','600051','600053','600054','600055','600056','600058','600059',\
-
 
38
                    '600060','600061','600062','600063','600064','600069','600070','600071','600073','600074','600075','600076','600077','600078',\
-
 
39
                    '600079','600080','600081','600082','600083','600084','600085','600086','600087','600088','600089','600090','600091','600092',\
-
 
40
                    '600093','600094','600095','600096','600097','600098','600099','600100','600101','600102','600104','600105','600106','600107',\
32
                '122003','122005','122006','122008','122009','122010','122015','122017','201010','201011','201012','201014','201301','201302','201303',\
41
                    '600108','600110','600111','600112','600113','600118','600122','600126']
33
                '201304','201305','201306','201307','201309','201310','201311']
42
 
-
 
43
hyd_pincodes = ['500001','500002','500003','500004','500005','500006','500007','500008','500009','500010','500011','500012','500013','500014','500015',\
-
 
44
                '500016','500017','500018','500019','500020','500021','500022','500023','500024','500025','500026','500027','500028','500029','500030',\
-
 
45
                '500032','500033','500034','500035','500036','500037','500038','500039','500040','500041','500042','500044','500045','500047','500048',\
-
 
46
                '500049','500050','500051','500052','500053','500054','500055','500056','500057','500058','500059','500060','500061','500062','500063',\
-
 
47
                '500064','500065','500066','500067','500068','500069','500070','500071','500072','500073','500074','500076','500077','500079','500080',\
-
 
48
                '500081','500082','500085','500095']
-
 
49
'''
34
'''
50
This class is for only data transfer. Never used outside this module.
35
This class is for only data transfer. Never used outside this module.
51
'''
36
'''
52
class _DeliveryEstimateObject:
37
class _DeliveryEstimateObject:
53
    def __init__(self, delivery_time, reliability, provider_id, warehouse_location, codAllowed):
38
    def __init__(self, delivery_time, reliability, provider_id, codAllowed):
54
        self.delivery_time = delivery_time
39
        self.delivery_time = delivery_time
55
        self.reliability = reliability
40
        self.reliability = reliability
56
        self.provider_id = provider_id
41
        self.provider_id = provider_id
57
        self.warehouse_location = warehouse_location
-
 
58
        self.codAllowed = codAllowed
42
        self.codAllowed = codAllowed
59
    
43
    
60
def initialize(dbname="logistics", db_hostname="localhost"):
44
def initialize(dbname="logistics", db_hostname="localhost"):
61
    log_entry("initialize@DataAccessor", "Initializing data service")
45
    log_entry("initialize@DataAccessor", "Initializing data service")
62
    DataService.initialize(dbname, db_hostname)
46
    DataService.initialize(dbname, db_hostname)
Line 68... Line 52...
68
    print "Done cache population at: " + str(datetime.datetime.now())
52
    print "Done cache population at: " + str(datetime.datetime.now())
69
 
53
 
70
def __cache_delivery_estimate_table():
54
def __cache_delivery_estimate_table():
71
    delivery_estimates = DeliveryEstimate.query.all()
55
    delivery_estimates = DeliveryEstimate.query.all()
72
    for delivery_estimate in delivery_estimates:
56
    for delivery_estimate in delivery_estimates:
73
        delivery_estimate_cache[delivery_estimate.destination_pin, delivery_estimate.provider_id, delivery_estimate.warehouse_location]\
57
        delivery_estimate_cache[delivery_estimate.destination_pin, delivery_estimate.provider_id]\
74
        =delivery_estimate.delivery_time, delivery_estimate.reliability
58
        =delivery_estimate.delivery_time, delivery_estimate.reliability
75
 
59
 
76
def __cache_serviceable_location_details_table():
60
def __cache_serviceable_location_details_table():
77
    serviceable_locations = ServiceableLocationDetails.query.all()
61
    serviceable_locations = ServiceableLocationDetails.query.all()
78
    for serviceable_location in serviceable_locations:
62
    for serviceable_location in serviceable_locations:
Line 94... Line 78...
94
 
78
 
95
def get_providers():
79
def get_providers():
96
    providers = Provider.query.filter_by(isActive = 1).all()
80
    providers = Provider.query.filter_by(isActive = 1).all()
97
    return providers 
81
    return providers 
98
 
82
 
99
def get_logistics_estimation(destination_pin, item_selling_price, warehouse_location=None, type=DeliveryType.PREPAID):
83
def get_logistics_estimation(destination_pin, item_selling_price, type=DeliveryType.PREPAID):
100
    logging.info("Getting logistics estimation for pincode:" + destination_pin + " and warehouse location: " + str(warehouse_location))
84
    logging.info("Getting logistics estimation for pincode:" + destination_pin )
101
    if warehouse_location is None:
-
 
102
        try:
-
 
103
            warehouse_location = warehouse_allocation_cache[destination_pin]
-
 
104
        except:
-
 
105
            print "Unexpected error:", sys.exc_info()[0]
-
 
106
            raise LogisticsServiceException(101, "No Warehouse locations assigned to this pincode: " + destination_pin)
-
 
107
    
85
    
108
    provider_id, codAllowed = __get_logistics_provider_for_destination_pincode(type, destination_pin, item_selling_price)
86
    provider_id, codAllowed = __get_logistics_provider_for_destination_pincode(type, destination_pin, item_selling_price)
109
    
87
    
110
    if not provider_id:
88
    if not provider_id:
111
        raise LogisticsServiceException(101, "No provider assigned for pincode: " + str(destination_pin) + \
89
        raise LogisticsServiceException(101, "No provider assigned for pincode: " + str(destination_pin))
112
                                        ", and warehouse location: " + str(warehouse_location))
-
 
113
    try:
90
    try:
114
        delivery_time = delivery_estimate_cache[destination_pin, provider_id, warehouse_location][0]
91
        delivery_time = delivery_estimate_cache[destination_pin, provider_id][0]
115
        reliability = delivery_estimate_cache[destination_pin, provider_id, warehouse_location][1]
92
        reliability = delivery_estimate_cache[destination_pin, provider_id][1]
116
        delivery_estimate = _DeliveryEstimateObject(delivery_time, reliability, provider_id, warehouse_location, codAllowed)
93
        delivery_estimate = _DeliveryEstimateObject(delivery_time, reliability, provider_id, codAllowed)
117
        return delivery_estimate
94
        return delivery_estimate
118
    except Exception as ex:
95
    except Exception as ex:
119
        print ex
96
        print ex
120
        raise LogisticsServiceException(103, "No Logistics partner listed for this destination pincode and the primary warehouse")
97
        raise LogisticsServiceException(103, "No Logistics partner listed for this destination pincode and the primary warehouse")
121
 
98
 
122
def __get_logistics_provider_for_destination_pincode(type, destination_pin, item_selling_price):
99
def __get_logistics_provider_for_destination_pincode(type, destination_pin, item_selling_price):
123
    if ncr_pincodes.__contains__(destination_pin) and item_selling_price <= 20000:
100
    if ncr_pincodes.__contains__(destination_pin) and item_selling_price <= 20000:
124
        return 3, True
101
        return 3, True
125
    if type == DeliveryType.COD and (chennai_pincodes.__contains__(destination_pin) or hyd_pincodes.__contains__(destination_pin)) and item_selling_price <= 10000:
102
    if serviceable_location_cache.get(3).has_key(destination_pin):
126
        return 3, True
103
        dest_code, exp, iscod, station_type = serviceable_location_cache.get(3).get(destination_pin)
127
    if type == DeliveryType.PREPAID and (chennai_pincodes.__contains__(destination_pin) or hyd_pincodes.__contains__(destination_pin)) and item_selling_price <= 5000:
104
        iscod = iscod and item_selling_price <= 10000
128
        return 3, True
105
        return 3, iscod
129
    if serviceable_location_cache.get(1).has_key(destination_pin):
106
    if serviceable_location_cache.get(1).has_key(destination_pin):
130
        dest_code, exp, iscod, station_type = serviceable_location_cache.get(1).get(destination_pin)
107
        dest_code, exp, iscod, station_type = serviceable_location_cache.get(1).get(destination_pin)
131
        iscod = iscod and item_selling_price <= 10000
108
        iscod = iscod and item_selling_price <= 10000
132
        return 1, iscod
109
        return 1, iscod
133
    elif type == DeliveryType.PREPAID and chennai_pincodes.__contains__(destination_pin):
-
 
134
        return 3, False
-
 
135
    else:
110
    else:
136
        return None, False    
111
        return None, False    
137
 
112
 
138
        
113
        
139
def add_empty_AWBs(numbers, provider_id, type):
114
def add_empty_AWBs(numbers, provider_id, type):