Subversion Repositories SmartDukaan

Rev

Rev 22636 | Rev 22752 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 22636 Rev 22749
Line -... Line 1...
-
 
1
from docutils.utils.math.math2html import URL
-
 
2
from shop2020.clients import TransactionClient
-
 
3
from shop2020.clients.LogisticsClient import LogisticsClient
-
 
4
from shop2020.config.client.ConfigClient import ConfigClient
1
from shop2020.thriftpy.logistics.ttypes import DeliveryType
5
from shop2020.thriftpy.logistics.ttypes import DeliveryType
-
 
6
from shop2020.thriftpy.model.v1.order.ttypes import Order
-
 
7
import json
2
import urllib
8
import urllib
3
import urllib2
9
import urllib2
4
import json
-
 
5
 
10
 
-
 
11
cc = ConfigClient()
-
 
12
live = cc.get_property("live")
-
 
13
 
-
 
14
warehouseMap = {}
-
 
15
 
6
#Live
16
if live=="true":
7
#username = 'ecomexpress'
17
    username = 'ecomexpress'
8
#password = 'Ke$3c@4oT5m6h#$'
18
    password = 'Ke$3c@4oT5m6h#$'
9
#wayBillApi = "http://staging.ecomexpress.in/apiv2/fetch_awb/";
19
    wayBillApi = 'http://staging.ecomexpress.in/apiv2/fetch_awb/'
10
#forwardApi = "http://staging.ecomexpress.in/apiv2/manifest_awb/";
20
    forwardApi = 'http://staging.ecomexpress.in/apiv2/manifest_awb/'
11
 
-
 
-
 
21
    consignee = ''
12
#Test
22
else:
13
username = 'ecomexpress'
23
    username = 'ecomexpress'
14
password = 'Ke$3c@4oT5m6h#$'
24
    password = 'Ke$3c@4oT5m6h#$'
15
wayBillApi = "http://staging.ecomexpress.in/apiv2/fetch_awb/";
25
    wayBillApi = 'http://staging.ecomexpress.in/apiv2/fetch_awb/'
16
forwardApi = "http://staging.ecomexpress.in/apiv2/manifest_awb/";
26
    forwardApi = 'http://staging.ecomexpress.in/apiv2/manifest_awb/'
-
 
27
    consignee = 'TEST'
-
 
28
    
-
 
29
F_AWB_NUMBER = "AWB_NUMBER" 
-
 
30
F_ORDER_NUMBER = "ORDER_NUMBER" 
-
 
31
F_PRODUCT = "PRODUCT" 
-
 
32
F_CONSIGNEE = "CONSIGNEE" 
-
 
33
F_CONSIGNEE_ADDRESS1 = "CONSIGNEE_ADDRESS1" 
-
 
34
F_CONSIGNEE_ADDRESS2 = "CONSIGNEE_ADDRESS2" 
-
 
35
F_DESTINATION_CITY = "DESTINATION_CITY" 
-
 
36
F_PINCODE = "PINCODE" 
-
 
37
F_STATE = "STATE" 
-
 
38
F_MOBILE = "MOBILE" 
-
 
39
F_ITEM_DESCRIPTION = "ITEM_DESCRIPTION" 
-
 
40
F_PIECES = "PIECES" 
-
 
41
F_COLLECTABLE_VALUE = "COLLECTABLE_VALUE" 
-
 
42
F_DECLARED_VALUE = "DECLARED_VALUE" 
-
 
43
F_ACTUAL_WEIGHT = "ACTUAL_WEIGHT" 
-
 
44
F_VOLUMETRIC_WEIGHT = "VOLUMETRIC_WEIGHT" 
-
 
45
F_LENGTH = "LENGTH" 
-
 
46
F_BREADTH = "BREADTH" 
-
 
47
F_HEIGHT = "HEIGHT" 
-
 
48
F_PICKUP_NAME = "PICKUP_NAME" 
-
 
49
F_PICKUP_ADDRESS_LINE1 = "PICKUP_ADDRESS_LINE1" 
-
 
50
F_PICKUP_ADDRESS_LINE2 = "PICKUP_ADDRESS_LINE2" 
-
 
51
F_PICKUP_PINCODE = "PICKUP_PINCODE" 
-
 
52
F_PICKUP_PHONE = "PICKUP_PHONE" 
-
 
53
F_PICKUP_MOBILE = "PICKUP_MOBILE" 
-
 
54
F_RETURN_NAME = "RETURN_NAME" 
-
 
55
F_RETURN_ADDRESS_LINE1 = "RETURN_ADDRESS_LINE1" 
-
 
56
F_RETURN_ADDRESS_LINE2 = "RETURN_ADDRESS_LINE2" 
-
 
57
F_RETURN_PINCODE = "RETURN_PINCODE" 
-
 
58
F_RETURN_PHONE = "RETURN_PHONE" 
-
 
59
F_RETURN_MOBILE = "RETURN_MOBILE" 
-
 
60
F_DG_SHIPMENT = "DG_SHIPMENT" 
-
 
61
F_INVOICE_NUMBER = "INVOICE_NUMBER" 
-
 
62
F_INVOICE_DATE = "INVOICE_DATE" 
-
 
63
F_ITEM_CATEGORY = "ITEM_CATEGORY" 
-
 
64
F_PACKING_TYPE = "PACKING_TYPE" 
-
 
65
F_PICKUP_TYPE = "PICKUP_TYPE" 
-
 
66
F_RETURN_TYPE = "RETURN_TYPE" 
-
 
67
F_PICKUP_LOCATION_CODE = "PICKUP_LOCATION_CODE" 
-
 
68
F_SELLER_GSTIN = "SELLER_GSTIN" 
-
 
69
F_GST_HSN = "GST_HSN" 
-
 
70
F_GST_ERN = "GST_ERN" 
-
 
71
F_GST_TAX_NAME = "GST_TAX_NAME"
-
 
72
F_GST_TAX_BASE = "GST_TAX_BASE"
-
 
73
F_GST_TAX_RATE_CGSTN = "GST_TAX_RATE_CGSTN"
-
 
74
F_GST_TAX_RATE_SGSTN = "GST_TAX_RATE_SGSTN"
-
 
75
F_GST_TAX_RATE_IGSTN = "GST_TAX_RATE_IGSTN"
-
 
76
F_GST_TAX_TOTAL = "GST_TAX_TOTAL"
17
 
77
 
18
#returns list of awb of specified type
78
#returns list of awb of specified type
-
 
79
#will generate 500 awbs at once
19
def generate_awb(deliveryType):
80
def generate_awb(deliveryType):
20
    if deliveryType == DeliveryType.COD:
81
    if deliveryType == DeliveryType.COD:
21
        ecomDeliveryType = "COD"
82
        ecomDeliveryType = "COD"
22
    if deliveryType == DeliveryType.PREPAID:
83
    if deliveryType == DeliveryType.PREPAID:
23
        ecomDeliveryType = "PPD"
84
        ecomDeliveryType = "PPD"
24
    values = {'username' : username,
85
    values = {'username' : username,
25
              'password' : password,
86
              'password' : password,
26
              'count' : '100',
87
              'count' : '500',
27
              'type' : ecomDeliveryType }
88
              'type' : ecomDeliveryType }
28
 
89
 
29
    data = urllib.urlencode(values)
90
    data = urllib.urlencode(values)
30
    req = urllib2.Request(wayBillApi, data)
91
    req = urllib2.Request(wayBillApi, data)
31
    response = urllib2.urlopen(req)
92
    response = urllib2.urlopen(req)
32
    the_page = response.read()
93
    the_page = response.read()
33
    return json.loads(the_page)['awb']
94
    return json.loads(the_page)['awb']
34
 
95
 
-
 
96
#All orders awbwise
-
 
97
#{'awb':[o1, o2, o3]}
-
 
98
def forward_request(ordersMap): 
-
 
99
    values = {'username' : username,
-
 
100
              'password' : password,
-
 
101
              'json_input' : _forwardMap(ordersMap),
-
 
102
              }
-
 
103
    data = urllib.urlencode(values)
-
 
104
    req = urllib2.Request(wayBillApi, data)
-
 
105
    response = urllib2.urlopen(req)
-
 
106
    the_page = response.read()
-
 
107
    print the_page
-
 
108
    
-
 
109
def _forwardMap(ordersMap):
-
 
110
    shipments = []
-
 
111
    for orders in ordersMap.itervalues():
-
 
112
        shipments.append(_createShipment(orders))
-
 
113
    return shipments    
-
 
114
    
-
 
115
        
-
 
116
def _createShipment(orders):
-
 
117
    shipment = {}
-
 
118
    total_payable = 0
-
 
119
    total_pieces = 0
-
 
120
    declared_value = 0
-
 
121
    total_weight = 0
-
 
122
    order1 = Order()
-
 
123
    for order1 in orders:
-
 
124
        total_payable += order1.net_payable_amount
-
 
125
        total_pieces += order1.lineitems[0].quantity
-
 
126
        declared_value += order1.total_amount + order1.shippingCost
-
 
127
        total_weight += order1.total_weight
-
 
128
    order = Order()
-
 
129
    warehouseAddressObj = get_shipper_object(order.warehouse_address_id)
-
 
130
    shipment[F_AWB_NUMBER] = order.airwaybill_no
-
 
131
    shipment[F_ORDER_NUMBER] = order.logisticsTransactionId 
-
 
132
    shipment[F_PRODUCT] = 'COD' if order.cod and total_payable > 0 else 'PPD' 
-
 
133
    shipment[F_CONSIGNEE] = order.customer_name 
-
 
134
    shipment[F_CONSIGNEE_ADDRESS1] = order.customer_address1 
-
 
135
    shipment[F_CONSIGNEE_ADDRESS2] = order.customer_address2
-
 
136
    shipment[F_DESTINATION_CITY] = order.customer_city 
-
 
137
    shipment[F_PICKUP_PINCODE] = order.customer_pincode 
-
 
138
    shipment[F_STATE] = order.customer_state
-
 
139
    shipment[F_MOBILE] = order.customer_mobilenumber 
-
 
140
    shipment[F_ITEM_DESCRIPTION] = '' 
-
 
141
    shipment[F_PIECES] = total_pieces
-
 
142
    shipment[F_COLLECTABLE_VALUE] = total_payable if order.cod else 0
-
 
143
    shipment[F_DECLARED_VALUE] = declared_value 
-
 
144
    shipment[F_ACTUAL_WEIGHT] = total_weight 
-
 
145
    #shipment[F_VOLUMETRIC_WEIGHT]
-
 
146
    shipment[F_LENGTH] = 10
-
 
147
    shipment[F_BREADTH] = 10
-
 
148
    shipment[F_HEIGHT] = 10
-
 
149
    shipment[F_PICKUP_NAME] = warehouseAddressObj.contact_person
-
 
150
    shipment[F_PICKUP_ADDRESS_LINE1] = warehouseAddressObj.address
-
 
151
    #shipment[F_PICKUP_ADDRESS_LINE2] = ''
-
 
152
    shipment[F_PICKUP_PINCODE] = warehouseAddressObj.pin
-
 
153
    shipment[F_PICKUP_MOBILE] = warehouseAddressObj.contact_number
-
 
154
    shipment[F_PICKUP_PHONE] = warehouseAddressObj.contact_number
35
 
155
    
-
 
156
    shipment[F_RETURN_NAME] = warehouseAddressObj.contact_person
-
 
157
    shipment[F_RETURN_ADDRESS_LINE1] = warehouseAddressObj.address
-
 
158
    #shipment[F_RETURN_ADDRESS_LINE2] = ''
-
 
159
    shipment[F_RETURN_PINCODE] = warehouseAddressObj.pin
-
 
160
    shipment[F_RETURN_MOBILE] = warehouseAddressObj.contact_number
-
 
161
    shipment[F_RETURN_PHONE] = warehouseAddressObj.contact_number
-
 
162
    shipment[F_DG_SHIPMENT] = 'false'
-
 
163
    shipment["ADDITIONAL_INFORMATION"] = {"MULTI_SELLER_INFORMATION": _getMultiSellerInfo(orders)} 
36
 
164
    
-
 
165
def _getMultiSellerInfo(orders):
37
 
166
    
38
 
167
 
39
def main():
168
def main():
-
 
169
    lc = LogisticsClient().get_client()
40
    print generate_awb(DeliveryType.PREPAID)
170
    print lc.getEmptyAWB(48, '731467')
41
    
171
    
42
    
172
    
43
 
173
 
44
if __name__ == '__main__':
174
if __name__ == '__main__':
45
    main()
-
 
46
175
    ordersMap = {}
-
 
176
    forward_request(ordersMap)
-
 
177
    
-
 
178
    
-
 
179
    
-
 
180
    
-
 
181
    
-
 
182
    
-
 
183
    
-
 
184
def get_shipper_object(address_id):
-
 
185
    global shipperMap
-
 
186
    if shipperMap.has_key(address_id):
-
 
187
        return shipperMap.get(address_id)
-
 
188
    else:
-
 
189
        tc = TransactionClient().get_client()
-
 
190
        info = tc.getBuyerByWarehouse(address_id)
-
 
191
        if info is None:
-
 
192
            raise RuntimeError("Buyer address mapping is None")
-
 
193
        shipperMap[address_id] = info
-
 
194
    return shipperMap.get(address_id)
-
 
195
47
196