| 5201 |
rajveer |
1 |
#!/usr/bin/python
|
|
|
2 |
|
|
|
3 |
import optparse
|
|
|
4 |
import sys
|
|
|
5 |
from elixir import session
|
|
|
6 |
|
|
|
7 |
if __name__ == '__main__' and __package__ is None:
|
|
|
8 |
import os
|
|
|
9 |
sys.path.insert(0, os.getcwd())
|
|
|
10 |
|
|
|
11 |
from shop2020.clients.LogisticsClient import LogisticsClient
|
|
|
12 |
from shop2020.thriftpy.logistics.ttypes import DeliveryType
|
|
|
13 |
|
|
|
14 |
from shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceException
|
|
|
15 |
from shop2020.model.v1.order.impl import DataService
|
|
|
16 |
from shop2020.model.v1.order.impl.DataAccessors import close_session, get_orders_in_batch
|
|
|
17 |
|
|
|
18 |
def update_awb(order):
|
|
|
19 |
logistics_client = LogisticsClient().get_client()
|
|
|
20 |
item_id = order.lineitems[0].item_id
|
|
|
21 |
logistics_info = logistics_client.getLogisticsInfo(order.customer_pincode, item_id, DeliveryType.COD)
|
|
|
22 |
print order.id, "OLD AWB: " + order.airwaybill_no + " NEW AWB"+ logistics_info.airway_billno
|
|
|
23 |
order.airwaybill_no = logistics_info.airway_billno
|
|
|
24 |
order.tracking_id = order.airwaybill_no
|
|
|
25 |
session.commit()
|
|
|
26 |
|
|
|
27 |
|
|
|
28 |
|
|
|
29 |
def main():
|
|
|
30 |
parser = optparse.OptionParser()
|
|
|
31 |
parser.add_option("-H", "--host", dest="hostname",
|
|
|
32 |
default="localhost",
|
|
|
33 |
type="string", help="The HOST where the DB server is running",
|
|
|
34 |
metavar="HOST")
|
|
|
35 |
(options, args) = parser.parse_args()
|
|
|
36 |
if len(args) != 0:
|
|
|
37 |
parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
|
|
|
38 |
DataService.initialize(db_hostname=options.hostname, echoOn=False)
|
|
|
39 |
|
|
|
40 |
try:
|
|
|
41 |
orders = get_orders_in_batch([2,3,5,35,36,37,38,39], 0, 0, 0)
|
|
|
42 |
for order in orders:
|
|
|
43 |
#print order.cod, order.logistics_provider_id, order.airwaybill_no
|
|
|
44 |
if not (order.cod == 1 and order.logistics_provider_id == 1 and order.id < 132904):
|
|
|
45 |
continue
|
|
|
46 |
#print order.id, order.cod, order.logistics_provider_id, order.airwaybill_no
|
|
|
47 |
update_awb(order)
|
|
|
48 |
#print order.airwaybill_no
|
|
|
49 |
except TransactionServiceException as tsex:
|
|
|
50 |
print tsex.message
|
|
|
51 |
finally:
|
|
|
52 |
close_session()
|
|
|
53 |
|
|
|
54 |
if __name__ == '__main__':
|
|
|
55 |
main()
|
|
|
56 |
|