Пример #1
0
 def update_order_product(order_id, product_id, dimension_id, new_quantity, new_price):
     number_of_items = Dimension.get_dimension(dimension_id).number
     product_price_per_line = number_of_items*new_quantity*new_price
     order_product_up = OrderProduct.get_order_product(order_id, product_id, dimension_id)
     order_product_up.quantity = new_quantity
     order_product_up.price = new_price
     order_product_up.product_price_per_line = product_price_per_line
     db_session.commit()
Пример #2
0
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)
Пример #3
0
 def add_order_product(order_id, product_id, dimension_id, quantity, price=0):
     number_of_items = Dimension.get_dimension(dimension_id).number
     product_price_per_line = int(number_of_items)*int(quantity)*float(price)
     order_product = OrderProduct(order_id, product_id, dimension_id, quantity, price, product_price_per_line)
     db_session.add(order_product)
     db_session.commit()
Пример #4
0
 def addProductStock(product_id, quantity):
     query = Dimension.get_all_dimensions()
     for i in query:
         productStock = ProductStock(product_id, i.id, quantity)
         db_session.add(productStock)
         db_session.commit()
Пример #5
0
from models.product_dao import Product, Dimension
from models.product_stock_dao import ProductStock
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)
def list_dimensions():
    d_list = Dimension.get_all_dimensions()
    return d_list
from models.product_dao import Product, Dimension

Dimension.add_dimension("item")
Dimension.add_dimension("box")
Dimension.add_dimension("package")

Product.add_product('apple', 'sweet apple', 1.5, 1)
Product.add_product('potato', 'ukrainian potato', 5.5, 2)
Product.add_product('apple', 'red apple', 10.0, 3)
Product.add_product('orange', 'tasty orange', 1.2, 1)
Product.add_product('banana', 'yellow banana', 7.0, 2)
Product.add_product('lemon', 'yellow lemon', 11.0, 3)
Product.add_product('tomato', 'red tomato', 2.5, 1)
Product.add_product('mango', 'ugly mango', 1.8, 1)
Product.add_product('apple', 'russian apple', 0.5, 1)
Product.add_product('orange', 'italian orange', 15.0, 3)
Product.add_product('apple', 'sweet apple', 11.3, 3)
Product.add_product('banana', 'brazilian banana', 12.1, 3)
Product.add_product('tomato', 'ukrainian tomato', 5.8, 2)
Product.add_product('mango', 'fresh mango', 7.5, 2)
Product.add_product('lemon', 'indian lemon', 4.4, 2)

# You can check, that all products and dimensions was added. You should comment text above, and uncomment below and run
# this script one more time.

#d = Dimension.get_all_dimensions()
#for i in d:
#    print i
#
#p = Product.get_all_products()
#for i in p:
def delete_dimension(id):
    validate_dimension_id(id)
    Dimension.del_dimension(id)
def update_dimension(id, new_name):
    validate_dimension_id(id)
    validate_name(new_name)
    Dimension.upd_dimension(id, new_name)
def create_dimension(name, id):
    validate_name(name)
    validate_dimension_id(id)
    Dimension.add_dimension(name, id)
def get_dimension_by_id(id):
    validate_dimension_id(id)
    dimension_by_id = Dimension.get_dimension(id)
    return dimension_by_id
def validate_dimension_id(id):
    if id is None:
        raise ValidationException("Dimension is required field")
    if not Dimension.get_dimension(id):
        raise NotFoundException("Unable to find dimension with given id")