def show_product(name_product: str): """Starts session to show a product and automatically ends it""" with Session.begin() as session: statement = select( Product.description).filter_by(description=name_product) result = session.execute(statement).all() print(result)
def all_products(): """Starts session to show all products and automatically ends it""" with Session.begin() as session: statement = select(Product.serial, Product.description, Product.price) result = session.execute(statement).all() for row in result: print(row)
def show_customer(name_customer: str): """Starts session to show a customer and automatically ends it""" with Session.begin() as session: statement = select(Customer.name, Customer.address, Customer.phone).filter_by(name=name_customer) result = session.execute(statement).all() print(result)
def get_product(name_product: str) -> List[str]: """Starts session to show a product and automatically ends it""" with Session.begin() as session: statement = select(Product.serial, Product.description, Product.price).filter_by(description=name_product) result = session.execute(statement).all() product_list = list(flatten(result)) return product_list
def all_customers(): """Starts session to show all customers and automatically ends it""" with Session.begin() as session: statement = select(Customer.name,\ Customer.address, Customer.phone) result = session.execute(statement).all() for row in result: print(row)
def all_invoices(): """Starts session to show all invoices and automatically ends it""" with Session.begin() as session: stmt = select(Invoice.id, Invoice.serial, Invoice.customer_id) result = session.execute(stmt).all() products_invoices_list = all_products_invoices() for row in zip(result, products_invoices_list): print(row)
def get_customer(name_customer: str) -> List[str]: """Starts session to show a customer and automatically ends it""" with Session.begin() as session: statement = select(Customer.name, Customer.address, Customer.phone).filter_by(name=name_customer) result = session.execute(statement).all() customer_iterable = flatten(result) customer_list = list(customer_iterable) return customer_list
def show_invoice(serial_for_invoice: str): """Starts session to show an invoice and automatically ends it""" with Session.begin() as session: statement = select(Invoice.id, Invoice.serial, Invoice.customer_relationship).where( Invoice.serial == serial_for_invoice) result = session.execute(statement).all() products_invoice_object = show_products_invoice(result[0][0]) result.append(products_invoice_object) print(result)
def get_invoice_serial() -> int: """Starts session to show a invoice and automatically ends it""" with Session.begin() as session: statement = select(Invoice.serial) result = session.execute(statement).all() print(result) if not result: return 1000 result = flatten(result) result = list(result) result = int(result[-1]) return result
def all_products_invoices(): with Session.begin() as session: statement = select(ProductsInvoice.id, ProductsInvoice.product_id, ProductsInvoice.invoice_id, ProductsInvoice.product_serial, ProductsInvoice.product_description, ProductsInvoice.product_rate, ProductsInvoice.product_quantity, ProductsInvoice.product_total) result = session.execute(statement).all() print(result) return result
def show_products_invoice(products_invoice_id: str): with Session.begin() as session: statement = select(ProductsInvoice.id, ProductsInvoice.product_id, ProductsInvoice.invoice_id, ProductsInvoice.product_serial, ProductsInvoice.product_description, ProductsInvoice.product_rate, ProductsInvoice.product_quantity, ProductsInvoice.product_total).\ filter_by(id=products_invoice_id) result = session.execute(statement).all() return result
def remove_products_invoice(products_invoice_id: str): with Session.begin() as session: statement = delete(ProductsInvoice.id == products_invoice_id).\ execution_options(synchronize_session="fetch") session.execute(statement)
def add_invoice(filled_invoice: Invoice): """Starts session to add invoice and automatically ends it""" with Session.begin() as session: session.add(filled_invoice) session.commit()
def remove_invoice(serial_for_invoice: str): """Starts session to remove invoice and automatically ends it""" with Session.begin() as session: statement = delete(Invoice).where(Invoice.serial == serial_for_invoice).\ execution_options(synchronize_session='fetch') session.execute(statement)
def remove_customer(name_customer: str): """Starts session to remove customer and automatically ends it""" with Session.begin() as session: statement = delete(Customer).where(Customer.name == name_customer).\ execution_options(synchronize_session='fetch') session.execute(statement)
def remove_product(name_product: str): """Starts session to remove product and automatically ends it""" with Session.begin() as session: statement = delete(Product).where(Product.description == name_product).\ execution_options(synchronize_session='fetch') session.execute(statement)
def add_customer(customer_object: Customer): """Starts session to add customer and automatically ends it""" with Session.begin() as session: session.add(customer_object) session.commit()
def add_products_invoice(products_invoice_object: ProductsInvoice): with Session.begin() as session: session.add(products_invoice_object) session.commit()
def add_product(name_product: Product): """Starts session to add product and automatically ends it""" with Session.begin() as session: session.add(name_product) session.commit()