| 1911 |
chandransh |
1 |
#!/usr/bin/python
|
|
|
2 |
|
| 4016 |
chandransh |
3 |
import optparse
|
| 1911 |
chandransh |
4 |
import time
|
|
|
5 |
import datetime
|
|
|
6 |
import sys
|
|
|
7 |
from elixir import session
|
| 5246 |
rajveer |
8 |
from shop2020.clients.LogisticsClient import LogisticsClient
|
| 1911 |
chandransh |
9 |
|
|
|
10 |
if __name__ == '__main__' and __package__ is None:
|
|
|
11 |
import os
|
|
|
12 |
sys.path.insert(0, os.getcwd())
|
|
|
13 |
|
| 5246 |
rajveer |
14 |
from shop2020.thriftpy.model.v1.order.ttypes import OrderStatus, TransactionServiceException
|
| 1911 |
chandransh |
15 |
from shop2020.model.v1.order.impl import DataService
|
| 5246 |
rajveer |
16 |
from shop2020.model.v1.order.impl.DataAccessors import get_order, close_session
|
| 1911 |
chandransh |
17 |
|
|
|
18 |
|
| 5246 |
rajveer |
19 |
def change_logistics_provider(order):
|
| 1911 |
chandransh |
20 |
'''
|
| 5246 |
rajveer |
21 |
Ship the order through different vendor.
|
| 1911 |
chandransh |
22 |
'''
|
| 5246 |
rajveer |
23 |
if order.status not in [OrderStatus.COD_VERIFICATION_PENDING, OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.INVENTORY_LOW, OrderStatus.ACCEPTED]:
|
| 1939 |
chandransh |
24 |
print "This order has already been processed. Please seek help from engineering."
|
|
|
25 |
return
|
|
|
26 |
|
| 5246 |
rajveer |
27 |
raw_provider_id = raw_input("Enter the ID of the provider that you want to ship through: ")
|
| 1939 |
chandransh |
28 |
try:
|
| 5246 |
rajveer |
29 |
provider_id = int(raw_provider_id)
|
| 1939 |
chandransh |
30 |
except ValueError:
|
| 5246 |
rajveer |
31 |
print("Invalid provider Id")
|
| 1939 |
chandransh |
32 |
return
|
|
|
33 |
|
| 5246 |
rajveer |
34 |
if order.logistics_provider_id == provider_id:
|
|
|
35 |
print("Provider Id entered by you is same as provider assigned to order.")
|
| 1939 |
chandransh |
36 |
return
|
| 2091 |
chandransh |
37 |
|
| 5246 |
rajveer |
38 |
logistics_client = LogisticsClient().get_client()
|
|
|
39 |
awb_number = logistics_client.getEmptyAWB(provider_id, order.cod)
|
|
|
40 |
order.logistics_provider_id = provider_id
|
|
|
41 |
order.airwaybill_no = awb_number
|
|
|
42 |
order.track_id = awb_number
|
| 1939 |
chandransh |
43 |
session.commit()
|
|
|
44 |
|
| 5246 |
rajveer |
45 |
print("Successfully updated the provider id")
|
| 2432 |
chandransh |
46 |
|
| 2439 |
chandransh |
47 |
def cancel(order):
|
| 1911 |
chandransh |
48 |
'''
|
|
|
49 |
Cancel
|
|
|
50 |
'''
|
| 1939 |
chandransh |
51 |
print("Your session has been closed")
|
| 2439 |
chandransh |
52 |
return
|
| 1911 |
chandransh |
53 |
|
| 2432 |
chandransh |
54 |
ACTIONS = {0: cancel,
|
| 5246 |
rajveer |
55 |
1: change_logistics_provider
|
| 1911 |
chandransh |
56 |
}
|
|
|
57 |
|
|
|
58 |
def get_py_datetime(time_string):
|
|
|
59 |
time_format = "%Y-%m-%d %H%M"
|
|
|
60 |
mytime = time.strptime(time_string, time_format)
|
|
|
61 |
return datetime.datetime(*mytime[:6])
|
|
|
62 |
|
|
|
63 |
def main():
|
| 4016 |
chandransh |
64 |
parser = optparse.OptionParser()
|
|
|
65 |
parser.add_option("-H", "--host", dest="hostname",
|
|
|
66 |
default="localhost",
|
|
|
67 |
type="string", help="The HOST where the DB server is running",
|
|
|
68 |
metavar="HOST")
|
|
|
69 |
(options, args) = parser.parse_args()
|
|
|
70 |
if len(args) != 0:
|
|
|
71 |
parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
|
|
|
72 |
DataService.initialize(db_hostname=options.hostname, echoOn=False)
|
| 1911 |
chandransh |
73 |
raw_order_id = raw_input("Enter Order Id which you want to modify:")
|
|
|
74 |
try:
|
|
|
75 |
order_id = int(raw_order_id)
|
|
|
76 |
print("You want to modify: " + str(order_id))
|
|
|
77 |
except ValueError:
|
|
|
78 |
print("Invalid Order Id.")
|
|
|
79 |
return
|
|
|
80 |
|
|
|
81 |
try:
|
|
|
82 |
order = get_order(order_id)
|
|
|
83 |
print("Please check the details of the order below and ensure that it's the same order which you want to modify:")
|
|
|
84 |
print("Order Id:\t\t" + str(order.id))
|
|
|
85 |
print("Customer Name:\t\t" + order.customer_name)
|
|
|
86 |
print("Pincode:\t\t" + order.customer_pincode)
|
|
|
87 |
print("Amount:\t\t\t" + str(order.total_amount))
|
|
|
88 |
print("Created On:\t\t" + str(order.created_timestamp))
|
| 5246 |
rajveer |
89 |
print("Current Status:\t\t" + str(order.status))
|
|
|
90 |
print("Status Description:\t\t" + order.statusDescription)
|
|
|
91 |
print("Logistics provider id:\t\t" + str(order.logistics_provider_id))
|
|
|
92 |
print("Airway bill number:\t\t" + order.airwaybill_no)
|
| 1939 |
chandransh |
93 |
print("Ordered Items description:")
|
|
|
94 |
for lineitem in order.lineitems:
|
|
|
95 |
print("Item Id:" + str(lineitem.item_id) + "\tBrand: " + str(lineitem.brand) + "\tModel: " + str(lineitem.model_number) + "\tColor: " + str(lineitem.color))
|
| 1911 |
chandransh |
96 |
print
|
|
|
97 |
print
|
|
|
98 |
print("You can perform following operations:")
|
|
|
99 |
for (key, val) in ACTIONS.iteritems():
|
|
|
100 |
print("[" + str(key) + "]" + val.__doc__ )
|
|
|
101 |
|
|
|
102 |
raw_action = raw_input("What do you want to do? ")
|
| 1939 |
chandransh |
103 |
if raw_action is None or raw_action == "":
|
| 1911 |
chandransh |
104 |
print("Your session has been closed.")
|
|
|
105 |
return
|
|
|
106 |
try:
|
|
|
107 |
action = int(raw_action)
|
|
|
108 |
except ValueError:
|
|
|
109 |
print("Invalid input.")
|
|
|
110 |
return
|
| 2439 |
chandransh |
111 |
if action > max(ACTIONS.keys()):
|
| 1911 |
chandransh |
112 |
print("Invalid input.")
|
|
|
113 |
return
|
| 2432 |
chandransh |
114 |
ACTIONS[action](order)
|
| 1911 |
chandransh |
115 |
except TransactionServiceException as tsex:
|
|
|
116 |
print tsex.message
|
|
|
117 |
finally:
|
|
|
118 |
close_session()
|
|
|
119 |
|
|
|
120 |
if __name__ == '__main__':
|
|
|
121 |
main()
|