コード例 #1
0
ファイル: views.py プロジェクト: jchenpku/Simple-Inventory
def quick():
	sku_input = request.args.get('sku', None)
	form = product_submit()
	a = open('app/sku/sku_'+str(sku_input)+'.data')
	u = json.load(a)
	if request.method == 'POST':
		q = request.form.get('qty', None)
		qty = int(u['PRODUCTS'][0]['STOCK']) - int(q)
		sku = u['PRODUCTS'][0]['SKU']
		name = u['PRODUCTS'][0]['NAME']
		stock = u['PRODUCTS'][0]['STOCK_LOCATION']
		company = u['PRODUCTS'][0]['COMPANY']
		poo = u['PRODUCTS'][0]['PLACE_OF_ORIGIN']
		w = u['PRODUCTS'][0]['WEIGHT']
		product = u['PRODUCTS'][0]['IMAGE']
		data(sku, name, stock, company, poo, w, qty, product, u['PRODUCTS'][0]['STOCK'])
		flash('Saved')
		return render_template('quick.html', form=form, sku=sku, title=' ', display='Saved', display1=sku, extra=' ', sku_default=sku_input, name_default=name, image=product, qty_default=qty)

	elif request.method == 'GET':
		if sku_input in open('app/sku/sku_'+sku_input+'.data').read():
			a = open('app/sku/sku_'+sku_input+'.data')
			u = json.load(a)
								
			try:
				if u['PRODUCTS'][0]['SKU'] == sku_input:
					name = u['PRODUCTS'][0]['NAME']
					product = u['PRODUCTS'][0]['IMAGE']
					stock_qty = u['PRODUCTS'][0]['STOCK']

					return render_template('quick.html', form=form, title='Product Input', display='Quick Edit', display1=sku_input, sku_default=sku_input, name_default=name, image=product, qty_default=stock_qty)

			except u['PRODUCTS'][0]['SKU'] != sku_input:
				return 'NO SKU FOUND'
コード例 #2
0
ファイル: views.py プロジェクト: jchenpku/Simple-Inventory
def submit_form():
	sku_input = request.args.get('sku', None)
	quick = request.args.get('quick', None)
	form = product_submit()
	if request.method == 'POST':
			sku = request.form.get('sku', None)
			name = request.form.get('name', None)
			company = request.form.get('company', None)
			stock_location = request.form.get('stock_location', None)
			place_of_origin = request.form.get('place_of_origin', None)
			weight = request.form.get('weight', None)
			qty = request.form.get('qty', None)
			file = request.files['file']
			if file and allowed_file(file.filename):
				filename = secure_filename(file.filename)
				file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
				data(sku, name, stock_location, company, place_of_origin, weight, qty, filename, qty)

			flash('Saved')
			return render_template('form.html', form=form, sku=sku, title=' ', display='Saved', display1=sku, extra=' ')

		


	elif request.method == 'GET':
		if sku_input is None:
			return render_template('form.html', form=form, title='Product Input', display='New', display1='Product', extra=' ', sku_default=' ', name_default=' ',
				weight_default=' ', company_default=' ', stock_default=' ', place_default=' ', qty_default=' ')
		elif sku_input is not None:
			

			if sku_input in open('app/sku/sku_'+sku_input+'.data').read() and quick is None:

				##DEFINE WH PRODUCTS

				a = open('app/sku/sku_'+sku_input+'.data')
				u = json.load(a)
							
				try:
					if u['PRODUCTS'][0]['SKU'] == sku_input:
						name = u['PRODUCTS'][0]['NAME']
						stock = u['PRODUCTS'][0]['STOCK_LOCATION']
						company = u['PRODUCTS'][0]['COMPANY']
						poo = u['PRODUCTS'][0]['PLACE_OF_ORIGIN']
						w = u['PRODUCTS'][0]['WEIGHT']
						stock_qty = u['PRODUCTS'][0]['STOCK']
						product = u['PRODUCTS'][0]['IMAGE']
						return render_template('form.html', form=form, title='Product Input', display='Edit', display1=sku_input, extra='Please Reselect The Image', sku_default=sku_input, name_default=name,
					weight_default=w, company_default=company, stock_default=stock, place_default=poo, qty_default=stock_qty)
				except u['PRODUCTS'][0]['SKU'] != sku_input:
						return 'NO SKU FOUND'