def query_inventory_data(): """ Get information of a given product. """ print("--- Query inventory data ---\n") print("Which product is it?") list_products = get_products() # display products to the user for products in list_products: print("- %s (%s)" % ( products['name'], products['id'] )) print() this_product = select_by_id_or_name(list_products, 'product') print("Selected: %s (%s)\n" % (this_product['name'], this_product['id'])) # display info print("Description:", this_product["description"]) print("Id:", this_product["id"]) print("Price per unit:", this_product["price"]) print("Quantity in stock:", this_product["quantity"]) print("Season:", this_product["season"]) print("Categories:", this_product["type"], "-", this_product["sub_type"])
def register_product_arrival(): """ Register when a product has arrived. This will update products.csv """ print("--- Register product arrival ---\n") print("Which product is it?\n") menu = get_products() # display products to the user for thing in menu: print("- %s (%s)" % (thing['name'], thing['id'])) print() chooosen_product = select_by_id_or_name(menu, 'product') print("Selected: %s (%s)\n" % (chooosen_product['name'], chooosen_product['id'])) arrival_quantity = safe_input('int_positive', 'Recent arrival quantity:') print() chooosen_product['quantity'] += arrival_quantity # show feedback to the users print('OKAY. You\'ve registered %s items of %s' % (arrival_quantity, chooosen_product['name'])) print('Now there are %s in stock' % chooosen_product['quantity']) update_products(menu)
def register_sale(): sale = { "date": today() } print("--- Satış kaydı ---\n") print("Urunu kim satıyor?") employees = get_employees() for e in employees: print("- %s (%s)" % (e['name'], e['id'])) print() employee = select_by_id_or_name(employees, 'employee') sale['employee_id'] = employee['id'] print("Selected: %s (%s)\n" % (employee['name'], employee['id'])) print("Bu hangi ürün?") products = get_products() for p in products: print("- (%s) %s (%s adet satilabilir.)" % (p['id'], p['name'], p['quantity'])) print() product = select_by_id_or_name(products, 'product') sale['product_id'] = product['id'] print("Secilen: %s (%s) (%s stokta var)\n" % (product['name'], product['id'], (product['quantity']))) quantity = 0 while True: quantity = safe_input("int_positive", "Kaç urun var? ") if quantity > 0 and quantity <= product['quantity']: print("Emir geçerlidir. Toplam fiyat hesaplanıyor...") break else: print( "Sipariş geçersiz. Lütfen stoktaki miktardan büyük olmayan bir sayı seçin") # we are updating the reference, so this dictionary is also modified # on the products list product['quantity'] -= quantity sale['num_products'] = quantity sale['total_price'] = quantity * product['price'] print("\nToplam fiyat: %sTL (+ %sTL vergi)" % (sale['total_price'], sale['total_price'] * 0.18)) sale['id'] = len(get_sales()) print("\nBu siparişin numarasi", sale['id']) update_products(products) add_sale(sale)
def register_sale(): sale = {"date": today()} print("--- Register sale ---\n") print("Who is selling the product?") employees = get_employees() for e in employees: print("- %s (%s)" % (e['name'], e['id'])) print() employee = select_by_id_or_name(employees, 'employee') sale['employee_id'] = employee['id'] print("Selected: %s (%s)\n" % (employee['name'], employee['id'])) print("Which product is it?") products = get_products() for p in products: print("- %s (%s) (%s in stock)" % (p['name'], p['id'], p['quantity'])) print() product = select_by_id_or_name(products, 'product') sale['product_id'] = product['id'] print("Selected: %s (%s) (%s in stock)\n" % (product['name'], product['id'], (product['quantity']))) quantity = 0 while True: quantity = safe_input("int_positive", "How many items? ") if quantity > 0 and quantity <= product['quantity']: print("The order is valid. Calculating total price...") break else: print( "The order is invalid. Please choose a number that is not greater than the quantity in stock" ) # we are updating the reference, so this dictionary is also modified # on the products list product['quantity'] -= quantity sale['num_products'] = quantity sale['total_price'] = quantity * product['price'] print("\nTotal price: $%s (+ $%s tax)" % (sale['total_price'], sale['total_price'] * 0.16)) sale['id'] = len(get_sales()) print("\nThis order's id is", sale['id']) update_products(products) add_sale(sale)
def print_products_and_subproducts_for_menu(): products_menu = list( chain.from_iterable( [category[PRODUCTOS] for category in categories if category[NOMBRE] == 'Menús'] ) ) products_menu = sorted_array( get_products(products, products_menu), ORDEN, default=NINETYNINE ) print("\nProductos y Subproductos de la categoria Menús") print("------------------------------------------------") print_elements(products_menu)
def most_sold_items(): """ Get the top 3 most sold items- """ print("--- Most sold items ---\n") print("Top 3 most sold product until now:") products = get_products() sales_file = get_sales() products_sold = {} # add initial values for product in products: products_sold[product["id"]] = 0 # update the product quantities for sold_item in sales_file: product_id = sold_item["product_id"] products_sold[product_id] += sold_item["num_products"] top_products = [] # top 3 for _i in range(3): top_product = {"product_id": -1, "products": -1} for k in products_sold: total = products_sold[k] # update the curent top value if total > top_product['products']: top_product = { "product_id": k, "products": total } # add to the podium top_products.append(top_product) # delete from list to calculate other placees del products_sold[top_product['product_id']] place = 0 for el in top_products: place += 1 product = find_by_key(products, 'id', el['product_id']) print(" %s) %s with %s units sold" % ( place, product['name'], el['products'] ))
def most_sold_items(): print("--- En çok satılan ürünler ---") print("Şimdiye kadar en çok satılan 3 ürün:") products = get_products() sales_file = get_sales() products_sold = {} for sold_items in sales_file: products_sold[sold_items["num_products"]] = 0 for product in products: product_id = product["product_id"] products_sold[product_id] += product["num_products"] print(product)
def most_sold_items(): print("--- Most sold items ---") print("Top 3 most sold product until now:") products = get_products() sales_file = get_sales() products_sold = {} for sold_items in sales_file: products_sold[sold_items["num_products"]] = 0 for product in products: product_id = product["product_id"] products_sold[product_id] += product["num_products"] print(product)
def get_products_from_url(url, location): """This method is meant to extract products from a get response :param url - site to search url :param location - SearchPlace location :return Dictionary with objects""" response = requests.get( url, headers={ 'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:57.0) Gecko/20100101 Firefox/57.0' }) response = response.text response = get_products(response, location) product_dict = {} update_dict(product_dict, response, location.name) return product_dict
def show_only_seasonal_products(): """ Ask for the user to select a season. Then, display the products to the user that match the selected season. """ print("--- Show only seasonal products ---\n") menu = get_products() seasons = [ { "id": 1, "name": "ALL" }, { "id": 2, "name": "SPRING" }, { "id": 3, "name": "SUMMER" }, { "id": 4, "name": "FALL" }, { "id": 5, "name": "WINTER" }, ] print('Select a season:') for sea in seasons: print(sea['name'].title(), '(' + str(sea['id']) + ')') print() this_season = select_by_id_or_name(seasons, 'season') print("Products available only in %s season:" % this_season["name"].title()) for product in menu: if product["season"] == this_season["name"]: print("-", product["name"])
def query_inventory_data(): print("---Query inventory data---") print("Which product is it?") list_products = get_products() for products in list_products: print(products['name'], products['id']) this_product = select_by_id_or_name(list_products, 'product') print("Description:", this_product["description"]) print("id:", this_product["id"]) print("Price per unit:", this_product["price"]) print("Quantity in stock:", this_product["quantity"]) print("Season:", this_product["season"]) print("Categories:", this_product["type"], "-", this_product["sub_type"])
def query_inventory_data(): print("---Envanter verilerini sorgulama---") print("Bu hangi ürün?") list_products = get_products() for products in list_products: print(products['id'], products['name']) this_product = select_by_id_or_name(list_products, 'product') print("Tanimlamasi:", this_product["description"]) print("Nosu:", this_product["id"]) print("Birim fiyati: %sTL" % this_product["price"]) print("Stoktaki Miktari:", this_product["quantity"]) print("Mevsimi:", this_product["season"]) print("Kategorileri:", this_product["type"], "-", this_product["sub_type"])
def register_product_arrival(): print("--- Register product arrival ---\n") print("Which product is it?") menu = get_products() for thing in menu: print(thing['name'], thing['id']) chooosen_product = select_by_id_or_name(menu, 'product') arrival_quantity = safe_input('int_positive', 'Recent arrival quantity:') chooosen_product['quantity'] += arrival_quantity print('OKAY. You\'ve registered %s items of %s product' % (arrival_quantity, chooosen_product['name'])) print('Now there are %s in stock' % chooosen_product['quantity']) update_products(menu)
def generate_report(): """ Generate a report for an employee This will write to a .txt file Sample file: ``` EMPLOYYEE NAME - POSITION | ID | NAME | QUANTITY | | ---- | ------------------- | -------- | | ... | ... | ... | | ... | ... | ... | ``` """ print("--- Generate employee's sales report ---") print("\nSelect an employee:") employees = get_employees() products = get_products() sales = get_sales() # display employees to the user for e in employees: print("- %s (%s)" % (e['name'], e['id'])) print() employee = select_by_id_or_name(employees, 'employee') print("Creating file...") product_quantities = {} # will be used for the output file largest_name = 0 # add initial values for product in products: product_quantities[product['id']] = 0 length = len(product['name']) if length > largest_name: largest_name = length # update the products sold by the employee for sale in sales: if sale['employee_id'] == employee['id']: product_quantities[sale['product_id']] += sale['num_products'] filename = "sales_report_%s_%s_%s_%s.txt" % ( employee['name'], employee['last_name'], # change to valid filename format today().replace('/', '-'), # apply some randomness to the filename randint(100, 999)) file = open(filename, 'w') file.write('%s %s - %s \n\n' % (employee['name'], employee['last_name'], employee['position'].title())) file.write('| ID | NAME' + (' ' * (largest_name - 4)) + ' | QUANTITY |\n') file.write('| ---- | ' + ('-' * largest_name) + ' | -------- |\n') for k in product_quantities: product = find_by_key(products, 'id', k) line = '| %s | %s | %s |\n' % (str(k).ljust(4), product['name'].ljust(largest_name), str(product_quantities[k]).ljust(8)) file.write(line) file.close() print('File saved as "%s"' % filename)
async def products(request): data = [] async for item in get_products(request): data.append(item) return response_api(data)