示例#1
0
def newDelivery():
    formMaker = SelectMakerForm()
    formMaker.maker.choices = [(a.id, a.name) for a in Maker.query.all()]
    formQuantities = ProductQuantityForm()
    products = None
    if formMaker.is_submitted():
        if formMaker.validate_on_submit():

            maker_id = formMaker.maker.data
            if not maker_id:
                flash(gettext("Maker not found."))
                return redirect(url_for("deliveries"))

            products = Product.query.order_by(Product.maker_id, Product.code)\
                .filter_by(maker_id=int(maker_id),
                           active_flg=True).all()
            for p in products:
                formQuantities.fields.append_entry()
                urls = getImgUrls(p.id)
                if urls:
                    p.img_url = urls[0]

    return render_template('deliveries/newDelivery.html',
                           title=gettext("New Delivery"),
                           formMaker=formMaker,
                           formQuantities=formQuantities,
                           products=products)
示例#2
0
def createOrder():
    formMaker = SelectMakerForm()
    formMaker.maker.choices = [(a.id, a.name) for a in Maker.query.all()]
    formQuantities = ProductQuantityForm()
    products = None

    order_items_ids = request.args.get('order_items_ids')
    maker_to_order = request.args.get('maker_to_order')
    # redirected from order management screen
    if order_items_ids and maker_to_order:
        products = Product.query.order_by(Product.code)\
            .filter_by(maker_id=int(maker_to_order),
                       active_flg=True).all()
        for p in products:
            qty_to_order = 0
            ids = order_items_ids.split(',')
            if str(p.id) in ids:
                qty_to_order = p.min_stock_limit - p.net_stock
            entry = formQuantities.fields.append_entry({'qty_order': qty_to_order})

    elif formMaker.is_submitted():
        if formMaker.validate_on_submit():

            maker_id = formMaker.maker.data
            if not maker_id:
                flash(gettext("Maker not found."))
                return redirect(url_for("orders"))

            products = Product.query.order_by(Product.code)\
                .filter_by(maker_id=int(maker_id),
                           active_flg=True).all()
            for p in products:
                formQuantities.fields.append_entry()

    return render_template('orders/createOrder.html',
                           title=gettext("Place new order to maker"),
                           formMaker=formMaker,
                           formQuantities=formQuantities,
                           products=products)