Example #1
0
def receive(message):
	"""
	Show to user info about all receive
	"""
	user_id = message.from_user.id
	if utils.perm_adm(user_id) == 1:
		db = SQLbase(config.db)
		txt = db.get_receive()
		db.close()
		bot.send_message(message.chat.id, text = txt)
	else:
		bot.send_message(message.chat.id, text = "У Вас нету доступа к этой функции")
Example #2
0
def in_process():
	"""
	Show a message of orders with status process
	"""
	db = SQLbase(config.db)
	list_orders = db.list_orders("process")
	db.close()
	txt = "Товар в производстве:\n"
	if list_orders != []:
		for item in list_orders:
			txt += txt_order(item)
			txt += "\n"
	else:
		txt = "У вас нету ни одного товара в производстве"
	return txt
Example #3
0
def decide_adm(order_id):
	"""
	In_kb with yes or no and text about order 
	"""
	db = SQLbase(config.db)
	list_order = db.info_request(order_id)
	db.close()
	txt_0 = "Вы уверенны что хотите выпустить на производство этот товар:"
	txt_1 = txt_order(list_order)
	txt = "{}\n{}".format(txt_0, txt_1)
	in_kb = types.InlineKeyboardMarkup()
	yes = types.InlineKeyboardButton(text = "Да", callback_data = "adm_yes{}".format(order_id))
	no = types.InlineKeyboardButton(text = "Нет", callback_data = "adm_no")
	in_kb.add(yes, no)
	return in_kb, txt
Example #4
0
def to_process(order_id):
	"""
	Put order in process and return a text
	"""
	db = SQLbase(config.db)
	db.to_process(order_id)
	list_order = db.info_request(order_id)
	db.remains(order_id)
	db.close()
	txt_0 = "Данный товар на производстве:"
	txt_1 = txt_order(list_order)
	txt = "{}\n{}".format(txt_0, txt_1)
	return txt
Example #5
0
def in_kb_shop():
	"""
	Create a in_kb for shop with orders in status 'process' 
	"""
	in_kb = types.InlineKeyboardMarkup()
	db = SQLbase(config.db)
	list_orders = db.list_orders("process")
	db.close()
	txt = "Выберите товар который хотите снять с производства"
	if list_orders != []:
		for item in list_orders:
			txt = txt_order(item)
			order_id = item[0]
			button = types.InlineKeyboardButton(text = txt, callback_data = "shop{}".format(order_id))
			in_kb.add(button)
	else:
		txt = "Нету ни одного товара в производстве"
	return in_kb, txt
Example #6
0
def in_kb_product():
	"""
	Show inline_kb for user to make a order
	"""
	in_kb = types.InlineKeyboardMarkup(row_width = 1)
	#get list of all product from db
	db = SQLbase(config.db)
	data = db.get_product()
	db.close()
	txt = "Выберите один из товаров: "
	for item in data:
		#item[2:] - info about product
		#item[:1] - id of a product
		#first ' ' is a border between id_product and info_product
		index = item.index(' ')
		button = types.InlineKeyboardButton(text = item[(index + 1):], callback_data = str(item[:index]))
		in_kb.add(button)
	button = types.InlineKeyboardButton(text = "Произвольный размер", callback_data = str(7))
	in_kb.add(button)
	return in_kb, txt
Example #7
0
def request_orders():
	"""
	Create in_kb of orders with status "request"
	"""
	db = SQLbase(config.db)
	list_orders = db.list_orders("request")
	db.close()
	logging.info("request_orders \n{}".format(list_orders))
	in_kb = types.InlineKeyboardMarkup()
	if list_orders != []:
		text = "Выберите запрос котроый хотите отправить на производство:"
		for item in list_orders:
			logging.info("Item:\n{}".format(item))
			txt = txt_order(item)
			#item[0] - id of order
			#item[0] multiply on 100 to handle collusions with in_kb_product
			button = types.InlineKeyboardButton(text = txt, callback_data = str(item[0]*100))
			in_kb.add(button)
	else:
		text = "Нет созданных запросов"
	return in_kb, text
Example #8
0
def receive_p_m(message):
	try:
		p_m = float(message.text)
	except:
		p_m = None

	if p_m == None:

		txt = "Вы ввели не правильное число для п.м.! Используйте целое число(Например: 50) или число с точкой (Например: 50.30)"
		bot.send_message(message.chat.id, text = txt)
		return
	else:
		#add_p_m to table Unique_term
		db = SQLbase(config.db)
		db.add_p_m_term_receive(p_m)
		id_material, p_m = db.term_receive_info() 
		db.add_receive(p_m, id_material)
		material = db.info_material(id_material)
		db.close()
		txt = "Вы добавили ткань материала: {}. И размером {} п.м.".format(material, p_m)
		worker_db.set_state(message.chat.id, config.States.START.value)
		bot.send_message(message.chat.id, text = txt)
Example #9
0
def in_kb_materials(id_product, status):
	"""
	Create inline keyboard of all materials
	"""
	in_kb = types.InlineKeyboardMarkup(row_width = 1)
	#get list of all materials from db
	db = SQLbase(config.db)
	materials = db.get_materials()
	db.close()
	if id_product != 7:
		if materials != 0:
			txt = "Выберите тип материала из которого сделать ранее выбранный товар:"
			for item in materials:
				#item[2:] - name material
				#item[:1] - id of a material
				#id_product - picked product by store or abm
				if status == "order":
					encode = "info {} {}".format(id_product, item[:1]) 
					button = types.InlineKeyboardButton(text = item[2:], callback_data = encode)
				elif status == "receive":
					txt = "Выберите тип материала котороый хотите добавить для учёта"
					encode = "receive {}".format(item[:1]) 
					button = types.InlineKeyboardButton(text = item[2:], callback_data = encode)
				in_kb.add(button)
		else:
			txt = "Не созданно не одного метриала. Администратор должен добавить вид материалов."
	else:
		if materials != 0:
			txt = "Выберите тип материала из которого сделать ранее созданный товар:"
			for item in materials:
				#item[2:] - name material
				#item[:1] - id of a material
				encode = "unique {}".format(item[:1]) 
				button = types.InlineKeyboardButton(text = item[2:], callback_data = encode)
				in_kb.add(button)
		else:
			txt = "Не созданно не одного метриала. Администратор должен добавить вид материалов."
	return in_kb, txt
Example #10
0
def add_material(name):
	"""
	add material in Material db
	"""
	db = SQLbase(config.db)
	db.add_material(name)
	db.close()
	txt = "Вы добавили новый материал с названием: {}".format(name)
	logging.info("Added material with name: {}".format(name))
	return txt
Example #11
0
def add_unique_order(id_material):
	"""
	add uniquer order in Order db and create a txt
	"""
	db = SQLbase(config.db)
	name_material = db.info_material(id_material)
	db.add_item_unique('name_material', name_material)
	name_prod, size, p_m = db.add_unique()
	db.close()

	txt_0 = "Вы создали заявку на производство товара со следующими характеристиками:"
	txt_1 = "Наименование товара: {}".format(name_prod)
	txt_2 = "Размер товара: {}".format(size)
	txt_3 = "Величина п/м: {}".format(p_m)
	txt_4 = "Вид материала: {}".format(name_material)
	txt = "{0}\n{1}\n{2}\n{3}\n{4}".format(txt_0, txt_1, txt_2, txt_3, txt_4)

	return txt
Example #12
0
def done_order(id_order):
	"""
	Update status process -> done in Order's db
	"""
	db = SQLbase(config.db)
	db.done_process(id_order)
	info_order = db.info_request(id_order)
	db.close()
	txt_0 = "Вы убрали с произвоства товар №{}: ".format(info_order[0])
	txt_1 = "Наименование товара: {}".format(info_order[1])
	txt_2 = "Вид материала: {}".format(info_order[2])
	txt_3 = "Размер товара: {}".format(info_order[3])
	txt_4 = "Величина п/м: {}".format(info_order[4])
	txt = "{0}\n{1}\n{2}\n{3}\n{4}".format(txt_0, txt_1, txt_2, txt_3, txt_4)
	return txt
Example #13
0
def info_order(id_product, id_material):
	"""
	Create info about an order
	"""
	db = SQLbase(config.db)
	name_prod, size, p_m = db.info_product(id_product)
	name_material = db.info_material(id_material)
	db.add_order(int(id_product), int(id_material))
	db.close()

	
	txt_0 = "Вы создали заявку на производство товара со следующими характеристиками:"
	txt_1 = "Наименование товара: {}".format(name_prod)
	txt_2 = "Вид материала: {}".format(name_material)
	txt_3 = "Размер товара: {}".format(size)
	txt_4 = "Величина п/м: {}".format(p_m)
	txt = "{0}\n{1}\n{2}\n{3}\n{4}".format(txt_0, txt_1, txt_2, txt_3, txt_4)
	
	return txt
Example #14
0
def receive_material(call):
	"""
	show a in_kb of materials
	"""
	id_info = re.findall(r"\d+", call.data)
	id_material = id_info[0]
	db = SQLbase(config.db)
	db.add_material_term_receive(id_material)
	db.close()
	worker_db.set_state(call.from_user.id, config.States.RECEIVE_P_M.value)
	txt_1 = "Теперь напишите погонный метр(п.м.)"
	txt_2 = "Пример: 50.30"
	txt_3 = "Используйте '.'! Не верно: 50,30"
	txt = "{}\n{}\n{}".format(txt_1, txt_2, txt_3)
	bot.edit_message_text(chat_id = call.message.chat.id, message_id = call.message.message_id, text = txt)
Example #15
0
def write_p_m(message):
	"""
	Adm or shop writing a p_m of a unique product
	"""
	try:
		p_m = float(message.text)
	except:
		p_m = None

	if p_m == None:
		txt = "Вы ввели не правильное число для п.м.! Используйте целое число(Например: 4) или число с точкой (Например: 4.30)"
		bot.send_message(message.chat.id, text = txt)
		return
	else:
		#add_p_m to table Unique_term
		db = SQLbase(config.db)
		db.add_item_unique('p_m', p_m)
		db.close()
		worker_db.set_state(message.chat.id, config.States.UNIQUE_MATERIAL.value)
		pick_material(message)
Example #16
0
def check_size(size, index):
	"""
	check string size on valid
	example '280*390'
	"""
	txt_0 = ""
	ziro = "Если Вы хотите отменить создание произвольного размера товара напиште боту '0'"
	example = "Пример правильного размера: 70*100"
	again = "Попробуйте ещё раз!"
	#handle this situation: '280390'
	if index == None:
		txt_0 = "Вы забыли использовать символ '*'.\n"
	#handle this situation: '*390'	
	elif index == 0:
		txt_0 = "Вы указали символ '*' в начале размера.\n"
	#handle this situation: 280*
	elif size[index + 1:] == '':
		txt_0 = "Вы не указали величину размера после символа '*'.\n"
	#handle this situation: 280*390u
	elif size[index + 1:] == False:
		txt_0 = "Вы указали не целое число после символа '*'.\n"
	#handle this situation: 280u*390
	elif size[index + 1:] == False:
		txt_0 = "Вы указали не целое число перед символом '*'.\n"
		
	#somthing went wrong
	if txt_0 != "":
		txt = "{}\n{}\n{}\n{}".format(txt_0, example, ziro, again)
		return 0, txt
	#user write size correctly
	else:
		db = SQLbase(config.db)
		db.add_item_unique('size', size)
		db.close()
		txt_0 = "Указанный Вами размер был сохранён."
		txt_1 = "Теперь напишите погонный метр(п.м.) произвольного товара."
		txt_2 = "Пример: 4.30"
		txt_3 = "Используйте '.'! Не верно: 4,30"
		txt = "{}\n{}\n{}\n{}".format(txt_0, txt_1, txt_2, txt_3)
		return 1, txt