Rev 9805 | Rev 12654 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#!/usr/bin/python# coding: ascii'''This script is used to load item details in the catalog database.It's now mostly used for Accessories since they come in huge numbers.@author: Chandranshu'''from elixir import *from shop2020.thriftpy.model.v1.catalog.ttypes import Itemimport csvimport datetimefrom datetime import timedeltaimport optparseimport xlrdfrom shop2020.clients.CatalogClient import CatalogClientfrom shop2020.clients.InventoryClient import InventoryClientfrom shop2020.thriftpy.model.v1.inventory.ttypes import VendorItemPricingfrom shop2020.utils.Utils import to_java_datefrom shop2020.utils.EmailAttachmentSender import mailif __name__ == '__main__' and __package__ is None:import sysimport ossys.path.insert(0, os.getcwd())def load_item_data(filename):workbook = xlrd.open_workbook(filename)sheet = workbook.sheet_by_index(0)num_rows = sheet.nrowsupdatedOn = to_java_date(datetime.datetime.now())cclient = CatalogClient().get_client()iclient = InventoryClient().get_client()for rownum in range(1, num_rows):print sheet.row_values(rownum)message = ""try:product_group, brand, model_number, model_name, color, mrp, sp, mop, dp, tp, nlc, start_date, preferred_vendor, risky, weight, item_type = sheet.row_values(rownum)[0:16]if isinstance(model_number, float):model_number = str(int(model_number))item = Item()item.productGroup = product_groupitem.brand = branditem.modelNumber = model_numberitem.modelName = model_nameitem.color = coloritem.mrp = round(mrp)item.sellingPrice = round(sp)item.startDate = long(to_java_date(datetime.datetime(1899, 12, 30) + timedelta(days=int(start_date))))item.preferredInsurer = preferred_vendoritem.risky = riskyitem.weight = weightitem.updatedOn = updatedOnitem.type = int(item_type)for c in (1,2,3,4,5):try:item_id = cclient.addItem(item)breakexcept Exception as e:cclient = CatalogClient().get_client()vip = VendorItemPricing()vip.itemId = item_idvip.dealerPrice = round(dp)vip.mop = round(mop)vip.nlc = round(nlc)vip.transferPrice = round(tp)vip.vendorId = preferred_vendorfor c in (1,2,3,4,5):try:iclient.addVendorItemPricing(vip)breakexcept Exception as e:iclient = InventoryClient().get_client()except Exception as e:message = message + "\t" + str(brand) + "\t" + str(model_name) + "\t" + str(model_number) + "\t" + str(e.message) + "\n"mail("build@shop2020.in", "cafe@nes", ["amit.gupta@shop2020.in", "chandan.kumar@shop2020.in"], "Problem while adding items", message, [], [], [])print "Successfully updated the item list information."def main():parser = optparse.OptionParser()parser.add_option("-f", "--file", dest="filename",default="ItemList.xls", type="string",help="Read the item list from FILE",metavar="FILE")(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?")filename = options.filenameload_item_data(filename)if __name__ == '__main__':main()