| 20718 |
kshitij.so |
1 |
from suds.client import Client
|
|
|
2 |
from shop2020.clients.TransactionClient import TransactionClient
|
|
|
3 |
from datetime import datetime, time, timedelta
|
|
|
4 |
import traceback
|
|
|
5 |
|
|
|
6 |
raclient = None
|
|
|
7 |
user_profile = None
|
|
|
8 |
shipper = None
|
|
|
9 |
|
|
|
10 |
DEBUG=True
|
|
|
11 |
|
|
|
12 |
acc_url="http://netconnect.bluedart.com/Ver1.7/Demo/ShippingAPI/WayBill/WayBillGeneration.svc?wsdl"
|
|
|
13 |
LOGIN_ID ="FA316326"
|
|
|
14 |
LICENCE_KEY="5f1740fdfb8196e7980faea7fe52dd0d"
|
|
|
15 |
API_VERSION="1.7"
|
|
|
16 |
API_TYPE="S"
|
|
|
17 |
AREA="ALL"
|
|
|
18 |
|
|
|
19 |
def get_client():
|
|
|
20 |
global raclient
|
|
|
21 |
if raclient is None:
|
|
|
22 |
raclient = Client(acc_url, timeout=70)
|
|
|
23 |
return raclient
|
|
|
24 |
else:
|
|
|
25 |
return raclient
|
|
|
26 |
|
|
|
27 |
def get_profile():
|
|
|
28 |
global user_profile
|
|
|
29 |
if user_profile is None:
|
|
|
30 |
profile = get_client().factory.create('ns0:UserProfile')
|
|
|
31 |
profile.Api_type = API_TYPE
|
|
|
32 |
profile.Area = AREA
|
|
|
33 |
profile.LicenceKey = LICENCE_KEY
|
|
|
34 |
profile.LoginID = LOGIN_ID
|
|
|
35 |
profile.Version = API_VERSION
|
|
|
36 |
user_profile = profile
|
|
|
37 |
return user_profile
|
|
|
38 |
|
|
|
39 |
def get_shipper_object():
|
|
|
40 |
global shipper
|
|
|
41 |
if shipper is None:
|
|
|
42 |
ship = get_client().factory.create('ns2:Shipper')
|
|
|
43 |
ship.CustomerName="Adonis Mobitrade Pvt Ltd"
|
|
|
44 |
ship.CustomerAddress1 ="Plot No. 485"
|
|
|
45 |
ship.CustomerAddress2 = "Udyog Vihar Phase V"
|
|
|
46 |
ship.CustomerAddress3 ="Gurgoan 122016"
|
|
|
47 |
ship.CustomerCode = "316326"
|
|
|
48 |
ship.CustomerMobile = "9311608716"
|
|
|
49 |
ship.VendorCode="AMPFAR"
|
|
|
50 |
ship.OriginArea = "FAR"
|
|
|
51 |
ship.CustomerPincode = "122016"
|
|
|
52 |
ship.Sender = "ADONIS MOBITRADE"
|
|
|
53 |
ship.CustomerTelephone="9311608716"
|
|
|
54 |
shipper = ship
|
|
|
55 |
return shipper
|
|
|
56 |
|
|
|
57 |
def generate_awb(orders_list):
|
|
|
58 |
try:
|
|
|
59 |
if not isinstance(orders_list, list) or not orders_list:
|
|
|
60 |
return ""
|
|
|
61 |
consignee = get_client().factory.create('ns2:Consignee')
|
|
|
62 |
consignee.ConsigneeAddress1 = orders_list[0].customer_address1
|
|
|
63 |
if orders_list[0].customer_address2:
|
|
|
64 |
consignee.ConsigneeAddress2 = orders_list[0].customer_address2
|
|
|
65 |
consignee.ConsigneeAddress3 = orders_list[0].customer_city+" "+orders_list[0].customer_state
|
|
|
66 |
else:
|
|
|
67 |
consignee.ConsigneeAddress2 = orders_list[0].customer_city
|
|
|
68 |
consignee.ConsigneeAttention = orders_list[0].customer_name
|
|
|
69 |
consignee.ConsigneeMobile = orders_list[0].customer_mobilenumber
|
|
|
70 |
consignee.ConsigneeName = orders_list[0].customer_name
|
|
|
71 |
consignee.ConsigneePincode = orders_list[0].customer_pincode
|
|
|
72 |
consignee.ConsigneeTelephone = orders_list[0].customer_mobilenumber
|
|
|
73 |
ser = get_client().factory.create('ns2:Services')
|
|
|
74 |
productType = get_client().factory.create('ns1:ProductType')
|
|
|
75 |
actual_weight = 0.0
|
|
|
76 |
collectable_amount = 0.0
|
|
|
77 |
declared_value = 0.0
|
|
|
78 |
quantity = 0
|
|
|
79 |
isCod = orders_list[0].cod
|
|
|
80 |
for order in orders_list:
|
|
|
81 |
line_item = order.lineitems[0]
|
|
|
82 |
actual_weight += line_item.total_weight
|
|
|
83 |
collectable_amount += order.total_amount + order.shippingCost
|
|
|
84 |
declared_value += order.total_amount
|
|
|
85 |
quantity += line_item.quantity
|
|
|
86 |
ser.ActualWeight = actual_weight
|
|
|
87 |
ser.CreditReferenceNo = orders_list[0].logisticsTransactionId
|
|
|
88 |
ser.DeclaredValue = declared_value
|
|
|
89 |
ser.ProductCode = "A"
|
|
|
90 |
ser.ProductType = productType.Dutiables
|
|
|
91 |
ser.PieceCount = int(quantity)
|
|
|
92 |
now_time = datetime.now().time()
|
|
|
93 |
if now_time <= time(19,00):
|
|
|
94 |
ser.PickupDate = datetime.today().strftime('%Y-%m-%d')
|
|
|
95 |
else:
|
|
|
96 |
ser.PickupDate = (datetime.now()+timedelta(days=1)).strftime('%Y-%m-%d')
|
|
|
97 |
ser.PickupTime="1900"
|
|
|
98 |
ser.IsReversePickup = False
|
|
|
99 |
ser.PDFOutputNotRequired = True
|
|
|
100 |
ser.RegisterPickup = False
|
|
|
101 |
if isCod:
|
|
|
102 |
ser.CollectableAmount = collectable_amount
|
|
|
103 |
ser.SubProductCode = "C"
|
|
|
104 |
wbg = get_client().factory.create('ns2:WayBillGenerationRequest')
|
|
|
105 |
wbg.Consignee = consignee
|
|
|
106 |
wbg.Services = ser
|
|
|
107 |
wbg.Shipper = get_shipper_object()
|
|
|
108 |
|
|
|
109 |
d= get_client().factory.create('ns2:Dimension')
|
|
|
110 |
d.Count=0
|
|
|
111 |
ser.Dimensions=[d]
|
|
|
112 |
print get_client().service.GenerateWayBill(wbg, get_profile())
|
|
|
113 |
except:
|
|
|
114 |
print traceback.print_exc()
|
|
|
115 |
finally:
|
|
|
116 |
if DEBUG:
|
|
|
117 |
print get_client().last_sent()
|
|
|
118 |
print get_client().last_received()
|
|
|
119 |
|
|
|
120 |
def main():
|
|
|
121 |
tc = TransactionClient().get_client()
|
|
|
122 |
orders = tc.getOrderList([1546485])
|
|
|
123 |
generate_awb(orders)
|
|
|
124 |
|
|
|
125 |
|
|
|
126 |
|
|
|
127 |
if __name__ == '__main__':
|
|
|
128 |
main()
|