Exemplo n.º 1
0
    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 to_excel(self, request, queryset):
        try:
            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))

            w = Workbook()
            sheet = w.add_sheet('order')

            FIELDS = [u'订单ID', u'履行天数', u'店铺名称', u'运营人']

            for index, item in enumerate(FIELDS):
                sheet.write(0, index, item)

            # 写数据
            row = 0

            for qs in queryset:
                row = row + 1
                column = 0
                sheet.write(row, column, qs.order_id)  # A 订单ID

                column = column + 1
                sheet.write(row, column, qs.days_to_fulfill)  # B 履行天数

                column = column + 1
                sheet.write(row, column, qs.shopName)  # C 店铺名称

                column = column + 1
                sheet.write(row, column, qs.Operators)  # D 运营人

            filename = request.user.username + '_' + datetime.now().strftime('%Y%m%d%H%M%S') + '.xls'
            w.save(path + '/' + filename)
            os.popen(r'chmod 777 %s' % (path + '/' + filename))

            # 上传oss对象
            auth = oss2.Auth(ACCESS_KEY_ID, ACCESS_KEY_SECRET)
            bucket = oss2.Bucket(auth, ENDPOINT, BUCKETNAME_XLS)
            bucket.create_bucket(oss2.BUCKET_ACL_PUBLIC_READ)
            # 删除现有的
            for object_info in oss2.ObjectIterator(bucket,
                                                   prefix='%s/%s_' % (request.user.username, request.user.username)):
                bucket.delete_object(object_info.key)
            bucket.put_object(u'%s/%s' % (request.user.username, filename), open(path + '/' + filename))

            messages.error(request, u'%s%s.%s/%s/%s' % (PREFIX, BUCKETNAME_XLS, ENDPOINT_OUT, request.user.username,
                                                        filename) + u':成功导出,可点击Download下载到本地............................。')
        except Exception as error:
            messages.error(request, u'{}'.format(error))
 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'])
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
    def to_excel(self, request, queryset):
        from xlwt import *

        path = MEDIA_ROOT + 'download_xls/' + request.user.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))

        w = Workbook()
        sheet = w.add_sheet('sku')

        FIELDS = [
            u'需求提交时间', u'主SKU', u'核价员', u'剪版费用', u'备注', u'正常售价', u'跟单员',
            u'供应链成本', u'供应链克重', u'纸样师', u'纸样样衣完成时间', u'报价完成时间'
        ]

        for index, item in enumerate(FIELDS):
            sheet.write(0, index, item)

        # 写数据
        row = 0

        for qs in queryset:
            row = row + 1
            column = 0
            sheet.write(row, column, u'{}'.format(qs.submittime))  # A 需求提交时间

            column = column + 1
            sheet.write(row, column, u'{}'.format(qs.mainsku))  # B 主SKU

            column = column + 1
            sheet.write(row, column, u'{}'.format(qs.checkman))  # C 核价员

            column = column + 1
            sheet.write(row, column, u'{}'.format(qs.shearplate))  # D 剪版费用

            column = column + 1
            sheet.write(row, column, u'{}'.format(qs.priceremark))  # E 备注

            column = column + 1
            sheet.write(row, column, u'{}'.format(qs.normalprice))  # F 正常售价

            column = column + 1
            sheet.write(row, column, u'{}'.format(qs.merchandiser))  # G 跟单员

            column = column + 1
            sheet.write(row, column, u'{}'.format(qs.aliprice))  # H 供应链成本

            column = column + 1
            sheet.write(row, column, u'{}'.format(qs.aliweight))  # I 供应链克重

            column = column + 1
            sheet.write(row, column, u'{}'.format(qs.patternman))  # J 纸样师

            column = column + 1
            sheet.write(row, column,
                        u'{}'.format(qs.patterntime))  # K 纸样样衣完成时间

            column = column + 1
            sheet.write(row, column, u'{}'.format(qs.checktime))  # L 报价完成时间

        filename = request.user.username + '_' + datetime.now().strftime(
            '%Y%m%d%H%M%S') + '.xls'
        w.save(path + '/' + filename)
        os.popen(r'chmod 777 %s' % (path + '/' + filename))

        # 上传oss对象
        auth = oss2.Auth(ACCESS_KEY_ID, ACCESS_KEY_SECRET)
        bucket = oss2.Bucket(auth, ENDPOINT, BUCKETNAME_XLS)
        bucket.create_bucket(oss2.BUCKET_ACL_PUBLIC_READ)
        # 删除现有的
        for object_info in oss2.ObjectIterator(
                bucket,
                prefix='%s/%s_' %
            (request.user.username, request.user.username)):
            bucket.delete_object(object_info.key)
        bucket.put_object(u'%s/%s' % (request.user.username, filename),
                          open(path + '/' + filename))

        messages.error(
            request, u'%s%s.%s/%s/%s' % (PREFIX, BUCKETNAME_XLS, ENDPOINT_OUT,
                                         request.user.username, filename) +
            u':成功导出,可点击Download下载到本地............................。')
Exemplo n.º 7
0
    def to_export_aliexpress_link(self, request, queryset):
        from xlwt import *

        path = MEDIA_ROOT + 'download_xls/' + request.user.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))

        w = Workbook()

        sheet = w.add_sheet(u'Aliexpress链接统计')
        sheet.write(0, 0, u'账号店铺ALI')
        sheet.write(0, 1, u'账号名称')
        sheet.write(0, 2, u'销售员(中文)')
        sheet.write(0, 3, u'刊登人')
        sheet.write(0, 4, u'统计数量')
        sheet.write(0, 5, u'统计日期')

        row = 0
        for qs in queryset:
            row = row + 1
            column = 0
            sheet.write(row, column, qs.shopName)

            column = column + 1
            sheet.write(row, column, qs.accountName)

            column = column + 1
            sheet.write(row, column, qs.seller_zh)

            column = column + 1
            sheet.write(row, column, qs.submitter)

            column = column + 1
            sheet.write(row, column, qs.link_number)

            column = column + 1
            sheet.write(row, column, qs.gmt_create)
        filename = request.user.username + '_' + datetime.datetime.now(
        ).strftime('%Y%m%d%H%M%S') + '.xls'
        w.save(path + '/' + filename)
        os.popen(r'chmod 777 %s' % (path + '/' + filename))

        #上传oss对象
        auth = oss2.Auth(ACCESS_KEY_ID, ACCESS_KEY_SECRET)
        bucket = oss2.Bucket(auth, ENDPOINT, BUCKETNAME_XLS)
        bucket.create_bucket(oss2.BUCKET_ACL_PUBLIC_READ)
        #删除现有的
        for object_info in oss2.ObjectIterator(
                bucket,
                prefix='%s/%s_' %
            (request.user.username, request.user.username)):
            bucket.delete_object(object_info.key)
        bucket.put_object(u'%s/%s' % (request.user.username, filename),
                          open(path + '/' + filename))

        messages.error(
            request, u'%s%s.%s/%s/%s' % (PREFIX, BUCKETNAME_XLS, ENDPOINT_OUT,
                                         request.user.username, filename) +
            u':成功导出,可点击Download下载到本地............................。')
    def get_excel_to_py(self, request, objs):
        from xlwt import *
        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))

        w = Workbook()
        sheet = w.add_sheet(u'采购计划单')

        sheetlist = [
            u'需求人',
            u'备货计划号',
            u'采购订单',
            u'1688单号',
            u'sku',
            u'商品名称',
            u'图片',
            u'采购数量',
            u'含税单价',
            u'仓库',
            u'供应商',
            u'采购链接',
            u'网页URL2',
            u'包装规格',
            u'预计到货日期',
            u'采购人',
            u'备货计划时间',
            u'采购状态',
            u'账号',
            u'备注',
        ]

        for index, item in enumerate(sheetlist):
            sheet.write(0, index, item)

        # 写数据
        idlist = []
        row = 0
        for qs in objs:

            row = row + 1

            column = 0
            sheet.write(row, column, qs.Demand_people)  # 需求人

            column = column + 1
            sheet.write(row, column, qs.Stocking_plan_number)  # 备货计划号

            column = column + 1
            sheet.write(row, column, qs.Single_number)  # 采购订单/调拨单号

            column = column + 1
            sheet.write(row, column, qs.Ali_number)  # 1688单号

            column = column + 1
            sheet.write(row, column, qs.ProductSKU)  # sku

            column = column + 1
            sheet.write(row, column, qs.ProductName)  # 商品名称

            column = column + 1
            sheet.write(row, column, qs.ProductImage)  # 图片

            column = column + 1
            sheet.write(row, column, qs.QTY)  # 采购数量

            column = column + 1
            sheet.write(row, column, qs.ProductPrice)  # 含税单价

            column = column + 1
            Destination_warehouse = ''
            for warehouse in getChoices(ChoiceWarehouse):
                if warehouse[
                        1] is not None and qs.Destination_warehouse == warehouse[
                            0].strip():
                    Destination_warehouse = warehouse[1].strip()
            sheet.write(row, column, Destination_warehouse)  # 仓库

            column = column + 1
            sheet.write(row, column, qs.Supplier)  # 供应商

            column = column + 1
            sheet.write(row, column, qs.Supplierlink)  # 采购链接

            column = column + 1
            URL2 = ''
            PackName = ''
            py_b_goods_obj = py_b_goods.objects.filter(
                SKU=qs.ProductSKU).values('LinkUrl2', 'PackName')
            if py_b_goods_obj.exists():
                URL2 = py_b_goods_obj[0]['LinkUrl2']
                PackName = py_b_goods_obj[0]['PackName']
            sheet.write(row, column, URL2)  # 网页URL2
            column = column + 1
            sheet.write(row, column, PackName)  # 包装规格

            column = column + 1
            sheet.write(row, column, qs.Arrival_date)  # 预计到货日期

            column = column + 1
            sheet.write(row, column, qs.Buyer)  # 采购人

            column = column + 1
            sheet.write(row, column, '%s' % qs.Stock_plan_date)  # 备货计划时间

            column = column + 1
            sta = u'未采购'
            if qs.Status == 'check':
                sta = u'完成采购'
            elif qs.Status == 'purchasing':
                sta = u'采购中'
            elif qs.Status == 'abnormalpurchase':
                sta = u'采购异常数据'
            elif qs.Status == 'completedeliver':
                sta = u'已发货'
            else:
                sta = u'未采购'
            sheet.write(row, column, sta)  # 采购状态

            column = column + 1
            sheet.write(row, column, qs.AccountNum)  # 账号

            column = column + 1
            sheet.write(row, column, qs.Remarks)  # 备注
            idlist.append(qs.id)
        filename = request.user.username + '_' + ddtime.now().strftime(
            '%Y%m%d%H%M%S') + '.xls'
        w.save(path + '/' + filename)
        os.popen(r'chmod 777 %s' % (path + '/' + filename))

        # 上传oss对象
        auth = oss2.Auth(ACCESS_KEY_ID, ACCESS_KEY_SECRET)
        bucket = oss2.Bucket(auth, ENDPOINT, BUCKETNAME_XLS)
        bucket.create_bucket(oss2.BUCKET_ACL_PUBLIC_READ)
        # 删除现有的
        for object_info in oss2.ObjectIterator(
                bucket,
                prefix='%s/%s_' %
            (request.user.username, request.user.username)):
            bucket.delete_object(object_info.key)
        bucket.put_object(u'%s/%s' % (request.user.username, filename),
                          open(path + '/' + filename))
        objs.filter(id__in=idlist).update(ExcelStatus='yes')
        messages.error(
            request, u'%s%s.%s/%s/%s' % (PREFIX, BUCKETNAME_XLS, ENDPOINT_OUT,
                                         request.user.username, filename) +
            u':成功导出,可点击Download下载到本地............................。')