示例#1
0
def steal_products(thief):
    available_items = SparePart.find(**{"stores.store_id": thief.store_id})
    stolen_item = random.choice(available_items)
    amount = stolen_item.stores[0]["stock"]
    stolen_item.stores[0]["stock"] = 0
    stolen_item.save()
    return amount, stolen_item
示例#2
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()
示例#3
0
def get_product_by_product_nr(product_nr: str):
    return MongoSparePart.find(product_nr=product_nr).first_or_none()
示例#4
0
def get_product_by_id(product_id: str):
    return MongoSparePart.find(_id=product_id).first_or_none()