Rev 22749 | Rev 22919 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
from docutils.utils.math.math2html import URLfrom shop2020.clients import TransactionClientfrom shop2020.clients.LogisticsClient import LogisticsClientfrom shop2020.config.client.ConfigClient import ConfigClientfrom shop2020.thriftpy.logistics.ttypes import DeliveryTypefrom shop2020.thriftpy.model.v1.order.ttypes import Orderimport jsonimport urllibimport urllib2cc = ConfigClient()live = cc.get_property("live")warehouseMap = {}if live=="true":username = 'ecomexpress'password = 'Ke$3c@4oT5m6h#$'wayBillApi = 'http://staging.ecomexpress.in/apiv2/fetch_awb/'forwardApi = 'http://staging.ecomexpress.in/apiv2/manifest_awb/'consignee = ''else:username = 'ecomexpress'password = 'Ke$3c@4oT5m6h#$'wayBillApi = 'http://staging.ecomexpress.in/apiv2/fetch_awb/'forwardApi = 'http://staging.ecomexpress.in/apiv2/manifest_awb/'consignee = 'TEST'F_AWB_NUMBER = "AWB_NUMBER"F_ORDER_NUMBER = "ORDER_NUMBER"F_PRODUCT = "PRODUCT"F_CONSIGNEE = "CONSIGNEE"F_CONSIGNEE_ADDRESS1 = "CONSIGNEE_ADDRESS1"F_CONSIGNEE_ADDRESS2 = "CONSIGNEE_ADDRESS2"F_DESTINATION_CITY = "DESTINATION_CITY"F_PINCODE = "PINCODE"F_STATE = "STATE"F_MOBILE = "MOBILE"F_ITEM_DESCRIPTION = "ITEM_DESCRIPTION"F_PIECES = "PIECES"F_COLLECTABLE_VALUE = "COLLECTABLE_VALUE"F_DECLARED_VALUE = "DECLARED_VALUE"F_ACTUAL_WEIGHT = "ACTUAL_WEIGHT"F_VOLUMETRIC_WEIGHT = "VOLUMETRIC_WEIGHT"F_LENGTH = "LENGTH"F_BREADTH = "BREADTH"F_HEIGHT = "HEIGHT"F_PICKUP_NAME = "PICKUP_NAME"F_PICKUP_ADDRESS_LINE1 = "PICKUP_ADDRESS_LINE1"F_PICKUP_ADDRESS_LINE2 = "PICKUP_ADDRESS_LINE2"F_PICKUP_PINCODE = "PICKUP_PINCODE"F_PICKUP_PHONE = "PICKUP_PHONE"F_PICKUP_MOBILE = "PICKUP_MOBILE"F_RETURN_NAME = "RETURN_NAME"F_RETURN_ADDRESS_LINE1 = "RETURN_ADDRESS_LINE1"F_RETURN_ADDRESS_LINE2 = "RETURN_ADDRESS_LINE2"F_RETURN_PINCODE = "RETURN_PINCODE"F_RETURN_PHONE = "RETURN_PHONE"F_RETURN_MOBILE = "RETURN_MOBILE"F_DG_SHIPMENT = "DG_SHIPMENT"F_INVOICE_NUMBER = "INVOICE_NUMBER"F_INVOICE_DATE = "INVOICE_DATE"F_ITEM_CATEGORY = "ITEM_CATEGORY"F_PACKING_TYPE = "PACKING_TYPE"F_PICKUP_TYPE = "PICKUP_TYPE"F_RETURN_TYPE = "RETURN_TYPE"F_PICKUP_LOCATION_CODE = "PICKUP_LOCATION_CODE"F_SELLER_GSTIN = "SELLER_GSTIN"F_GST_HSN = "GST_HSN"F_GST_ERN = "GST_ERN"F_GST_TAX_NAME = "GST_TAX_NAME"F_GST_TAX_BASE = "GST_TAX_BASE"F_GST_TAX_RATE_CGSTN = "GST_TAX_RATE_CGSTN"F_GST_TAX_RATE_SGSTN = "GST_TAX_RATE_SGSTN"F_GST_TAX_RATE_IGSTN = "GST_TAX_RATE_IGSTN"F_GST_TAX_TOTAL = "GST_TAX_TOTAL"#returns list of awb of specified type#will generate 500 awbs at oncedef generate_awb(deliveryType):if deliveryType == DeliveryType.COD:ecomDeliveryType = "COD"if deliveryType == DeliveryType.PREPAID:ecomDeliveryType = "PPD"values = {'username' : username,'password' : password,'count' : '500','type' : ecomDeliveryType }data = urllib.urlencode(values)req = urllib2.Request(wayBillApi, data)response = urllib2.urlopen(req)the_page = response.read()return json.loads(the_page)['awb']#All orders awbwise#{'awb':[o1, o2, o3]}def forward_request(ordersMap):values = {'username' : username,'password' : password,'json_input' : _forwardMap(ordersMap),}data = urllib.urlencode(values)req = urllib2.Request(wayBillApi, data)response = urllib2.urlopen(req)the_page = response.read()print the_pagedef _forwardMap(ordersMap):shipments = []for orders in ordersMap.itervalues():shipments.append(_createShipment(orders))return shipmentsdef _createShipment(orders):shipment = {}total_payable = 0total_pieces = 0declared_value = 0total_weight = 0order1 = Order()for order1 in orders:total_payable += order1.net_payable_amounttotal_pieces += order1.lineitems[0].quantitydeclared_value += order1.total_amount + order1.shippingCosttotal_weight += order1.total_weightorder = Order()warehouseAddressObj = get_shipper_object(order.warehouse_address_id)shipment[F_AWB_NUMBER] = order.airwaybill_noshipment[F_ORDER_NUMBER] = order.logisticsTransactionIdshipment[F_PRODUCT] = 'COD' if order.cod and total_payable > 0 else 'PPD'shipment[F_CONSIGNEE] = order.customer_nameshipment[F_CONSIGNEE_ADDRESS1] = order.customer_address1shipment[F_CONSIGNEE_ADDRESS2] = order.customer_address2shipment[F_DESTINATION_CITY] = order.customer_cityshipment[F_PICKUP_PINCODE] = order.customer_pincodeshipment[F_STATE] = order.customer_stateshipment[F_MOBILE] = order.customer_mobilenumbershipment[F_ITEM_DESCRIPTION] = ''shipment[F_PIECES] = total_piecesshipment[F_COLLECTABLE_VALUE] = total_payable if order.cod else 0shipment[F_DECLARED_VALUE] = declared_valueshipment[F_ACTUAL_WEIGHT] = total_weight#shipment[F_VOLUMETRIC_WEIGHT]shipment[F_LENGTH] = 10shipment[F_BREADTH] = 10shipment[F_HEIGHT] = 10shipment[F_PICKUP_NAME] = warehouseAddressObj.contact_personshipment[F_PICKUP_ADDRESS_LINE1] = warehouseAddressObj.address#shipment[F_PICKUP_ADDRESS_LINE2] = ''shipment[F_PICKUP_PINCODE] = warehouseAddressObj.pinshipment[F_PICKUP_MOBILE] = warehouseAddressObj.contact_numbershipment[F_PICKUP_PHONE] = warehouseAddressObj.contact_numbershipment[F_RETURN_NAME] = warehouseAddressObj.contact_personshipment[F_RETURN_ADDRESS_LINE1] = warehouseAddressObj.address#shipment[F_RETURN_ADDRESS_LINE2] = ''shipment[F_RETURN_PINCODE] = warehouseAddressObj.pinshipment[F_RETURN_MOBILE] = warehouseAddressObj.contact_numbershipment[F_RETURN_PHONE] = warehouseAddressObj.contact_numbershipment[F_DG_SHIPMENT] = 'false'shipment["ADDITIONAL_INFORMATION"] = {"MULTI_SELLER_INFORMATION": _getMultiSellerInfo(orders)}def _getMultiSellerInfo(orders):passdef main():lc = LogisticsClient().get_client()print lc.getEmptyAWB(48, '731467')if __name__ == '__main__':ordersMap = {}forward_request(ordersMap)def get_shipper_object(address_id):global shipperMapif shipperMap.has_key(address_id):return shipperMap.get(address_id)else:tc = TransactionClient().get_client()info = tc.getBuyerByWarehouse(address_id)if info is None:raise RuntimeError("Buyer address mapping is None")shipperMap[address_id] = inforeturn shipperMap.get(address_id)