| 23141 |
amit.gupta |
1 |
#!/usr/bin/python
|
|
|
2 |
|
|
|
3 |
'''
|
|
|
4 |
Loads the static logic of assigning provider to a particular pincode
|
|
|
5 |
into the DestinationProviderAllocation table.
|
|
|
6 |
|
|
|
7 |
@author: Amit Gupta
|
|
|
8 |
'''
|
|
|
9 |
from datetime import *
|
|
|
10 |
from elixir import *
|
|
|
11 |
from shop2020.logistics.service.impl import DataService, EcomExpressService
|
|
|
12 |
from shop2020.logistics.service.impl.DataAccessor import add_empty_AWBs
|
|
|
13 |
from shop2020.logistics.service.impl.DataService import \
|
|
|
14 |
ServiceableLocationDetails, Awb
|
|
|
15 |
from shop2020.logistics.service.impl.EcomExpressService import generate_awb
|
|
|
16 |
from shop2020.logistics.service.script import AwbNumberLoader
|
|
|
17 |
from shop2020.thriftpy.logistics.ttypes import DeliveryType
|
|
|
18 |
from shop2020.utils.EmailAttachmentSender import get_attachment_part, mail
|
|
|
19 |
import optparse
|
|
|
20 |
|
|
|
21 |
if __name__ == '__main__' and __package__ is None:
|
|
|
22 |
import sys
|
|
|
23 |
import os
|
|
|
24 |
sys.path.insert(0, os.getcwd())
|
|
|
25 |
|
|
|
26 |
|
|
|
27 |
|
|
|
28 |
def main():
|
|
|
29 |
parser = optparse.OptionParser()
|
|
|
30 |
parser.add_option("-H", "--host", dest="hostname",
|
|
|
31 |
default="localhost",
|
|
|
32 |
type="string", help="The HOST where the DB server is running",
|
|
|
33 |
metavar="HOST")
|
|
|
34 |
parser.add_option("-P", "--provider_id", dest="provider_id",
|
|
|
35 |
default="localhost",
|
|
|
36 |
type="string", help="The HOST where the DB server is running",
|
|
|
37 |
metavar="HOST")
|
|
|
38 |
(options, args) = parser.parse_args()
|
|
|
39 |
if len(args) != 0:
|
|
|
40 |
parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
|
|
|
41 |
provider_id = options.provider_id
|
|
|
42 |
hostname = options.hostname
|
|
|
43 |
if provider_id is None or hostname is None:
|
|
|
44 |
parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
|
|
|
45 |
|
|
|
46 |
DataService.initialize(dbname='logistics', db_hostname=hostname)
|
|
|
47 |
if provider_id=="49":
|
|
|
48 |
subject = "Tat is missing for Ecom Express active pincodes"
|
|
|
49 |
missingPincodes = []
|
| 23235 |
amit.gupta |
50 |
try:
|
| 23239 |
amit.gupta |
51 |
serviceabilityPincodeList = EcomExpressService.getServiceablePinCodes(datetime.now()-timedelta(days=15))
|
|
|
52 |
#print "serviceabilityPincodeList", serviceabilityPincodeList
|
| 23235 |
amit.gupta |
53 |
for serviceabilityPincode in serviceabilityPincodeList:
|
|
|
54 |
pincode = str(serviceabilityPincode["pincode"])
|
|
|
55 |
serviceableLocationDetails = ServiceableLocationDetails.query.filter_by(provider_id=int(provider_id)).filter_by(dest_pincode=pincode).first()
|
|
|
56 |
if serviceableLocationDetails:
|
|
|
57 |
if serviceabilityPincode['active']:
|
|
|
58 |
serviceableLocationDetails.exp=1
|
|
|
59 |
serviceableLocationDetails.cod=1
|
|
|
60 |
else:
|
|
|
61 |
serviceableLocationDetails.exp=0
|
|
|
62 |
serviceableLocationDetails.cod=0
|
|
|
63 |
|
|
|
64 |
elif serviceabilityPincode['active']:
|
|
|
65 |
missingPincodes.append(pincode)
|
|
|
66 |
print missingPincodes
|
|
|
67 |
if missingPincodes:
|
|
|
68 |
subject += " - " + ", ".join(missingPincodes)
|
| 23839 |
amit.gupta |
69 |
mail("cnc.center@shop2020.in", "5h0p2o2o", ["deena.nath@smartdukaan.com"], subject, text="")
|
| 23235 |
amit.gupta |
70 |
|
|
|
71 |
session.commit()
|
|
|
72 |
except:
|
|
|
73 |
print "problem updating pincodes"
|
| 23238 |
amit.gupta |
74 |
print "After Error"
|
| 23141 |
amit.gupta |
75 |
#add_new_awbs(provider_id, isCod, awbs, awbUsedFor)
|
|
|
76 |
prepaidCount = Awb.query.filter_by(provider_id = provider_id, is_available = True, type='Prepaid').count()
|
|
|
77 |
if prepaidCount < 100:
|
|
|
78 |
prepaidAwbs = EcomExpressService.generate_awb(DeliveryType.PREPAID)
|
|
|
79 |
add_empty_AWBs(prepaidAwbs, 49, "Prepaid")
|
|
|
80 |
|
|
|
81 |
codCount = Awb.query.filter_by(provider_id = provider_id, is_available = True, type='COD').count()
|
|
|
82 |
if codCount < 100:
|
| 23249 |
amit.gupta |
83 |
codAwbs = EcomExpressService.generate_awb(DeliveryType.COD)
|
| 23141 |
amit.gupta |
84 |
add_empty_AWBs(codAwbs, 49, "COD")
|
|
|
85 |
|
|
|
86 |
session.close()
|
|
|
87 |
|
|
|
88 |
|
|
|
89 |
if __name__ == '__main__':
|
|
|
90 |
main()
|