Exemplo n.º 1
0
def add_warehouse_post():
    form = AddWarehouseForm()
    state = form.state.data
    max_warehouse = current_user.seller_id[0].max_warehouse
    if max_warehouse <= 1:
        if state != 0:
            flash('您只允许开通“正常仓”。请重新选择。')
            return redirect(url_for('.add_warehouse'))
    if max_warehouse <= 2:
        if state == 2:
            flash('您只允许开通“正常仓”和“库存仓”。请重新选择。')
            return redirect(url_for('.add_warehouse'))
    if Warehouse.query.filter_by(
            seller=current_user.seller_id[0]).count() >= max_warehouse:
        flash('您账号最大允许添加:%s个仓库,目前已经有了这么多个不能再添加了。' % str(max_warehouse))
        return redirect(url_for('.add_warehouse'))

    if form.validate_on_submit():
        Warehouse.create(
            name=form.name.data,
            nickname=form.nickname.data,
            seller=current_user.seller_id[0],
            state=state,
        )
        flash('添加成功', 'success')
        return redirect(url_for('.location_management'))
    else:
        flash('添加失败', 'danger')
        flash_errors(form)
    return redirect(url_for('.location_management'))
Exemplo n.º 2
0
def create_store_post():
    form = CreateStoreForm()
    if form.validate_on_submit():
        Seller.create(
            users=current_user,
            name=form.name.data,
            address=form.address.data,
            note=form.note.data,
            contact=form.contact.data,
        )
        flash('创建成功,等待管理员审核', 'success')
        return redirect(url_for('.home'))
    else:
        flash_errors(form)
    return dict(form=form)
Exemplo n.º 3
0
def add_stock():
    form = StockForm()
    if not form.validate_on_submit():
        flash('添加失败', 'danger')
        flash_errors(form)
        return redirect(url_for('.stock'))

    choice_str = 'ABCDEFGHJKLNMPQRSTUVWSXYZ'
    str_time = time.time()
    number_str = 'S'
    number_str += str(int(int(str_time) * 1.301))
    for i in range(2):
        number_str += random.choice(choice_str)

    receipt = Receipt()
    receipt.supplier = form.supplier.data
    receipt.seller = current_user.seller_id[0]
    if form.buy_time.data:
        receipt.buy_time = form.buy_time.data
    if form.send_time.data:
        receipt.send_time = form.send_time.data

    receipt.freight = form.freight.data
    receipt.discount = form.discount.data
    receipt.pay_price = form.pay_price.data

    if form.pay_time.data:
        receipt.pay_time = form.pay_time.data

    receipt.pay_type = form.pay_type.data
    receipt.note = form.note.data
    receipt.number = number_str
    receipt.users = current_user
    receipt.order_state = 0

    receipt.variety = 0
    receipt.goods_sum = 0
    receipt.price_sum = 0

    db.session.add(receipt)
    try:
        db.session.commit()
        return redirect(url_for('.show_receipt', id=receipt.id))
    except Exception as e:
        db.session.rollback()
        flash('添加失败。数据错误.')
        return redirect(url_for('.stock'))
Exemplo n.º 4
0
def add_user_address_post():
    form = AddUserAddressForm()
    if form.validate_on_submit():
        user_address = UserAddress()
        user_address.name = form.name.data
        user_address.phone = form.phone.data
        user_address.address = form.address.data
        user_address.users = current_user
        if not UserAddress.query.filter_by(users=current_user).first():
            user_address.state = 0
        db.session.add(user_address)
        db.session.commit()
        flash('添加成功', 'success')
    else:
        flash('添加失败', 'danger')
        flash_errors(form)

    return redirect(url_for('public.submit_order'))
Exemplo n.º 5
0
def add_category_post():
	form=AddCategoryForm(request.form)
	if form.validate_on_submit():
		if form.pid.data==-1:
			form.pid.data=None
			
		Category.create(
			name=form.name.data,
			ico=form.ico.data,
			sort=form.sort.data,
			parent_id=form.pid.data,
			active=True,			
		)
		flash('添加成功','success')
		return redirect(url_for('.add_category'))
	else:
		flash('添加失败','danger')
		flash_errors(form)
	return redirect(url_for('.add_category'))
Exemplo n.º 6
0
def add_location_post():
    form = AddLocationForm()
    max_goods_location = current_user.seller_id[0].max_goods_location
    goodsed_allocation_count = GoodsAllocation.query \
     .filter_by(users=current_user) \
     .count()

    if goodsed_allocation_count >= max_goods_location:
        flash('您账号最大允许添加:%s个货位,目前已经有了这么多个不能再添加了。' % str(max_goods_location))
        return redirect(url_for('.add_location'))

    if form.validate_on_submit():
        GoodsAllocation.create(name=form.name.data,
                               sort=form.sort.data,
                               note=form.note.data,
                               warehouse_id=form.warehouse.data,
                               users=current_user)
        flash('添加成功', 'success')
        return redirect(url_for('.add_location'))
    else:
        flash('添加失败', 'danger')
        flash_errors(form)
    return redirect(url_for('.add_location'))
Exemplo n.º 7
0
def stock_post():
    form = StockForm()
    if not form.validate_on_submit():
        flash('添加失败', 'danger')
        flash_errors(form)
        return redirect(url_for('.stock'))

    f = request.files['excel']
    filename = secure_filename(f.filename)
    if not filename:
        flash('添加失败文件名错误或未选择文件', 'danger')
        return redirect(url_for('.stock'))
    if not allowed_file(f.filename, 'ALLOWED_EXTENSIONS_EXCEL'):
        flash('文件名或格式错误,请使用英文名称且不要带"."符号。', 'danger')
        return redirect(url_for('.stock'))
    dataetime = dt.datetime.today().strftime('%Y%m%d')
    file_dir = 'store/stock/excel/%s/%s/' % (current_user.id, dataetime)
    if not os.path.isdir(current_app.config['UPLOADED_PATH'] + file_dir):
        os.makedirs(current_app.config['UPLOADED_PATH'] + file_dir)

    f.save(current_app.config['UPLOADED_PATH'] + file_dir + filename)

    data = xlrd.open_workbook(current_app.config['UPLOADED_PATH'] + file_dir +
                              filename,
                              encoding_override='utf-8')

    table = data.sheets()[0]
    message = ''
    try:
        if table.col(0)[0].value.strip() != '商品编号':
            message = u"第一行名称必须叫‘商品编号’,请返回修改"
        if table.col(1)[0].value.strip() != '货位编号':
            message = u"第二行名称必须叫‘货位编号’,请返回修改"
        if table.col(2)[0].value.strip() != '数量':
            message = u"第三行名称必须叫‘数量’,请返回修改"
        if table.col(3)[0].value.strip() != '备注':
            message = u"第四行名称必须叫‘备注’,请返回修改"

        if message != "":
            flash(message)
            return redirect(url_for('.stock'))
    except Exception as e:
        flash('excel文件操作错误:%s' % str(e))
        return redirect(url_for('.stock'))

    nrows = table.nrows  #行数

    #这里得到表单的数据  商品id 货位id
    data_list = [
        table.row_values(i) for i in range(1, nrows) if table.row_values(i)
    ]

    #获得库存中的商品
    inventory = Inventory.query.filter_by(users=current_user).all()
    inventory_dic = defaultdict(list)
    for i in inventory:
        inventory_dic[str(i.goods_id) + '_' +
                      str(i.goods_allocation_id)].append(i)

    #获取用户货位
    goodsed_allocation = GoodsAllocation.query.filter_by(
        users=current_user).all()
    goodsed_allocation_dic = defaultdict(list)
    for i in goodsed_allocation:
        goodsed_allocation_dic[str(i.id)].append(i)

    #用户的商品信息
    goodsed = Goods.query.filter_by(seller=current_user.seller_id[0]).all()
    goodsed_dic = defaultdict(list)
    for i in goodsed:
        goodsed_dic[str(i.id)].append(i)

    choice_str = 'ABCDEFGHJKLNMPQRSTUVWSXYZ'
    str_time = time.time()
    number_str = 'S'
    number_str += str(int(int(str_time) * 1.301))
    for i in range(2):
        number_str += random.choice(choice_str)

    receipt = Receipt()
    receipt.supplier = form.supplier.data
    receipt.seller = current_user.seller_id[0]
    if form.buy_time.data:
        receipt.buy_time = form.buy_time.data
    if form.send_time.data:
        receipt.send_time = form.send_time.data

    receipt.freight = form.freight.data
    receipt.discount = form.discount.data
    receipt.pay_price = form.pay_price.data

    if form.pay_time.data:
        receipt.pay_time = form.pay_time.data

    receipt.pay_type = form.pay_type.data
    receipt.note = form.note.data
    receipt.number = number_str
    receipt.users = current_user
    receipt.order_state = 1
    """
		1.检查货位,如果不是该用户货位退出
		2.检查商品,如果不是该用户货位退出
		3.检查是否同库位,同商品,如同则更新,否则添加。

	"""

    #检查商品和货位重复的列
    data_list_dic = {}
    for i in data_list:
        goods_id = str(int(i[0]))
        goods_allocation_id = str(int(i[1]))
        if data_list_dic.has_key(goods_id + '_' + goods_allocation_id):
            count = data_list_dic[goods_id + '_' + goods_allocation_id][2]
            data_list_dic[goods_id + '_' + goods_allocation_id] = [
                i[0], i[1], i[2] + count, i[3]
            ]
        else:
            data_list_dic[goods_id + '_' + goods_allocation_id] = i
    ast_data_list = []
    for x, y in data_list_dic.iteritems():
        ast_data_list.append(y)

    variety = 0
    goods_sum = 0
    price_sum = 0

    #表格数据
    for i in ast_data_list:

        #商品总类
        variety += 1
        #商品总数
        goods_sum += int(i[2])

        success_goodsed = ''
        success_alllocation = ''

        #商品数据
        if goodsed_dic.has_key(str(int(i[0]))):
            success_goodsed = goodsed_dic[str(int(i[0]))][0]

        #商品总价
        price_sum += success_goodsed.special_price * int(i[2])

        #货位数据
        if goodsed_allocation_dic.has_key(str(int(i[1]))):
            success_alllocation = goodsed_allocation_dic[str(int(i[1]))][0]

        #
        if not success_goodsed:
            flash('商品编号%d校验失败' % i[0])
            abort(401)
        else:
            flash('商品%s校验ok' % (success_goodsed.id))
        #
        if not success_alllocation:
            flash('货位编号%d校验失败' % i[1])
            abort(401)
        else:
            flash('货位%s校验ok' % (success_alllocation.id))

        inventory_dic_has_key = inventory_dic.has_key(
            str(success_goodsed.id) + '_' + str(success_alllocation.id))

        save_stock = Stock()
        save_stock.users = current_user
        save_stock.goodsed = success_goodsed
        save_stock.goods_allocation = success_alllocation
        save_stock.receipts = receipt
        save_stock.stock_count = int(i[2])

        if inventory_dic_has_key:

            count = inventory_dic[str(success_goodsed.id) + '_' + str(
                success_alllocation.id)][0].count + int(i[2])

            save_stock.residue_count = inventory_dic[
                str(success_goodsed.id) + '_' +
                str(success_alllocation.id)][0].count

            inventory_dic[str(success_goodsed.id) + '_' +
                          str(success_alllocation.id)][0].update(count=count)

        else:

            save_stock.residue_count = 0

            db.session.add(
                Inventory(
                    goodsed=success_goodsed,
                    goods_allocation=success_alllocation,
                    count=int(i[2]),
                    note=i[3],
                    users=current_user,
                ))
            # print '添加库存:商品信息{success_goodsed.id},货位{success_alllocation.id}'

        db.session.add(save_stock)

    receipt.variety = variety
    receipt.goods_sum = goods_sum
    receipt.price_sum = price_sum

    db.session.add(receipt)

    try:
        db.session.commit()
        flash('====添加完成=====')
    except Exception as e:
        flash('====添加失败=====')
        db.session.rollback()

    return redirect(url_for('.stock'))
Exemplo n.º 8
0
def commodity_data_post():
    form = CommodityDataForm()

    #如果通过系统商品基础数据的模板读取
    hidden_id = request.form.get('hidden_id')
    if hidden_id:
        base_product = BaseProducts.query.get_or_404(int(hidden_id))
        is_goods = Goods.query.filter_by(
            title=base_product.title,
            seller=current_user.seller_id[0]).first()
        if is_goods:
            flash('该商品已存在,请勿重复添加', 'success')
            return redirect(url_for('.home'))

        Goods.create(
            title=base_product.title,
            original_price=form.original_price.data,
            special_price=form.special_price.data,
            note=base_product.note,
            is_sell=True,
            hot=True,
            ean=base_product.ean,
            unit=base_product.unit,
            seller=current_user.seller_id[0],
            category_id=base_product.category_id,
            main_photo=base_product.main_photo,
        )
        flash('添加成功', 'success')
        return redirect(url_for('.home'))

    if form.validate_on_submit():
        f = request.files['image']

        filename = secure_filename(f.filename)
        if not filename:
            flash(u'请选择图片', 'error')
            return redirect(url_for('.home'))
        if not allowed_file(f.filename):
            flash(u'图文件名或格式错误。', 'error')
            return redirect(url_for('.home'))

        dataetime = dt.datetime.today().strftime('%Y%m%d')
        file_dir = 'store/%s/main_photo/%s/' % (current_user.id, dataetime)
        if not os.path.isdir(os.getcwd() + '/' +
                             current_app.config['UPLOADED_PATH'] + file_dir):
            os.makedirs(os.getcwd() + '/' +
                        current_app.config['UPLOADED_PATH'] + file_dir)
        f.save(current_app.config['UPLOADED_PATH'] + file_dir + filename)

        create_thumbnail(f, 80, file_dir, filename)

        Goods.create(
            title=form.title.data,
            original_price=form.original_price.data,
            special_price=form.special_price.data,
            note=form.note.data,
            is_sell=form.is_sell.data,
            hot=form.hot.data,
            ean=form.ean.data,
            unit=form.unit.data,
            seller=current_user.seller_id[0],
            category_id=form.category.data,
            main_photo=file_dir + filename,
        )
        flash('添加成功', 'success')
        return redirect(url_for('.home'))
    else:

        flash('添加失败', 'danger')
        flash_errors(form)
    return redirect(url_for('.home'))