Beispiel #1
0
	def post(self):
		sku = self.request.get('sku')
		name = self.request.get('name')
		unit_price = self.request.get('unit_price')
		bulk_quantity = self.request.get('bulk_quantity')
		bulk_price = self.request.get('bulk_price')
		description = self.request.get('description')
		currency = self.request.get('currency')

		if len(currency) == 0:
			currency = '$'

		p = ProductEntity(
					sku = sku, 
					name = name,
					unit_price = unit_price,
					bulk_quantity = bulk_quantity,
					bulk_price = bulk_price,
					description = description,
					currency = currency
				)
		if p.insert([Product]):
			self.render('new_product.html')
			self.write("<br><br>"+p.build_json()+"<br><br>was just added to the datastore")
		else:
			self.write("error")
Beispiel #2
0
	def get(self):
		self.render('delete_product.html')

		sku = self.request.get('sku')
		all_entries = self.request.get('all_entries')
		
		if all_entries.lower() == 'true':
			Product.delete(all_entries=True)
			self.write("Items deleted")
		else:
			if sku:
				details = Terminal().get_product_details(sku)
				if details:
					p = ProductEntity().load_json(details)
					p.delete([Product])
				else:
					self.write('Item not found')
Beispiel #3
0
	def calculate_price(self, sku, count):
		try:
			entity = self.get_product_details(sku)
			product = ProductEntity().load_json(entity)
			unit_price = float(product.get_unit_price()[1:])
			bulk_count = product.get_bulk_quantity()
			bulk_price = product.get_bulk_price()[1:]
			
			if bulk_count and bulk_price:
				bulk_count = float(bulk_count)
				bulk_price = float(bulk_price)
				diff = 0
				if count >= bulk_count:
					diff = count - bulk_count
					return (diff * unit_price) + bulk_price
				else:
					return count * unit_price
			else:
				return count * unit_price
		except:
			return 0.00
Beispiel #4
0
	def set_price(self, authenticated=False, DBNames=[], sku=None, unit_price=None, bulk_quantity=None, bulk_price=None, currency='$'):
		if authenticated and sku and unit_price:
			try:
				entity = self.get_product_details(sku)
			except:
				return False
			product = ProductEntity().load_json(entity)
			product.set_unit_price(unit_price, currency=currency)
			
			if bulk_price:
				product.set_bulk_price(bulk_price, currency=currency)
			if bulk_quantity:
				product.set_bulk_quantity(bulk_quantity)
			status = product.update(DBNames)
			
			return status
		return False