def fire_employee(employee): try: session.query(Employee).filter_by( employee_id=employee.employee_id).delete() session.commit() except: session.rollback()
def store_new_first_name(customer, new_value): try: customer.contactFirstName = new_value # .... session.commit() except: session.rollback()
def add_customer_car(customer, c): regnr, car_model_id, color = c customer_id = customer.id new_car = CustomerCar(customer_id=customer_id, regnr=regnr, car_model_id=car_model_id, color=color) session.add(new_car) session.commit() return new_car
def steal_products(thief): item = session.query(SparePartStore).filter(SparePartStore.store_id == thief.store_id) \ .filter(SparePartStore.spare_part_id == random.choice([1, 2, 3, 4])).first() amount = item.stock item.stock = 0 session.commit() return amount, item.spare_part.description
def add_contact_person(contact_person, chosen_customer): name, phone, email = contact_person contact_person = ContactPerson(name=name, phone=phone, email=email) session.add(contact_person) session.commit() chosen_customer.contact_id = contact_person.id session.commit() return contact_person
def add_event(name, location, description, date, person_id): event = Event(Name=name, Location=location, Description=description, Date=date, people_id=person_id) session.add(event) session.commit()
def remove_store(store): if not store.employees: session.delete(store) session.commit() return f"Butiken {store} har tagits bort." else: return (f"Du får inte ta bort butiken {store} eftersom det finns tillhörande anställda. " f"Ta bort eller flytta dessa innan du försöker igen.")
def add_employee(e): store_id, name, phone, email, job_title = e new_employee = Employee(store_id=store_id, name=name, phone=phone, email=email, job_title=job_title) session.add(new_employee) session.commit()
def add_product(product, order: Order) -> OrderedProduct: ordered_product: OrderedProduct = OrderedProduct( order_id=order.id, product_id=product[0], product_amount=product[1], ) session.add(ordered_product) session.commit() return ordered_product
def delete_product(product): success = False try: session.delete(product) session.commit() success = True except: session.rollback() finally: return success
def delete_customer(customer): success = False try: session.query(Customer).filter( Customer.customer_id == customer[0].customer_id).delete() session.commit() success = True except: session.rollback() finally: return success
def add_product(product: SparePart): success = False try: session.add(product) session.commit() success = True except: session.rollback() finally: return success """
def add_people_from_file(): with open("/_documents/people.txt", "r") as file: peoples = defaultdict() for column in file.readlines(): line = column.split() peoples["FirstName"] = line[0] peoples["LastName"] = line[1] peoples["DOB"] = line[2] peoples["Relation"] = line[3] users = People(**peoples) session.add(users) session.commit()
def update_product(product: SparePart, attribute_name, new_value): success = False try: for product_attribute, value in vars(product).items(): if product_attribute == attribute_name: product.__setattr__(product_attribute, new_value) session.commit() success = True except: session.rollback() finally: return success
def add_private(customer): name, street_address, zip_code, city, phone, email, customer_type = customer customer = Customer(name=name, street_address=street_address, zip_code=zip_code, city=city, phone=phone, email=email, customer_type_id=customer_type) session.add(customer) session.commit() return customer
def add_business(customer, contact_person): name, street_address, zip_code, city, phone, email, customer_type = customer contact_person = cpr.add_contact_person_to_new_customer(contact_person) contact_id = contact_person.id customer = Customer(name=name, street_address=street_address, zip_code=zip_code, city=city, phone=phone, email=email, customer_type_id=customer_type, contact_id=contact_id) session.add(customer) session.commit() return customer
def create(**kwargs): # TODO: Use default in model kwargs['date_created'] = dt.datetime.utcnow() try: order = Order(**kwargs) # TODO: Check if order could be created except Exception: return None try: session.add(order) except Exception as e: print(repr(e)) return None try: session.commit() except Exception as e: print(repr(e)) session.rollback() return None return order
def store_changes(): session.commit()
def add_store(store): name, street_address, zip_code, city, phone, email = store store = Store(name=name, street_address=street_address, zip_code=zip_code, city=city, phone=phone, email=email) session.add(store) session.commit() return store
def edit_new_email(customer, edit_email): customer.private_customer_email = edit_email session.commit()
def edit_new_phone_number(customer, edit_phone_number): customer.private_customer_phone = edit_phone_number session.commit()
def add_private_customer(customer): session.add(customer) session.commit()
def add_gift(name, price, link): gift = Gift(Name=name, Price=price, Link=link) session.add(gift) session.commit()
def save_changes(_): session.commit()
def remove_customer(chosen_customer): session.delete(chosen_customer) session.commit()
def edit_new_email(customer, edit_email): customer.company_customer_email = edit_email session.commit()
def remove_customer_car(_, car): session.delete(car) session.commit()
def add_company_customer(customer): session.add(customer) session.commit()
def create_order(new_order): try: session.add(new_order) session.commit() except: session.rollback()
def update_stock(old_stock, quantity): try: old_stock.stock -= quantity session.commit() except: session.rollback()