Ejemplo n.º 1
0
def product(barcode):
    # Fetch product goes here
    product = dbproduct.Product(barcode, use_gs1_api=True)
    product.stock = request.args.get('stock', product.stock)
    product_data = product.get_data()
    product_data = render_template('product.inc',
                                   barcode=barcode,
                                   data=product_data,
                                   action='insert')
    if request.args.get('app') is not None:
        return product_data
    else:
        return render_template('template.html',
                               main_data=product_data,
                               title="Product Database")
Ejemplo n.º 2
0
def manage_stock(action):
    try:
        barcode = request.form['barcode']
        quantity = request.form['quantity']
        product = dbproduct.Product(barcode)
        new_stock = 0
    except KeyError:
        return Response('{"status": "Bad Request"}', status=400)

    if action == "add":
        new_stock = int(product.stock) + int(quantity)
    elif action == "remove":
        new_stock = int(product.stock) - int(quantity)
        if new_stock < 0:
            new_stock = 0

    return Response(product.update({'stock': str(new_stock)}))
Ejemplo n.º 3
0
  def stock_query(self, item):
    product = dbproduct.Product()
    res, col = product.search(item)
    if res is None:
      return statement('Sorry, ' + item + ' not found in stock')

    #found_numbers = len(res)
    product.load(res[0])
    
    if product.stock == '0':
      msg = product.brand + ' ' + product.name + ' is running out of stock'
    elif product.stock == '1':
      msg = product.brand + ' ' + product.name + ' has only one quantity left in stock'
    else:
      msg = product.brand + ' ' + product.name + ' has ' + str(product.stock) + ' quantities in stock'
    
    return statement(msg)
Ejemplo n.º 4
0
def manage_product(action):
    method = request.method
    redirect = False

    product = dbproduct.Product(action)

    if request.method == 'GET':
        product_data = product.get_data(is_json=True)
        return Response(product_data)
    elif request.method == 'POST':
        if action == "insert":
            method = 'PUT'
            redirect = True
        elif action == "update":
            method = 'PUT'
            redirect = True
        elif action == "delete":
            method = 'DELETE'
            redirect = True
        else:
            return Response('{"status": "Bad Request"}', status=400)

    if method == "PUT":
        product.brand = request.form['company']
        product.name = request.form['name']
        product.category = request.form['category']
        product.measurement = request.form['measurement']
        product.mrp = request.form['mrp']
        product.stock = request.form['stock']
        if product._is_present:
            return Response(product.update())
        return Response(product.add())
    elif method == "PATCH":
        return '{"status": "OK"}'
    elif method == "DELETE":
        return Response(product.delete())
    else:
        return Response('{"status": "Internal Server Error"1}', status=500)
Ejemplo n.º 5
0
from sinventory import product as dbproduct

product = dbproduct.Product('8906017290026')
product_data = product.get_data()
print(product_data)