| 1504 |
ankur.sing |
1 |
#!/usr/bin/python
|
|
|
2 |
|
| 4090 |
chandransh |
3 |
'''
|
|
|
4 |
Loads the static logic of assigning provider to a particular pincode
|
|
|
5 |
into the DestinationProviderAllocation table.
|
|
|
6 |
|
|
|
7 |
It reads the logic from a XLS workbook containing two sheets. The first sheet is
|
|
|
8 |
for shipments worth less than Rs 5000. The second sheet is for shipments costing
|
|
|
9 |
more than Rs 5000.
|
|
|
10 |
|
|
|
11 |
@attention: This script may need enhancement if we want to differentiate between
|
|
|
12 |
COD and Prepaid orders.
|
|
|
13 |
|
|
|
14 |
@attention: This table is not being used currently. If and when this comes into
|
|
|
15 |
use, please remember to update the logic of get_logistics_estimation
|
|
|
16 |
in DataAccessor.py.
|
|
|
17 |
|
|
|
18 |
@author: Ankur Singhal
|
|
|
19 |
'''
|
| 23132 |
amit.gupta |
20 |
from datetime import *
|
|
|
21 |
from elixir import *
|
|
|
22 |
from shop2020.logistics.service.impl import DataService, EcomExpressService
|
|
|
23 |
from shop2020.logistics.service.impl.DataService import \
|
|
|
24 |
ServiceableLocationDetails
|
|
|
25 |
from shop2020.utils.EmailAttachmentSender import get_attachment_part, mail
|
| 1504 |
ankur.sing |
26 |
import optparse
|
|
|
27 |
|
|
|
28 |
if __name__ == '__main__' and __package__ is None:
|
|
|
29 |
import sys
|
|
|
30 |
import os
|
|
|
31 |
sys.path.insert(0, os.getcwd())
|
|
|
32 |
|
|
|
33 |
|
|
|
34 |
|
|
|
35 |
def main():
|
|
|
36 |
parser = optparse.OptionParser()
|
| 4014 |
chandransh |
37 |
parser.add_option("-H", "--host", dest="hostname",
|
|
|
38 |
default="localhost",
|
|
|
39 |
type="string", help="The HOST where the DB server is running",
|
|
|
40 |
metavar="HOST")
|
| 23132 |
amit.gupta |
41 |
parser.add_option("-P", "--provider_id", dest="provider_id",
|
|
|
42 |
default="localhost",
|
|
|
43 |
type="string", help="The HOST where the DB server is running",
|
|
|
44 |
metavar="HOST")
|
| 1504 |
ankur.sing |
45 |
(options, args) = parser.parse_args()
|
|
|
46 |
if len(args) != 0:
|
|
|
47 |
parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
|
| 23132 |
amit.gupta |
48 |
provider_id = options.provider_id
|
|
|
49 |
hostname = options.hostname
|
|
|
50 |
if provider_id is None or hostname is None:
|
|
|
51 |
parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
|
|
|
52 |
|
|
|
53 |
DataService.initialize(dbname='logistics', db_hostname=hostname)
|
|
|
54 |
if provider_id=="49":
|
|
|
55 |
subject = "Tat is missing for Ecom Express active pincodes"
|
|
|
56 |
missingPincodes = []
|
|
|
57 |
serviceabilityPincodeList = EcomExpressService.getServiceablePinCodes(datetime.now()-timedelta(days=5))
|
|
|
58 |
#print "serviceabilityPincodeList", serviceabilityPincodeList
|
|
|
59 |
for serviceabilityPincode in serviceabilityPincodeList:
|
|
|
60 |
pincode = str(serviceabilityPincode["pincode"])
|
|
|
61 |
serviceableLocationDetails = ServiceableLocationDetails.query.filter_by(provider_id=int(provider_id)).filter_by(dest_pincode=pincode).first()
|
|
|
62 |
if serviceableLocationDetails:
|
|
|
63 |
if serviceabilityPincode['active']:
|
|
|
64 |
serviceableLocationDetails.exp=1
|
|
|
65 |
serviceableLocationDetails.cod=1
|
|
|
66 |
else:
|
|
|
67 |
serviceableLocationDetails.exp=0
|
|
|
68 |
serviceableLocationDetails.cod=0
|
|
|
69 |
|
|
|
70 |
elif serviceabilityPincode['active']:
|
|
|
71 |
missingPincodes.append(pincode)
|
|
|
72 |
print missingPincodes
|
|
|
73 |
if missingPincodes:
|
|
|
74 |
subject += " - " + ", ".join(missingPincodes)
|
| 23839 |
amit.gupta |
75 |
mail("cnc.center@shop2020.in", "5h0p2o2o", ["deena.nath@smartdukaan.com"], subject, text="")
|
| 23132 |
amit.gupta |
76 |
|
|
|
77 |
session.commit()
|
|
|
78 |
session.close()
|
|
|
79 |
|
|
|
80 |
|
| 1504 |
ankur.sing |
81 |
if __name__ == '__main__':
|
|
|
82 |
main()
|