def read_db_for_sales(): '''Read show_db SQLite database and populate sales list''' try: db = sqlite3.connect('data/show_db.db') cur = db.cursor() cur.execute("PRAGMA foreign_keys=ON") # Fetch some data, using the cursor. This returns another cursor object # that can be iterated over for row in cur.execute('select * from sales'): #ui.message(row) update_ind = g.BLANK sales = Sales(row[1], row[2], row[3], row[4], update_ind) sales.set_id(row[0]) g.sales_list.append(sales) # ui.message('************* Sales **************') # ui.message(g.sales_list) # ui.message('') except sqlite3.Error as e: # As we are reading, no changes to roll back print('Error reading from database', e) logging.error('Database error {}'.format(e)) traceback.print_exc() finally: db.close()
def modify_sales_record(sale_index, sale_id): print('Your record to modify is:') print(g.sales_list[sale_index]) while True: clear() while True: try: saleitemid = int(input('Enter the item ID of the sale item (an integer from above list): ')) if saleitemid < 0: message('Enter a positive number') else: break except ValueError: message('Enter a whole number') while True: try: salequantity = int(input('Enter the quantity of sales items sold: ')) if salequantity < 0: message('Enter a positive number') else: break except ValueError: message('Enter a whole number') while True: try: saletotal = float(input('Enter the total sale dollar amount: ')) if saletotal < 0: message('Enter a positive amount') else: break except ValueError: message('Enter a positive amount') while True: try: showid = int(input('Enter the Show ID (an integer from the above list): ')) if showid < 0: message('Enter a positive number') else: break except ValueError: message('Enter a whole number') message('You entered {} {} {} {} '.format(saleitemid, salequantity, saletotal, showid)) check = input('Is this correct? "y" or "n": ') if check.lower() == 'y': break update_ind = g.MODIFY sale = Sales(saleitemid, salequantity, saletotal, showid, update_ind) # generate a new replacement object sale.set_id(sale_id) g.sales_list.insert(sale_index, sale) # insert the object back into the list where it came from
def random_employee(employee_type): if employee_type == 'developer': return Developer(**Developer.random_attrs()) if employee_type == 'sales': return Sales(**Sales.random_attrs()) if employee_type == 'project_manager': return ProjectManager(**ProjectManager.random_attrs()) if employee_type == 'support': return Support(**Support.random_attrs()) err_msg = ( '{} employee type is not supported.\n'.format(type), 'Allowed values are: \'developer\', \'project_manager\', \'sales\' or \'support\'', ) raise ValueError(err_msg)
class UserInterface: def __init__(self): self.warehouse = Warehouse() self.sales = Sales() self.finance = Finance() def add_new_bike(self, model, price, colour, size, gender, quantity): self.warehouse.add_item(model, price, colour, size, gender, quantity) def display_stock(self): self.warehouse.print_all_items() # def add_bike_to_cart(self,model,quantity): # if self.warehouse.can_buy(model,quantity) : # self.sales.add_to_cart(model,quantity) def add_to_cart(self): bike_model = input("Enter bike model:") bike_index = self.warehouse.find_bike_by_model(bike_model) if (bike_index == -1): print("We don't have that model") else: bike = self.warehouse.stock[bike_index] amount = int(input("How many of bikes would you buy?")) if (amount > bike.quantity): print("We don't have enough of that model") else: self.sales.add_to_cart(bike, amount) def make_purchase(self): cart = self.sales.get_cart() if (len(cart) == 0): print("No items in cart!") else: for bike, amount in cart: self.warehouse.decrease_quantity_by(bike.model, amount) report = self.finance.create_report(cart) print(report) self.sales.make_purchase() def display_cart(self): self.sales.display_cart() def display_reports(self): self.finance.display_reports() def empty_the_cart(self): self.sales.empty_the_cart()
def add_sales_record(): '''This function will add a sales record to the sales_list list the function will rely on the database to catch any foreign key mis-match errors''' clear() message('*** Enter a Sales Record ***') message('') message('*** Here are the available Items. The item ID must be specified') message(' when adding a sales item.') for item in g.items_list: message(item) message('') message('*** Here are the available Shows. The show ID must be specified') message(' when adding a sales item.') for show in g.show_list: message(show) message('') while True: clear() while True: try: saleitemid = int(input('Enter the item ID of the sale item (an integer from above list): ')) if saleitemid < 0: message('Enter a positive number') else: break except ValueError: message('Enter a whole number') while True: try: salequantity = int(input('Enter the quantity of sales items sold: ')) if salequantity < 0: message('Enter a positive number') else: break except ValueError: message('Enter a whole number') while True: try: saletotal = float(input('Enter the total sale dollar amount: ')) if saletotal < 0: message('Enter a positive amount') else: break except ValueError: message('Enter a whole decimal number') while True: try: showid = int(input('Enter the Show ID (an integer from the above list): ')) if showid < 0: message('Enter a positive amount') else: break except ValueError: message('Enter a whole number') message('You entered {} {} {} {} '.format(saleitemid, salequantity, saletotal, showid)) check = input('Is this correct? "y" or "n": ') if check.lower() == 'y': break update_ind = g.ADD sale = Sales(saleitemid, salequantity, saletotal, showid, update_ind) g.sales_list.append(sale) for sale in g.sales_list: message(sale)
def sales_btn(self): root2 = Toplevel(self.master) myGui = Sales(root2)
from flask import Flask, jsonify, request, abort, make_response from products import Products from sales import Sales app = Flask(__name__) product = Products() sales = Sales() # Error Handling @app.errorhandler(400) def bad_request(error): return make_response(jsonify({'error': 'Bad Request'}), 400) @app.errorhandler(404) def not_found(error): return make_response(jsonify({'error': 'Server Not Found'}), 404) # Routes @app.route('/store_manager/api/v1/user/products', methods=['GET']) def get_products(): return jsonify({'products': product.get_all_products()}), 200 @app.route('/store_manager/api/v1/admin/products', methods=['POST']) def create_product(): return jsonify({'product': product.create_pdt()}), 201 @app.route('/store_manager/api/v1/user/products/<int:pdt_id>', methods=['GET']) def get_product(pdt_id): return jsonify({'product': product.get_pdt(pdt_id)}), 200
}}) cherrypy.tree.mount( AllBooks(), '/api/allBooks', {'/': { 'request.dispatch': cherrypy.dispatch.MethodDispatcher() }}) cherrypy.tree.mount( Tickets(), '/api/tickets', {'/': { 'request.dispatch': cherrypy.dispatch.MethodDispatcher() }}) cherrypy.tree.mount( Sales(), '/api/sales', {'/': { 'request.dispatch': cherrypy.dispatch.MethodDispatcher() }}) cherrypy.tree.mount( AddCredit(), '/api/addcredit', {'/': { 'request.dispatch': cherrypy.dispatch.MethodDispatcher() }}) cherrypy.tree.mount( TotalSales(), '/api/totalsales', {'/': { 'request.dispatch': cherrypy.dispatch.MethodDispatcher() }})
def __init__(self): self.warehouse = Warehouse() self.sales = Sales() self.finance = Finance()