def get_excel_to_py(self, request, objs): path = MEDIA_ROOT + 'download_xls/' + request.user.username # if not os.path.exists(path): mkdir_p(MEDIA_ROOT + 'download_xls') os.popen('chmod 777 %s' % (MEDIA_ROOT + 'download_xls')) mkdir_p(path) os.popen('chmod 777 %s' % (path)) # 写数据 thelist = [] for qs in objs: batsta = None for batbb in getChoices(Choicebatchstatus): if batbb[0] == qs.Status: batsta = batbb[1] break t_set_warehouse_storage_situation_list_objs = t_set_warehouse_storage_situation_list.objects.filter(Delivery_lot_number = qs.Delivery_lot_number) for obj in t_set_warehouse_storage_situation_list_objs: remarks = None t_stocking_demand_list_objs = t_stocking_demand_list.objects.filter(Stocking_plan_number = obj.Stocking_plan_number) if t_stocking_demand_list_objs.exists(): remarks = t_stocking_demand_list_objs[0].Remarks warehouse = '' for ware in getChoices(ChoiceWarehouse): if obj.Destination_warehouse == ware[0]: warehouse = ware[1] level = '' for lev in getChoices(ChoiceLevel): if obj.level == lev[0]: level = lev[1] house = u'浦江集货仓' if ('%s'%obj.Purchase_Order_No).find(u'调拨') != -1 or ('%s'%obj.Purchase_Order_No).find(u'调货') != -1: house = u'浦江仓库' thelist.append([obj.ProductSKU,obj.ShopSKU,obj.The_arrival_of_the_number,qs.Warehouse_number,qs.GoodsCategory,qs.The_first_Logistics_cost, qs.LogisticsNumber,qs.Sender,batsta,obj.Price,house,warehouse,obj.ProductName,level,obj.Demand_people,remarks,obj.AccountNum]) thelist.insert(0,[u'SKU',u'店铺SKU',u'Qty',u'入库单号',u'货物品类',u'头程费用',u' 物流单号',u'发货人',u'本批次发货状态', u'含税单价',u'出库仓',u'入库仓',u'产品名称',u'紧急程度',u'计划需求人',u'备注',u'店铺名(账号)']) filename = request.user.username + '_' + dattime.now().strftime('%Y%m%d%H%M%S') + '.xls' getexcel = generate_excel(thelist,path + '/' + filename) if getexcel['code'] == 0: from brick.public.upload_to_oss import upload_to_oss os.popen(r'chmod 777 %s' % (path + '/' + filename)) upload_to_oss_obj = upload_to_oss(BUCKETNAME_XLS) myresult = upload_to_oss_obj.upload_to_oss({'path':request.user.username,'name':filename,'byte':open(path + '/' + filename),'del':0}) if myresult['errorcode'] == 0: messages.error(request, myresult['result'] + u':成功导出,可点击Download下载到本地............................。') else: messages.error(request, u'导出失败。。。。。')
def generate_fba_price_pdf(self,all_sku_list, upload_path, shopname, timestamp): from brick.public.clear_dir import clear_p from brick.public.create_dir import mkdir_p filePath = '/data/djangostack-1.9.7/apps/django/django_projects/Project/media/Amazon/IN/fba/price/' clear_p(filePath) mkdir_p(filePath) params = {} amzon_india_price_config_obj = amzon_india_price_config(connection) price_config = amzon_india_price_config_obj.getAmazonPriceCofig(ShopName=shopname) if price_config['code'] <> 0: return params['EXCHANGE_RATE'] = float(price_config['data']['EXCHANGE_RATE']) params['PROFIT_RATE'] = float(price_config['data']['PROFIT_RATE']) params['TRACK_PRICE_ELEC'] = float(price_config['data']['TRACK_PRICE_ELEC']) params['TRACK_PRICE_UNELEC'] = float(price_config['data']['TRACK_PRICE_UNELEC']) params['TRACK_DEAL_WEIGHT'] = decimal.Decimal("%.2f" % float(price_config['data']['TRACK_DEAL_WEIGHT'])) params['TRACK_DEAL_PRICE'] = float(price_config['data']['TRACK_DEAL_PRICE']) params['MARKETED'] = price_config['data']['MARKETED'] params['MANUFACTURED'] = price_config['data']['MANUFACTURED'] params['MRP_START'] = price_config['data']['MRP_START'] params['MRP_END'] = price_config['data']['MRP_END'] params['CUSTOMER_PHONE'] = price_config['data']['CUSTOMER_PHONE'] params['END_MESSAGE'] = price_config['data']['END_MESSAGE'] params['TABLE_WIDTH'] = price_config['data']['TABLE_WIDTH'] count = 1 for all_skus in all_sku_list: for sku,sku_values in all_skus.items(): result_sku_info = self.get_price_and_weight_color_by_sku(sku_values, params) result_sku_info['company'] = params['MARKETED'] params['filepath'] = filePath + str(count) + '.pdf' result_sku_info['expiry_date'] = (datetime.datetime.now() + datetime.timedelta(days=-60)).strftime("%d/%m/%Y") self.fba_data_to_pdf(params, result_sku_info) count += 1 new_filePath = filePath[:-1] result_msg = self.zip_ya(new_filePath, new_filePath + '.zip') if result_msg == 1: upload_to_oss_obj = upload_to_oss('fancyqube-download') upload_params = {'path': upload_path, 'name': 'FBA_Price_%s.zip'%timestamp, 'byte': open(new_filePath + '.zip'), 'del': 1} upload_to_oss_obj.upload_to_oss(upload_params) t_download_info.objects.create(appname=upload_path + '/FBA_Price_%s.zip'%timestamp, abbreviation='FBA_Price_%s.zip'%timestamp, updatetime=datetime.datetime.now(), Belonger=upload_path.split('/')[-1], Datasource='t_order_amazon_india_fba')
def already_Ship(self, request, objs): from django.db import connection The_lot_number = 'SHIP' + datetime.datetime.now().strftime( '%Y%m%d%H%M%S') + '-' + str(objs[0].id) myplan = [] myproductinfo = [] warehouselist = [] Cargo_infor = [] for obj in objs: if obj.Arrival_status == 'already' and obj.Storage_status == 'already' and obj.Delivery_status == 'notyet': myplan.append(obj.Stocking_plan_number) myproductinfo.append(obj.ProductSKU + '*' + str(obj.The_arrival_of_the_number)) warehouselist.append(obj.Destination_warehouse) productinfo = [ obj.ProductSKU, obj.Stocking_quantity, obj.The_arrival_of_the_number, '', obj.ProductName, '' ] Cargo_infor.append(productinfo) if len(set(warehouselist)) > 1: messages.error(request, u'同一批次必须是同一目的地仓库!!!') elif len(set(warehouselist)) == 1: from brick.public.generate_excel import generate_excel from brick.public.create_dir import mkdir_p from Project.settings import BUCKETNAME_overseas_warehouse_cargo_infor_xls, MEDIA_ROOT import os, oss2 from brick.public.upload_to_oss import upload_to_oss Cargo_infor.insert( 0, ['SKU', u'计划发货数量', u'实际发货数量', u'备注', u'产品名称', u'仓位']) path = MEDIA_ROOT + 'download_xls/' + request.user.username # if not os.path.exists(path): mkdir_p(MEDIA_ROOT + 'download_xls') os.popen('chmod 777 %s' % (MEDIA_ROOT + 'download_xls')) mkdir_p(path) os.popen('chmod 777 %s' % (path)) filename = request.user.username + '_' + datetime.datetime.now( ).strftime('%Y%m%d%H%M%S') + '.xls' exresult = generate_excel(Cargo_infor, path + '/' + filename) if exresult['code'] == 0: os.popen(r'chmod 777 %s' % (path + '/' + filename)) upload_to_oss_obj = upload_to_oss( BUCKETNAME_overseas_warehouse_cargo_infor_xls) uploadresult = upload_to_oss_obj.upload_to_oss({ 'path': request.user.username, 'name': filename, 'byte': open(path + '/' + filename), 'del': 1 }) if uploadresult['result'] != '': objs.update(Delivery_lot_number=The_lot_number, Delivery_status='already', genBatchMan=request.user.first_name, genBatchTime=ddtime.now()) t_shipping_management.objects.create( Stocking_plan_number='|'.join(myplan), Cargo_infor=uploadresult['result'], Delivery_lot_number=The_lot_number, Destination_warehouse=warehouselist[0], OplogTime=ddtime.now(), Status='notyet', All_ProductSKU_Num=';'.join(myproductinfo)) else: messages.error(request, u'导出失败!请稍后 重试。。。') else: messages.error(request, u'导出失败!请稍后 重试。。。%s' % exresult['error'])
def download_excel_by_porductid(list, opname='', warehouse='STANDARD'): myresult = {} try: classlisting_obj = classlisting(connection, redis_coon) t_wish_store_oplogs_obj = t_wish_store_oplogs(connection) username = opname.split('-')[-1] path = MEDIA_ROOT + 'download_xls/' + username mkdir_p(MEDIA_ROOT + 'download_xls') os.popen('chmod 777 %s' % (MEDIA_ROOT + 'download_xls')) mkdir_p(path) os.popen('chmod 777 %s' % (path, )) datalist = [] datalist.append( ['shopname', 'productid', 'sku', 'shopsku', 'Inventory']) num = len(list) for i, elist in enumerate(list): shopname = elist[0] productid = elist[1] parentsku = elist[2] classshopsku_obj = classshopsku(connection, redis_coon, shopname=shopname) shopskulist = classlisting_obj.getJoomShopSKUList(productid) for shopsku in shopskulist: sku = classshopsku_obj.getSKU(shopsku) if warehouse == 'STANDARD': inventory = classshopsku_obj.getQuantity(shopsku) else: q = getattr(classshopsku_obj, 'getWish%sQuantity' % warehouse) inventory = q(shopsku) datalist.append([shopname, productid, sku, shopsku, inventory]) if i < num - 1: uResult = t_wish_store_oplogs_obj.updateStatusP( opname, opname, 'runing', '') assert uResult['errorcode'] == 0, uResult['errortext'] filename = username + '_' + syntime.now().strftime( '%Y%m%d%H%M%S') + '.xls' eResult = generate_excel(datalist, path + '/' + filename) assert eResult['code'] == 0, eResult['error'] os.popen(r'chmod 777 %s' % (path + '/' + filename)) upload_to_oss_obj = upload_to_oss(BUCKETNAME_XLS) upResult = upload_to_oss_obj.upload_to_oss({ 'path': username, 'name': filename, 'byte': open(path + '/' + filename), 'del': 0 }) assert upResult['errorcode'] == 0, upResult['errortext'] filepath = upResult['result'] uResult = t_wish_store_oplogs_obj.updateStatusP( opname, opname, 'over', filepath) assert uResult['errorcode'] == 0, uResult['errortext'] myresult['Code'] = 1 myresult['messages'] = u'文件生成成功! \n 下载链接:%s' % (filepath, ) except Exception, e: myresult['Code'] = -1 myresult['messages'] = '%s:%s:%s' % (opname, Exception, e)
def save_models(self): request = self.request obj = self.new_obj SallingFile_obj = request.FILES.get('SallingFile') DisableFile_obj = request.FILES.get('DisableFile') ShopName = request.POST.get('ShopName') now_time = datetime.datetime.now().strftime('%H_%M_%S') first_name = request.user.first_name if SallingFile_obj: SallingFile_obj.name = first_name + '-' + now_time + '-' + SallingFile_obj.name obj.SallingFile = SallingFile_obj if DisableFile_obj: DisableFile_obj.name = first_name + '-' + now_time + '-' + DisableFile_obj.name obj.DisableFile = DisableFile_obj if ShopName: obj.ShopName = ShopName if not SallingFile_obj and not DisableFile_obj and not obj.SallingFile and not obj.DisableFile: messages.error(request, u'请上传对应Excel文件') return obj.UploadUser = first_name obj.UploadDatetime = datetime.datetime.now() obj.ImportRes = 'Importing File, Please Wait a little later' obj.save() # 导入数据 salling_file = '' disable_file = '' if obj.SallingFile: salling_file = os.path.join(settings.MEDIA_ROOT, obj.SallingFile.name) if obj.DisableFile: disable_file = os.path.join(settings.MEDIA_ROOT, obj.DisableFile.name) # Upload File To OSS upload_oss_obj = upload_to_oss(settings.BUCKETNAME_XLS) salling_params = dict() disable_params = dict() if SallingFile_obj: salling_params['del'] = 0 salling_params[ 'path'] = 'aliexpress_products/%s/salling_file' % ShopName salling_params['name'] = SallingFile_obj.name salling_params['byte'] = open(salling_file) salling_res = upload_oss_obj.upload_to_oss(salling_params) print 'salling_res', salling_res try: os.remove(salling_file) except: pass if DisableFile_obj: disable_params['del'] = 0 disable_params[ 'path'] = 'aliexpress_products/%s/disable_file' % ShopName disable_params['name'] = DisableFile_obj.name disable_params['byte'] = open(disable_file) disable_res = upload_oss_obj.upload_to_oss(disable_params) print 'disable_res', disable_res try: os.remove(disable_file) except: pass uploadfile_id = obj.id import_user = request.user.first_name # TODO delay # aliexpress_import_products_task( aliexpress_import_products_task.delay(salling_file=salling_params, disable_file=disable_params, shopname=obj.ShopName, uploadfile_id=uploadfile_id, import_user=import_user) messages.info(request, u'正在导入商品数据,请稍后...')