Example #1
0
def fire_employee(employee):
    try:
        session.query(Employee).filter_by(
            employee_id=employee.employee_id).delete()
        session.commit()
    except:
        session.rollback()
Example #2
0
def store_new_first_name(customer, new_value):
    try:
        customer.contactFirstName = new_value
        # ....
        session.commit()
    except:
        session.rollback()
Example #3
0
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
Example #4
0
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
Example #6
0
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()
Example #7
0
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.")
Example #8
0
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()
Example #9
0
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
Example #10
0
def delete_product(product):
    success = False
    try:
        session.delete(product)
        session.commit()
        success = True
    except:
        session.rollback()
    finally:
        return success
Example #11
0
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
Example #12
0
def add_product(product: SparePart):
    success = False
    try:
        session.add(product)
        session.commit()
        success = True
    except:
        session.rollback()
    finally:
        return success
    """
Example #13
0
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()
Example #14
0
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
Example #17
0
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
Example #18
0
def store_changes():
    session.commit()
Example #19
0
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
Example #20
0
def edit_new_email(customer, edit_email):
    customer.private_customer_email = edit_email
    session.commit()
Example #21
0
def edit_new_phone_number(customer, edit_phone_number):
    customer.private_customer_phone = edit_phone_number
    session.commit()
Example #22
0
def add_private_customer(customer):
    session.add(customer)
    session.commit()
Example #23
0
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()
Example #27
0
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()