def stockList(id): productStock = ProductStock.getStockByProduct(id) productStockList = [] for i in productStock: productStockList.append({'dimension': Dimension.get_dimension(i.dimension_id).name, 'quantity': i.quantity, 'dimension_id': i.dimension_id}) product = ({"name": Product.get_product(id).name, "description": Product.get_product(id).description, "price": str(Product.get_product(id).price)}) return make_response(jsonify(productStock=productStockList, product=product), 200)
def product_search(): name = request.args.get('name') prods = Product.pagerByFilterItem(name) products_arr = [] for i in prods: products_arr.append({'id': i.id, 'name': i.name,'description': i.description}) return make_response(jsonify(products=products_arr), 200)
def products_page(): records_per_page = int(request.args.get('table_size')) page = int(request.args.get('page')) filter_dict = {'name': request.args.get('name'), 'name_options': request.args.get('name_options'), 'description': request.args.get('description'), 'description_options': request.args.get('description_options'), 'price': request.args.get('price'), 'price_options': request.args.get('price_options')} all_rec, count = Product.filter_product_grid(filter_dict, page, records_per_page) products_arr = [] for i in all_rec: products_arr.append({'id': i.id, 'name': i.name, 'price': str(i.price), 'description': i.description, }) return make_response(jsonify(products=products_arr, records_amount=count, records_per_page=records_per_page), 200)
def productsPage(): name = request.args.get('name') start_price = request.args.get('start_price') end_price = request.args.get('end_price') records_per_page = int(request.args.get('table_size')) page = int(request.args.get('page')) sort_by = request.args.get('sort_by') index_sort = request.args.get('index_sort') prods, records_amount = Product.listProducts(name, start_price, end_price, page, sort_by, index_sort, records_per_page) products_arr = [] for i in prods: products_arr.append({'id': i.id, 'name': i.name, 'price': str(i.price), 'description': i.description}) status_list = list_dimensions() status_arr = [] for i in status_list: status_arr.append({'id': i.id, 'name': i.name}) return make_response(jsonify(products=products_arr,status=status_arr, records_amount=records_amount, records_per_page=records_per_page), 200)
def addDimensionStock(dimension_id, quantity): query = Product.get_all_products() for i in query: productStock = ProductStock(i.id, dimension_id, quantity) db_session.add(productStock) db_session.commit()
from models.region_dao import RegionDao from models.role_dao import RoleDao from models.user_dao import UserDao, UserLevel, Security from models.order_dao import Order, OrderProduct, OrderStatus,DeliveryType from models.product_stock_dao import ProductStock from datetime import date # This file can fill you DB store_db # just run this file Dimension.add_dimension("Items", 1) Dimension.add_dimension("Box", 5) Dimension.add_dimension("Package", 10) Product.add_product('apple', 'sweet apple', 1.5) Product.add_product('potato', 'ukrainian potato', 5.5) Product.add_product('apple', 'red apple', 10.0) Product.add_product('orange', 'tasty orange', 1.2) Product.add_product('banana', 'yellow banana', 7.0) Product.add_product('lemon', 'yellow lemon', 11.0) Product.add_product('tomato', 'red tomato', 2.5) Product.add_product('mango', 'ugly mango', 1.8) Product.add_product('apple', 'russian apple', 0.5) Product.add_product('orange', 'italian orange', 15.0) Product.add_product('apple', 'sweet apple', 11.3) Product.add_product('banana', 'brazilian banana', 12.1) Product.add_product('tomato', 'ukrainian tomato', 5.8) Product.add_product('mango', 'fresh mango', 7.5) Product.add_product('lemon', 'indian lemon', 4.4)
def delete_product(id): validate_product_id(id) Product.del_product(id)
def update_product(id, new_name, new_description, new_price): validate_product_id(id) validate_name(new_name) validate_price(new_price) Product.upd_product(id, new_name, new_description, new_price)
def create_product(name, description, price): validate_name(name) validate_price(price) Product.add_product(name, description, price)
def get_product_by_id(id): validate_product_id(id) product_by_id = Product.get_product(id) return product_by_id
def list_products(): p_list = Product.get_all_products() return p_list
def validate_product_id(id): if id is None: raise ValidationException("Product id is required field") if not Product.get_product(id): raise NotFoundException("Unable to find product with given id")