| 5677 |
rajveer |
1 |
#!/usr/bin/python
|
|
|
2 |
|
|
|
3 |
'''
|
|
|
4 |
Send mail to courier partners to pickup the orders from store.
|
|
|
5 |
|
|
|
6 |
Created on 26-Jul-2012
|
|
|
7 |
|
|
|
8 |
@author: Rajveer
|
|
|
9 |
'''
|
|
|
10 |
import xlwt
|
|
|
11 |
import datetime
|
|
|
12 |
from optparse import OptionParser
|
|
|
13 |
from textwrap import dedent
|
|
|
14 |
|
|
|
15 |
|
|
|
16 |
|
|
|
17 |
if __name__ == '__main__' and __package__ is None:
|
|
|
18 |
import sys
|
|
|
19 |
import os
|
|
|
20 |
sys.path.insert(0, os.getcwd())
|
|
|
21 |
|
|
|
22 |
from shop2020.model.v1.order.impl import DataService
|
|
|
23 |
from shop2020.model.v1.order.impl.DataService import Order
|
|
|
24 |
from shop2020.thriftpy.model.v1.order.ttypes import OrderStatus
|
|
|
25 |
from shop2020.clients.LogisticsClient import LogisticsClient
|
|
|
26 |
from shop2020.thriftpy.logistics.ttypes import PickupStore, DeliveryType
|
|
|
27 |
from shop2020.clients.CatalogClient import CatalogClient
|
|
|
28 |
from shop2020.utils.EmailAttachmentSender import mail, get_attachment_part
|
|
|
29 |
|
|
|
30 |
|
|
|
31 |
def process_pickup_store_returns():
|
|
|
32 |
DataService.initialize(db_hostname="192.168.190.114", echoOn=True)
|
|
|
33 |
to_date = datetime.datetime.today() + datetime.timedelta(days = -5)
|
|
|
34 |
logistics_store_order_mapping = {}
|
|
|
35 |
orders = Order.query.filter(Order.pickupStoreId > 0).filter(Order.delivery_timestamp <= to_date).order_by(Order.pickupStoreId).order_by(Order.logistics_provider_id).order_by(Order.warehouse_id).all()
|
|
|
36 |
for order in orders:
|
|
|
37 |
if logistics_store_order_mapping.has_key(order.pickupStoreId, order.logistics_provider_id, order.warehouse_id):
|
|
|
38 |
logistics_store_order_mapping.get(order.pickupStoreId, order.logistics_provider_id, order.warehouse_id).append(order.id)
|
|
|
39 |
else:
|
|
|
40 |
logistics_store_order_mapping[order.pickupStoreId, order.logistics_provider_id, order.warehouse_id] = [order.id]
|
|
|
41 |
order.status = OrderStatus.RET_PICKUP_REQUEST_RAISED
|
|
|
42 |
order.statusDescription = "Return request raised"
|
|
|
43 |
session.commit()
|
|
|
44 |
|
|
|
45 |
lclient = LogisticsClient().get_client()
|
|
|
46 |
cclient = CatalogClient().get_client()
|
|
|
47 |
for key in logistics_store_order_mapping.iterkeys():
|
|
|
48 |
provider = lclient.getProvider(key[1])
|
|
|
49 |
to_addr = provider.details[DeliveryType.PREPAID].email
|
|
|
50 |
pickupStore = lclient.getPickupStore(key[0])
|
|
|
51 |
warehouse = cclient.getWarehouse(key[2])
|
|
|
52 |
subject = "Pickup request from " + pickupStore.city
|
|
|
53 |
raw_message = '''
|
|
|
54 |
Dear Sir/Madam,
|
|
|
55 |
|
|
|
56 |
Kindly arrange a pickup today from %(customer_city)s. Pickup and delivery addresses are mentioned below.
|
|
|
57 |
|
|
|
58 |
Pickup Order Ids: %(order_ids)
|
|
|
59 |
|
|
|
60 |
Pickup CODE: %(provider_code)s
|
|
|
61 |
|
|
|
62 |
Pickup Address:
|
|
|
63 |
|
|
|
64 |
%(customer_address)s
|
|
|
65 |
|
|
|
66 |
Delivery Address:
|
|
|
67 |
|
|
|
68 |
%(warehouse_executive)s
|
|
|
69 |
%(warehouse_address)s
|
|
|
70 |
PIN %(warehouse_pin)s
|
|
|
71 |
|
|
|
72 |
Thanks and Regards
|
|
|
73 |
Sandeep Sachdeva
|
|
|
74 |
'''
|
|
|
75 |
|
|
|
76 |
if warehouse.id == 7:
|
|
|
77 |
executive = 'Amit Kumar'
|
|
|
78 |
else:
|
|
|
79 |
executive = 'Dinesh Kumar'
|
|
|
80 |
|
|
|
81 |
address = pickupStore.name + "\n" + pickupStore.line1 + "\n"
|
|
|
82 |
if pickupStore.line2:
|
|
|
83 |
address = address + pickupStore.line2 + "\n"
|
|
|
84 |
address = address + pickupStore.city + "\n"
|
|
|
85 |
address = address + pickupStore.state + "\n"
|
|
|
86 |
address = address + "PIN " + pickupStore.pin + "\n"
|
|
|
87 |
address = address + "Phone: " + pickupStore.phone
|
|
|
88 |
|
|
|
89 |
order_ids = ""
|
|
|
90 |
order_ids.join(logistics_store_order_mapping.get(key))
|
|
|
91 |
|
|
|
92 |
message = dedent(raw_message) % { 'customer_city' : pickupStore.city,
|
|
|
93 |
'provider_code' : provider.details[DeliveryType.PREPAID].accountNo,
|
|
|
94 |
'order_weight' : str(0.5),
|
|
|
95 |
'customer_address' : address,
|
|
|
96 |
'warehouse_executive' : executive,
|
|
|
97 |
'warehouse_address' : warehouse.location,
|
|
|
98 |
'warehouse_pin' : warehouse.pincode,
|
|
|
99 |
'order_ids' : order_ids}
|
|
|
100 |
to_addresses = [to_addr, 'suraj.sharma@shop2020.in']
|
|
|
101 |
|
|
|
102 |
mail('cnc.center@shop2020.in', '5h0p2o2o', to_addresses, subject, message)
|
|
|
103 |
|
|
|
104 |
def main():
|
|
|
105 |
process_pickup_store_returns()
|
|
|
106 |
|
|
|
107 |
if __name__ == '__main__':
|
|
|
108 |
main()
|