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 steal_car():
    customer_cars = session.query(CustomerCar.customer_registration_nr).all()

    stolen_car = session.query(CustomerCar).filter_by(
        customer_registration_nr=random.choice(customer_cars)[0]).first()

    session.query(CustomerCar).filter_by(
        customer_registration_nr=stolen_car.customer_registration_nr).delete()

    return stolen_car
Example #3
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 #4
0
def fix_spare_parts():
    spare_parts = session.query(SparePart).all()

    for spare_part in spare_parts:
        as_dict = spare_part.__dict__
        as_dict['manufacturer_id'] = MongoManufacturer.find(
            manufacturer_id=spare_part.manufacturer_id).first_or_none()._id
        as_dict['supplier_id'] = MongoSupplier.find(
            supplier_id=spare_part.supplier_id).first_or_none()._id
        car_models = []
        if spare_part.car_models is not None:
            for car_model in spare_part.car_models:
                car_models.append({
                    'model_name': car_model.model_name,
                    'brand_name': car_model.brand_name
                })
            as_dict.update({'car_models': car_models})
        stores = []
        for store in spare_part.stores:
            stores.append({
                'store_id':
                MongoStore.find(store_id=store.store_id).first_or_none()._id,
                'stock':
                store.stock,
                'stock_location':
                store.stock_location
            })
        as_dict.update({'stores': stores})
        as_dict['estimated_time_of_arrival'] = datetime.datetime(
            spare_part.estimated_time_of_arrival.year,
            spare_part.estimated_time_of_arrival.month,
            spare_part.estimated_time_of_arrival.day)
        del as_dict["_sa_instance_state"]
        mongo_spare_part = MongoSparePart(as_dict)
        mongo_spare_part.save()
Example #5
0
def fix_orders():
    orders = session.query(Order).all()

    for order in orders:
        as_dict = order.__dict__
        as_dict["employee_id"] = MongoEmployee.find(
            employee_id=order.employee_id).first_or_none()._id
        as_dict["customer_id"] = MongoCustomer.find(
            customer_id=order.customer_id).first_or_none()._id
        as_dict["store_id"] = MongoStore.find(
            store_id=order.store_id).first_or_none()._id

        order_line = [{
            "spare_part_id":
            MongoSparePart.find(
                spare_part_id=ol.spare_part_id).first_or_none()._id,
            "quantity":
            ol.quantity
        } for ol in order.order_lines]

        as_dict.update({"order_detail": order_line})

        del as_dict["order_lines"]
        del as_dict["_sa_instance_state"]

        mongo_order = MongoOrder(as_dict)

        for ol in mongo_order.order_detail:
            del ol["spare_part"]

        mongo_order.save()
Example #6
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
Example #7
0
def fix_customers():
    customers = session.query(Customer).all()
    for customer in customers:
        as_dict = customer.__dict__
        if customer.customer_type == 1:
            as_dict.update({
                'customer_first_name':
                customer.priv_customer[0].private_customer_first_name
            })
            as_dict.update({
                'customer_last_name':
                customer.priv_customer[0].private_customer_last_name
            })
            as_dict.update({
                'customer_phone':
                customer.priv_customer[0].private_customer_phone
            })
            as_dict.update({
                'customer_email':
                customer.priv_customer[0].private_customer_email
            })
            del as_dict['priv_customer']
        else:
            as_dict.update({
                'company_name':
                customer.comp_customer[0].company_customer_company_name
            })
            as_dict.update({
                'customer_first_name':
                customer.comp_customer[0].company_customer_first_name
            })
            as_dict.update({
                'customer_last_name':
                customer.comp_customer[0].company_customer_last_name
            })
            as_dict.update({
                'customer_phone':
                customer.comp_customer[0].company_customer_phone
            })
            as_dict.update({
                'customer_email':
                customer.comp_customer[0].company_customer_email
            })
            del as_dict['comp_customer']
        customer_cars = []
        for car in customer.cars:
            customer_cars.append({
                'customer_registration_nr': car.customer_registration_nr,
                'customer_car_brand': car.customer_car_brand,
                'customer_car_model': car.customer_car_model,
                'customer_car_model_year': car.customer_car_model_year,
                'customer_car_color': car.customer_car_color
            })
        as_dict.update({'cars': customer_cars})
        del as_dict['_sa_instance_state']
        del as_dict['customer_type']

        mongo_customer = MongoCustomer(as_dict)
        mongo_customer.save()
Example #8
0
def fix_stores():
    stores = session.query(Store).all()

    for store in stores:
        as_dict = store.__dict__
        del as_dict["_sa_instance_state"]

        mongo_store = MongoStore(as_dict)
        mongo_store.save()
Example #9
0
def fix_suppliers():
    suppliers = session.query(Supplier).all()

    for supplier in suppliers:
        as_dict = supplier.__dict__
        del as_dict["_sa_instance_state"]

        mongo_supplier = MongoSupplier(as_dict)
        mongo_supplier.save()
Example #10
0
def fix_employees():
    employees = session.query(Employee).all()

    for employee in employees:
        as_dict = employee.__dict__
        as_dict["store_id"] = MongoStore.find(
            store_id=employee.store_id).first_or_none()._id
        as_dict["employee_first_name"] = employee.employee_name
        as_dict["employee_last_name"] = employee.employee_lastname
        del as_dict["employee_name"]
        del as_dict["employee_lastname"]
        del as_dict["_sa_instance_state"]

        mongo_employee = MongoEmployee(as_dict)
        mongo_employee.save()
def fix_manufacturers():
    manufacturers = session.query(Manufacturer).all()

    for manufacturer in manufacturers:
        as_dict = manufacturer.__dict__

        if manufacturer.company_contacts is not None:
            contact_list_dict = []
            for contact in manufacturer.company_contacts:
                contact_list_dict.append({
                    'manufacturer_contact_name':
                    contact.manufacturer_contact_name,
                    'manufacturer_contact_phone_nr':
                    contact.manufacturer_contact_phone_nr,
                    'manufacturer_contact_email':
                    contact.manufacturer_contact_email
                })
            as_dict.update({'company_contacts': contact_list_dict})

        del as_dict['_sa_instance_state']

        mongo_manufacturer = MongoManufacturer(as_dict)
        mongo_manufacturer.save()
Example #12
0
def get_product_by_product_nr(product_nr: str):
    return session.query(SparePart).filter(
        SparePart.product_nr == product_nr).first()
def find_customer_by_name(keyword):
    return session.query(Customer).filter(
        Customer.name.like(f'%{keyword}%')).all()
def find_customer_by_id(keyword):
    return session.query(Customer).filter(Customer.id == keyword).all()
Example #15
0
def get_all_car_models():
    return session.query(CarModel).all()
Example #16
0
def get_manufacturer_by_id(manufacturer_id):
    return session.query(Manufacturer).filter(
        Manufacturer.manufacturer_id == manufacturer_id).first()
Example #17
0
def get_supplier_by_id(supplier_id):
    return session.query(Supplier).filter(
        Supplier.supplier_id == supplier_id).first()
Example #18
0
def show_people():
    return session.query(People).all()
Example #19
0
def get_all_products():
    return session.query(SparePart).all()
Example #20
0
def get_all_customers():
    return session.query(Customer).all()
Example #21
0
def get_customer_by_id(selected_id):
    return session.query(Customer).filter_by(
        customer_id=int(selected_id)).first()
Example #22
0
def get_customer_by_first_name(selected_first_name):
    return session.query(PrivateCustomer).filter_by(
        private_customer_first_name=selected_first_name).first()
Example #23
0
def get_employee_by_id(selection):
    return session.query(Employee).filter_by(employee_id=selection).first()
Example #24
0
def get_all_employees():
    return session.query(Employee).all()
Example #25
0
def get_private_customer():
    return session.query(PrivateCustomer).all()
Example #26
0
def get_products_by_product_description_pattern(description_pattern: str):
    return session.query(SparePart).filter(
        SparePart.description.like(f'%{description_pattern}%')).all()
Example #27
0
def get_customer_by_name(pattern):
    # Post.query.filter(Post.tags.like(search)).all()
    return session.query(Customer).filter(
        Customer.customerName.like(f'%{pattern}%')).all()
Example #28
0
def get_all_stores():
    return session.query(SparePartStore).all()
Example #29
0
def get_customer_by_id(id):
    return session.query(Customer).filter(
        Customer.customerNumber == id).first()
Example #30
0
def get_car_model_by_id(car_model_id):
    return session.query(CarModel).filter(
        CarModel.car_model_id == car_model_id).first()