示例#1
0
def products():
    data = json.loads(request.data)
    product = Product(
        data['name'],
        data['category'],
        data['description'],
        data['price']
    )
    product.save()
    return jsonify(data)
示例#2
0
	def get(self):
		if not self.user:
			self.tv["product"] = Product.query().fetch()
			#logging.critical(self.tv["product"])
			self.render('dashboard.html')

		if self.user:
			self.tv["user"] = True
			self.tv["edit"] = True

			self.tv["product"] = Product.query(Product.owner == self.user.key).fetch()
			#logging.critical(self.tv["product"])
			self.render('dashboard.html')
示例#3
0
def show_product_description(payload, event):
    selected_id = payload.split('|')[1]
    print("__________PROCUT_ID: ", selected_id)

    category_id = str(Product.get_category_id(selected_id))

    navigation = [
        QuickReply("explore categories", payload="SHOW_CATEGORIES"),
        QuickReply("check cart", payload="CHECK_CART"),
    ]

    page.send(event.sender_id, Product.get_description(selected_id))
    page.send(event.sender_id,
              "Continue navigatation",
              quick_replies=navigation)
示例#4
0
 def make_sale():
     """
     Make a sale of product to customer.
     """
     Customer.print_all()
     customer_id = input("\nCustomer id:\n")
     Product.print_all()
     product_id = input("\nProduct id:\n")
     quantity = input("\nQuantity\n")
     try:
         customer = Customer.get_by_id(customer_id)
         check = customer.purchase(product_id, quantity)
         bcolors.print_success(check)
     except ValueError as e:
         bcolors.print_fail(str(e))
示例#5
0
 def test_product_creation(self):
     """
     Test product creation.
     """
     product = Product('Table', 50, 100, 15)
     assert product.cost == 50
     assert product.price == 100
     assert product.weight == 15
示例#6
0
def add_product():
    if request.method == 'POST':
        category_obj_db = Category.objects.get(name_category=request.form.get('category'))
        product_dict = {
            'name_product': request.form.get('name_product'),
            'quantity': request.form.get('quantity'),
            'price': request.form.get('price'),
            'product_for_sale': request.form.get('bool'),
            'category': category_obj_db
        }
        product_obj = Product(**product_dict)
        product_obj.save()
        category_obj_db = Category.objects
        return render_template("add_product.html", data=category_obj_db)
    if request.method == 'GET':
        category_obj_db = Category.objects
        return render_template('add_product.html', data=category_obj_db)
示例#7
0
def products():
    """
        This is api endpoint for getting all products information in JSON on GET
        request and creating new proudct on post request
    """
    from models.products import Product

    if request.method == "GET":
        products = Product.get_all()
        return json.dumps(products)
    if request.method == "POST":
        model_name = request.form.get("model-name")
        manufacturer = request.form.get("manufacturer")
        price = request.form.get("price")
        image_file = request.files["image"]
        product = Product(model_name, manufacturer, price, image_file)
        product.save()
        return Response("Created Successfully")
示例#8
0
 def test_product_creation_exception_str(self):
     """
     Test product creation with string passed to decimal field.
     """
     try:
         product = Product('Table', 'one', 100, 15)
         self.assertFail()
     except Exception as inst:
         self.assertEqual(str(inst), 'Cost value should be decimal.')
示例#9
0
 def test_product_creation_exception(self):
     """
     Test product creation raises exception when price passed to constructor 
     is less then product cost.
     """
     try:
         product = Product('Table', 105, 100, 15)
         self.assertFail()
     except Exception as inst:
         self.assertEqual(str(inst), 'Price cannot be below cost.')
示例#10
0
 def test_check_creation(self):
     """
     Test check creation.
     """
     customer = Customer('Lili', 10, 'EUR')
     product = Product('Chocolate', 50, 100, 15)
     buy = Buy(customer, product.id, 1)
     check = Check.print_check(buy.id, customer.currency)
     self.assertEqual(
         check,
         """1 Chocolate purchased for 3.00EUR\nDiscount amount: 0.33EUR""")
 def test_add_product(self):
     product = Product("test", "product test", "12311231256", 10)
     self.product_service.add(product)
     conn = sqlite3.connect("inventory")
     cursor = conn.execute("SELECT * FROM product WHERE name = ?",
                           [product.name])
     db_object = cursor.fetchone()
     conn.close()
     self.assertEqual(db_object[1], product.name)
     self.assertEqual(db_object[2], product.description)
     self.assertEqual(db_object[3], product.bar_code)
     self.assertEqual(db_object[4], product.qtd)
示例#12
0
	def post(self,instance):
		instance = Product.get_by_id(long(instance))
		prodname = self.request.get("prod_name")
		description = self.request.get("description")
		price = self.request.get("price")
		qty = self.request.get("quantity")

		instance.prod_name = prodname
		instance.description = description
		instance.price = float(price)
		instance.quantity=int(qty)
		instance.put()
		self.redirect('/')
 def list(self):
     connection = self.get_connection()
     cur = connection.execute("SELECT * FROM product")
     result = cur.fetchall()
     products = []
     for product in result:
         products.append(
             Product(_id=product[0],
                     name=product[1],
                     description=product[2],
                     bar_code=product[3],
                     qtd=product[4]))
     return products
示例#14
0
 def add_product():
     """
     Add new product.
     """
     name = input("\nProduct name:\n")
     cost = input("\nProduct cost:\n")
     price = input("\nProduct price:\n")
     weight = input("\nProduct weight:\n")
     try:
         product = Product(name, cost, price, weight)
         bcolors.print_success(
             '{} was successfully added to product list!'.format(
                 product.name))
     except ValueError as e:
         bcolors.print_fail(str(e))
示例#15
0
	def post(self):
		prodname = self.request.get("prod_name")
		description = self.request.get("description")
		price = self.request.get("price")
		qty = self.request.get("quantity")
		prod = Product()

		try:
			prod.prod_name = prodname
			prod.description = description
			prod.price =float(price)
			prod.quantity = int(qty)
			prod.owner = self.user.key
			prod.owner_name = self.user.email
			prod.put()
			self.message = "Successfully save"
			self.redirect('/create/prod')
		except:
			self.error = "Check Input"
			self.redirect('/create/prod?error='+self.error)
			return
示例#16
0
 def test_buy_creation(self):
     """
     Test buy creation.
     """
     customer = Customer('Nancy', 20, 'EUR')
     product = Product('Chocolate', 50, 100, 15)
     buy = Buy(customer, product.id, 2)
     assert buy.total_weight == 30
     assert buy.total_amount == 160
     assert buy.discount_amount == 40
     self.assertEqual(
         buy.total_amount_in_currency,
         decimal.Decimal(5.33).quantize(decimal.Decimal('.01'),
                                        rounding=decimal.ROUND_DOWN))
     assert Buy.get_by_id(buy.id).customer.id == customer.id
     assert Buy.get_by_id(buy.id).product_id == product.id
示例#17
0
	def get(self,instance):
		self.tv["prod"]=Product.get_by_id(long(instance))
		instance = Product.get_by_id(long(instance))
		self.tv["instance"]=instance
		self.render("updateprod.html")
 def get(self):
     return Product(many=True).dump(P_model.objects()), 200
示例#19
0
def products(id):
    products_obj_db = Product.objects(category=id)
    return render_template("products.html", data=products_obj_db)
示例#20
0
 def __init__(self):
     self.__inventory = {
         '0': Product('0', 'Powerthirst Shocklate', 1.00, 10),
         '1': Product('1', 'Brawndo', 1.50, 10, 'The thirst mutilator'),
         '2': Product('1', 'Soylent Green', 0.50, 100, 'Totally not people')
     }
示例#21
0
from models.products import Product, Category

category_obj = Category('vegetables')
category_obj_db = Category.objects.get(name_category='vegetables')
print(category_obj_db)

product_dict = {
    'name_product': 'tomato',
    'quantity': 200,
    'price': 15.50,
    'product_for_sale': True,
    'category': category_obj_db
}

#category_obj.save()

product_obj = Product(**product_dict)
product_obj.save()
 def test_list_products(self):
     product = Product("test", "product test", "12311231256", 10)
     self.product_service.add(product)
     result = self.product_service.list()
     self.assertEqual(1, len(result))
示例#23
0
 def product_list():
     """
     List all entered products.
     """
     Product.print_all()
示例#24
0
	def get(self,instance):
		items = Product.get_by_id(long(instance))
		items.key.delete()
		self.redirect('/')
示例#25
0
	def get(self):
		self.tv["user"] = True
		self.tv["edit"] = False
		self.tv["product"] = Product.query().fetch()
		logging.critical(self.tv["product"])
		self.render('dashboard.html')
示例#26
0
 def test_product_get_by_id(self):
     """
     Test Product method get_by_id.
     """
     product = Product('Book', 10, 15, 2)
     assert Product.get_by_id(product.id).name == 'Book'
示例#27
0
from models.user import User
from models.store import Store
from models.products import Product
from models.category import Category, CategoriesProducts

if CategoriesProducts.table_exists:
    CategoriesProducts.drop_table()

if Category.table_exists():
    Category.drop_table()

if Product.table_exists():
    Product.drop_table()

if Store.table_exists():
    Store.drop_table()

if User.table_exists():
    User.drop_table()

User.create_table()
Store.create_table()
Product.create_table()
Category.create_table()
CategoriesProducts.create_table()

# Insert data

# 1
user1 = User()
user1.username = '******'
示例#28
0
from models.products import Product
from models.store import Store
from models.user import User
from models.category import *

query = (Product.select().join(Store).join(User).where(User.id == 4).order_by(
    Product.price.desc()))

for p in query:
    print(p)

print('\n', '*' * 10, ' Categories ', '*' * 10)
categories = Category.select()
for c in categories:
    print('\t *', c)
    for product in c.products:
        print('\t\t *', product)