コード例 #1
0
def orderJson():
    if session:
        data = request.get_json(force=True)
        stock_item = Products.query.filter_by(id=data['product_id']).first()

        if int(data['quantity']) > int(stock_item.quantity):
            flash('Quantity ordered is higher than stock remaining', 'danger')

            return 'We have an error', 400
        else:
            # update the product's stock quantity when an order is made
            stock_item.quantity = int(stock_item.quantity) - int(
                data['quantity'])
            db.session.add(stock_item)
            db.session.commit()

            o = Orders(email=session['email'],
                       quantity=data['quantity'],
                       total=data['total'],
                       product_id=data['product_id'],
                       company=session['companyname'],
                       customer_id=session['uid'])
            o.create_record()

            return 'Order successfully saved', 200
コード例 #2
0
def cust_home():
    allproducts = Products.fetch_all()
    if 'email' in session:
        if request.method == 'POST':
            email = session['email']
            product = request.form['productname']
            company = request.form['name']
            qun = request.form['quantity']
            date = request.form['date']

            # check for the product quantity
            # product_to_check = Products.query.filter_by(name=product).first()

            if qun > 0:
                flash('Quantity ordered is higher than stock remaining',
                      'danger')
                return redirect(url_for('cust_home'))
            else:
                ch = Orders(email=email,
                            product=product,
                            orderdate=date,
                            customer_id=session['uid'],
                            company=company)
                ch.create_record()

                flash('Order successfully made', 'success')
                return redirect(url_for('cust_home'))

        return render_template('customerorder.html', products=allproducts)
    else:
        flash('Please login', 'danger')
        return redirect(url_for('login'))
コード例 #3
0
def orderJson():
    data = request.get_json(force=True)
    o = Orders(email=session['email'],
               quantity=data['quantity'],
               total=data['total'],
               product_id=data['product_id'],
               company=data['company'])  #,customer_id=session['uid']
    o.create_record()
    return 'Order successfully saved'
コード例 #4
0
def customers():
    allproducts = Products.fetch_all()

    if request.method == 'POST':

        email = request.form['email']
        products = request.form['productname']
        date = request.form['date']
        company = request.form['company']

        o = Orders(email=email,
                   product=products,
                   orderdate=date,
                   company=company)
        o.create_record()
        flash('Order successfull made', 'success')
        return redirect(url_for('customers'))

    return render_template('customers.html', products=allproducts)
コード例 #5
0
def cust_home():
    allproducts = Products.fetch_all()
    if 'email' in session:
        if request.method == 'POST':
            email = session['email']
            product = request.form['productname']
            company = request.form['name']

            qun = request.form['quantity']

            date = request.form['date']

            ch = Orders(email=email,
                        product=product,
                        orderdate=date,
                        customer_id=session['uid'],
                        company=company)
            ch.create_record()
            flash('Order successfully made', 'success')
            return redirect(url_for('cust_home'))
        return render_template('customerorder.html', products=allproducts)
    else:
        flash('Please login', 'danger')
        return redirect(url_for('login'))