Rev 4016 | Blame | Compare with Previous | Last modification | View Log | RSS feed
#!/usr/bin/pythonimport optparseimport timeimport datetimeimport sysfrom elixir import sessionfrom shop2020.clients.LogisticsClient import LogisticsClientif __name__ == '__main__' and __package__ is None:import ossys.path.insert(0, os.getcwd())from shop2020.thriftpy.model.v1.order.ttypes import OrderStatus, TransactionServiceExceptionfrom shop2020.model.v1.order.impl import DataServicefrom shop2020.model.v1.order.impl.DataAccessors import get_order, close_sessiondef change_logistics_provider(order):'''Ship the order through different vendor.'''if order.status not in [OrderStatus.COD_VERIFICATION_PENDING, OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.INVENTORY_LOW, OrderStatus.ACCEPTED]:print "This order has already been processed. Please seek help from engineering."returnraw_provider_id = raw_input("Enter the ID of the provider that you want to ship through: ")try:provider_id = int(raw_provider_id)except ValueError:print("Invalid provider Id")returnif order.logistics_provider_id == provider_id:print("Provider Id entered by you is same as provider assigned to order.")returnlogistics_client = LogisticsClient().get_client()awb_number = logistics_client.getEmptyAWB(provider_id, order.cod)order.logistics_provider_id = provider_idorder.airwaybill_no = awb_numberorder.track_id = awb_numbersession.commit()print("Successfully updated the provider id")def cancel(order):'''Cancel'''print("Your session has been closed")returnACTIONS = {0: cancel,1: change_logistics_provider}def get_py_datetime(time_string):time_format = "%Y-%m-%d %H%M"mytime = time.strptime(time_string, time_format)return datetime.datetime(*mytime[:6])def main():parser = optparse.OptionParser()parser.add_option("-H", "--host", dest="hostname",default="localhost",type="string", help="The HOST where the DB server is running",metavar="HOST")(options, args) = parser.parse_args()if len(args) != 0:parser.error("You've supplied extra arguments. Are you sure you want to run this program?")DataService.initialize(db_hostname=options.hostname, echoOn=False)raw_order_id = raw_input("Enter Order Id which you want to modify:")try:order_id = int(raw_order_id)print("You want to modify: " + str(order_id))except ValueError:print("Invalid Order Id.")returntry:order = get_order(order_id)print("Please check the details of the order below and ensure that it's the same order which you want to modify:")print("Order Id:\t\t" + str(order.id))print("Customer Name:\t\t" + order.customer_name)print("Pincode:\t\t" + order.customer_pincode)print("Amount:\t\t\t" + str(order.total_amount))print("Created On:\t\t" + str(order.created_timestamp))print("Current Status:\t\t" + str(order.status))print("Status Description:\t\t" + order.statusDescription)print("Logistics provider id:\t\t" + str(order.logistics_provider_id))print("Airway bill number:\t\t" + order.airwaybill_no)print("Ordered Items description:")for lineitem in order.lineitems:print("Item Id:" + str(lineitem.item_id) + "\tBrand: " + str(lineitem.brand) + "\tModel: " + str(lineitem.model_number) + "\tColor: " + str(lineitem.color))print("You can perform following operations:")for (key, val) in ACTIONS.iteritems():print("[" + str(key) + "]" + val.__doc__ )raw_action = raw_input("What do you want to do? ")if raw_action is None or raw_action == "":print("Your session has been closed.")returntry:action = int(raw_action)except ValueError:print("Invalid input.")returnif action > max(ACTIONS.keys()):print("Invalid input.")returnACTIONS[action](order)except TransactionServiceException as tsex:print tsex.messagefinally:close_session()if __name__ == '__main__':main()