Exemplo n.º 1
0
 def put(self, request, format=None):
     file_obj = request.data['file']
     vip_id = Users.objects.filter(appid=request.user.appid, developer=1, is_delete=0).first().vip
     file_check = FileVipCheck.FileVipCheck(file_obj.size, vip_id)
     if file_check == "N":
         return Response(FBMsg.err_data())
     elif file_check == "Y":
         if os.path.exists(os.path.join(settings.BASE_DIR, 'media/upload/' + pathlink)):
             pass
         else:
             os.makedirs(os.path.join(settings.BASE_DIR, 'media/upload/' + pathlink))
         if file_obj.name.endswith('.xlsx'):
             filename = os.path.join(settings.BASE_DIR,
                                     'media/upload/' + pathlink + '/' + request.user.appid + '.xlsx')
         elif file_obj.name.endswith('.xls'):
             filename = os.path.join(settings.BASE_DIR,
                                     'media/upload/' + pathlink + '/' + request.user.appid + '.xls')
         else:
             return Response(FBMsg.err_data())
         with open(filename, 'wb+') as f:
             for chunk in file_obj.chunks():
                 f.write(chunk)
             f.close()
         df = pd.read_excel(filename)
         if ListModel.objects.filter(appid=request.user.appid).exists():
             upload_data = ListModel.objects.filter(appid=request.user.appid)
             for i in range(len(upload_data)):
                 upload_data[i].delete()
         for index, row in df.iterrows():
             if str(row[pathname]) == '':
                 pass
             else:
                 if ListModel.objects.filter(appid=request.user.appid, name=str(row[pathname]),
                                             is_delete=0).exists():
                     pass
                 else:
                     if binsize.models.ListModel.objects.filter(appid=request.user.appid, name=str(row['库位尺寸']),
                                                                is_delete=0).exists():
                         if property.models.ListModel.objects.filter(appid=request.user.appid,
                                                                     name=str(row['库位属性']),
                                                                     is_delete=0).exists():
                             create_name = Users.objects.filter(openid=request.auth, appid=request.user.appid,
                                                                is_delete=0).first().name
                             ListModel.objects.create(appid=request.user.appid, name=str(row[pathname]),
                                                      bin_size=str(row['库位尺寸']),
                                                      bin_property=str(row['库位属性']),
                                                      create_name=create_name, t_code=Md5.md5(str(row[pathname])))
         os.remove(filename)
         ip = request.META.get('HTTP_X_FORWARDED_FOR') if request.META.get(
             'HTTP_X_FORWARDED_FOR') else request.META.get('REMOTE_ADDR')
         ret = FBMsg.wms_ret()
         ret['ip'] = ip
         return Response(ret)
     else:
         return Response(FBMsg.err_data())
Exemplo n.º 2
0
 def put(self, request, format=None):
     file_obj = request.data['file']
     vip_id = Users.objects.filter(appid=request.user.appid, developer=1, is_delete=0).first().vip
     file_check = FileVipCheck.FileVipCheck(file_obj.size, vip_id)
     if file_check == "N":
         return Response(FBMsg.err_data())
     elif file_check == "Y":
         if os.path.exists(os.path.join(settings.BASE_DIR, 'media/upload/' + pathlink)):
             pass
         else:
             os.makedirs(os.path.join(settings.BASE_DIR, 'media/upload/' + pathlink))
         if file_obj.name.endswith('.xlsx'):
             filename = os.path.join(settings.BASE_DIR, 'media/upload/' + pathlink + '/' + request.user.appid + '.xlsx')
         elif file_obj.name.endswith('.xls'):
             filename = os.path.join(settings.BASE_DIR, 'media/upload/' + pathlink + '/' + request.user.appid + '.xls')
         else:
             return Response(FBMsg.err_data())
         with open(filename, 'wb+') as f:
             for chunk in file_obj.chunks():
                 f.write(chunk)
             f.close()
         df = pd.read_excel(filename)
         if ListModel.objects.filter(appid=request.user.appid).exists():
             upload_data = ListModel.objects.filter(appid=request.user.appid)
             for i in range(len(upload_data)):
                 upload_data[i].delete()
         for index, row in df.iterrows():
             if str(row[pathname]) == '':
                 pass
             else:
                 if ListModel.objects.filter(appid=request.user.appid, is_delete=0).count() > 0:
                     ret = FBMsg.wms_warehouse_more()
                     ret['data'] = row
                     return Response(ret)
                 else:
                     ListModel.objects.create(appid=request.user.appid, name=str(row[pathname]), province=str(row['省份']),
                                              city=str(row['城市']), district=str(row['行政区']), address=str(row['详细地址']),
                                              manager=str(row['负责人']), mobile=str(row['联系电话']),
                                              t_code=Md5.md5(str(row[pathname])))
         os.remove(filename)
         ip = request.META.get('HTTP_X_FORWARDED_FOR') if request.META.get(
             'HTTP_X_FORWARDED_FOR') else request.META.get('REMOTE_ADDR')
         ret = FBMsg.wms_ret()
         ret['ip'] = ip
         return Response(ret)
     else:
         return Response(FBMsg.err_data())
Exemplo n.º 3
0
 def put(self, request, format=None):
     file_obj = request.data['file']
     vip_id = Users.objects.filter(appid=request.user.appid, developer=1, is_delete=0).first().vip
     file_check = FileVipCheck.FileVipCheck(file_obj.size, vip_id)
     if file_check == "N":
         return Response(FBMsg.err_data())
     elif file_check == "Y":
         if os.path.exists(os.path.join(settings.BASE_DIR, 'media/upload/' + pathlink)):
             pass
         else:
             os.makedirs(os.path.join(settings.BASE_DIR, 'media/upload/' + pathlink))
         if file_obj.name.endswith('.xlsx'):
             filename = os.path.join(settings.BASE_DIR, 'media/upload/' + pathlink + '/' + request.user.appid + '.xlsx')
         elif file_obj.name.endswith('.xls'):
             filename = os.path.join(settings.BASE_DIR, 'media/upload/' + pathlink + '/' + request.user.appid + '.xls')
         else:
             return Response(FBMsg.err_data())
         with open(filename, 'wb+') as f:
             for chunk in file_obj.chunks():
                 f.write(chunk)
             f.close()
         df = pd.read_excel(filename)
         if ListModel.objects.filter(appid=request.user.appid).exists():
             upload_data = ListModel.objects.filter(appid=request.user.appid)
             for i in range(len(upload_data)):
                 upload_data[i].delete()
         for index, row in df.iterrows():
             if str(row[pathname]) == '':
                 pass
             else:
                 if ListModel.objects.filter(appid=request.user.appid, name=str(row[pathname]), is_delete=0).exists():
                     pass
                 else:
                     create_name = Users.objects.filter(openid=request.auth, appid=request.user.appid,
                                                    is_delete=0).first().name
                     if goodsunit.models.ListModel.objects.filter(appid=request.user.appid, name=str(row['商品单位']),
                                                                  is_delete=0).exists():
                         pass
                     else:
                         goodsunit.models.ListModel.objects.create(appid=request.user.appid, name=str(row['商品单位']),
                                                                   create_name=create_name,
                                                                   t_code=Md5.md5(str(row['商品单位'])))
                     if goodsclass.models.ListModel.objects.filter(appid=request.user.appid, name=str(row['商品类别']),
                                                                  is_delete=0).exists():
                         pass
                     else:
                         goodsclass.models.ListModel.objects.create(appid=request.user.appid, name=str(row['商品类别']),
                                                                   create_name=create_name,
                                                                   t_code=Md5.md5(str(row['商品类别'])))
                     if goodsspecs.models.ListModel.objects.filter(appid=request.user.appid, name=str(row['商品规格']),
                                                                  is_delete=0).exists():
                         pass
                     else:
                         goodsspecs.models.ListModel.objects.create(appid=request.user.appid, name=str(row['商品规格']),
                                                                   create_name=create_name,
                                                                   t_code=Md5.md5(str(row['商品规格'])))
                     if goodsshape.models.ListModel.objects.filter(appid=request.user.appid, name=str(row['商品形状']),
                                                                  is_delete=0).exists():
                         pass
                     else:
                         goodsshape.models.ListModel.objects.create(appid=request.user.appid, name=str(row['商品形状']),
                                                                   create_name=create_name,
                                                                   t_code=Md5.md5(str(row['商品形状'])))
                     if goodscolor.models.ListModel.objects.filter(appid=request.user.appid, name=str(row['商品颜色']),
                                                                  is_delete=0).exists():
                         pass
                     else:
                         goodscolor.models.ListModel.objects.create(appid=request.user.appid, name=str(row['商品颜色']),
                                                                   create_name=create_name,
                                                                   t_code=Md5.md5(str(row['商品颜色'])))
                     if goodsbrand.models.ListModel.objects.filter(appid=request.user.appid, name=str(row['商品品牌']),
                                                                  is_delete=0).exists():
                         pass
                     else:
                         goodsbrand.models.ListModel.objects.create(appid=request.user.appid, name=str(row['商品品牌']),
                                                                   create_name=create_name,
                                                                   t_code=Md5.md5(str(row['商品品牌'])))
                     if goodscity.models.ListModel.objects.filter(appid=request.user.appid, name=str(row['商品产地']),
                                                                  is_delete=0).exists():
                         pass
                     else:
                         goodscity.models.ListModel.objects.create(appid=request.user.appid, name=str(row['商品产地']),
                                                                   create_name=create_name,
                                                                   t_code=Md5.md5(str(row['商品产地'])))
                     if stocklist.models.ListModel.objects.filter(appid=request.user.appid, name=str(row[pathname]),
                                                                  is_delete=0).exists():
                         pass
                     else:
                         stocklist.models.ListModel.objects.create(appid=request.user.appid, name=str(row[pathname]),
                                                                   goods_name=str(row['商品描述']),
                                                                   t_code=Md5.md5(str(row[pathname])))
                     ListModel.objects.create(appid=request.user.appid, name=str(row[pathname]), goods_name=str(row['商品描述']),
                                              goods_unit=str(row['商品单位']), goods_class=str(row['商品类别']),
                                              goods_spacs=str(row['商品规格']), goods_shape=str(row['商品形状']),
                                              goods_color=str(row['商品颜色']), goods_brand=str(row['商品品牌']),
                                              goods_city=str(row['商品产地']), create_name=create_name,
                                              goods_l=round(float(row['商品长(单位: mm)']), 2),
                                              goods_w=round(float(row['商品宽(单位: mm)']), 2),
                                              goods_h=round(float(row['商品高(单位: mm)']), 2),
                                              goods_weight=round(float(row['商品重量(单位: 克)']), 2),
                                              goods_cost=round(float(row['成本价(单位: 元)']), 2),
                                              goods_price1=round(float(row['一销价(单位: 元)']), 2),
                                              goods_price2=round(float(row['二销价(单位: 元)']), 2),
                                              goods_price3=round(float(row['三销价(单位: 元)']), 2),
                                              t_code=Md5.md5(str(row[pathname])))
         os.remove(filename)
         ip = request.META.get('HTTP_X_FORWARDED_FOR') if request.META.get(
             'HTTP_X_FORWARDED_FOR') else request.META.get('REMOTE_ADDR')
         ret = FBMsg.wms_ret()
         ret['ip'] = ip
         return Response(ret)
     else:
         return Response(FBMsg.err_data())
Exemplo n.º 4
0
 def put(self, request, format=None):
     global cyclecount_number
     file_obj = request.data['file']
     vip_id = Users.objects.filter(appid=request.user.appid,
                                   developer=1,
                                   is_delete=0).first().vip
     file_check = FileVipCheck.FileVipCheck(file_obj.size, vip_id)
     if file_check == "N":
         return Response(FBMsg.err_data())
     elif file_check == "Y":
         if os.path.exists(
                 os.path.join(settings.BASE_DIR,
                              'media/upload/' + pathlink)):
             pass
         else:
             os.makedirs(
                 os.path.join(settings.BASE_DIR,
                              'media/upload/' + pathlink))
         if file_obj.name.endswith('.xlsx'):
             filename = os.path.join(
                 settings.BASE_DIR, 'media/upload/' + pathlink + '/' +
                 request.user.appid + '.xlsx')
         elif file_obj.name.endswith('.xls'):
             filename = os.path.join(
                 settings.BASE_DIR, 'media/upload/' + pathlink + '/' +
                 request.user.appid + '.xls')
         else:
             return Response(FBMsg.err_data())
         with open(filename, 'wb+') as f:
             for chunk in file_obj.chunks():
                 f.write(chunk)
             f.close()
         df = pd.read_excel(filename)
         if ListModel.objects.filter(appid=request.user.appid).exists():
             upload_data = ListModel.objects.filter(
                 appid=request.user.appid)
             for i in range(len(upload_data)):
                 upload_data[i].delete()
         for index, row in df.iterrows():
             if str(row[pathname]) == '':
                 pass
             else:
                 if goodslist.models.ListModel.objects.filter(
                         appid=request.user.appid,
                         name=str(row['商品编码']),
                         is_delete=0).exists():
                     pass
                 else:
                     ret = FBMsg.wms_err()
                     ret['data'] = {"商品编码不存在": str(row['商品编码'])}
                     return Response(ret)
                 if binset.models.ListModel.objects.filter(
                         appid=request.user.appid,
                         name=str(row[pathname]),
                         is_delete=0).exists():
                     pass
                 else:
                     ret = FBMsg.wms_err()
                     ret['data'] = {"库位不存在": str(row[pathname])}
                     return Response(ret)
                 if Users.objects.filter(appid=request.user.appid,
                                         name=str(row['盘点用户名']),
                                         is_delete=0).exists():
                     pass
                 else:
                     ret = FBMsg.wms_err()
                     ret['data'] = {"用户不存在": str(row['盘点用户名'])}
                     return Response(ret)
                 if stockbinlist.models.ListModel.objects.filter(
                         appid=request.user.appid,
                         t_code=str(row['数据标识']),
                         is_delete=0).exists():
                     cycle_count_data = stockbinlist.models.ListModel.objects.filter(
                         appid=request.user.appid,
                         t_code=str(row['数据标识']),
                         is_delete=0).first()
                     ListModel.objects.create(
                         appid=request.user.appid,
                         name=str(row[pathname]),
                         goods_code=str(row['商品编码']),
                         goods_name=str(row['商品描述']),
                         cycle_count_balance=0 - cycle_count_data.goods_qty,
                         staff=str(row['盘点用户名']),
                         inbound_time=cycle_count_data.create_time,
                         t_code=Md5.md5(str(row[pathname])))
                 else:
                     ret = FBMsg.wms_err()
                     ret['data'] = {"数据不存在": str(row[pathname])}
                     return Response(ret)
         os.remove(filename)
         ip = request.META.get('HTTP_X_FORWARDED_FOR') if request.META.get(
             'HTTP_X_FORWARDED_FOR') else request.META.get('REMOTE_ADDR')
         ret = FBMsg.wms_ret()
         ret['ip'] = ip
         return Response(ret)
     else:
         return Response(FBMsg.err_data())