def bulk_order(): if request.method == "POST": data_list = request.json(force=True) for data in data_list: order = Order(data) sqldb.add_order(order) sqldb.add_order_details(order) elif request.method == "DELETE": for data in data_list: sqldb.delete_order(data)
def crud_order(order_id=None): if request.method == "POST": data = request.json(force=True) order = Order(data) sqldb.add_order(order) sqldb.add_order_details(order) elif request.method == "GET": sqldb.get_order(order_id) elif request.method == "DELETE": sqldb.delete_order(order_id)
reader = csv.DictReader(file) data = list(reader) data = [dict(i) for i in data] with Progress() as progress: products = {i["Lineitem sku"]: i["Lineitem name"] for i in data} task1 = progress.add_task("[cyan]Adding orders..", total=len(data)) task2 = progress.add_task("[green]Adding products..", total=len(products)) temp = {} for row in data: if row["Financial Status"] == "paid": if temp: order = Order(temp) sqldb.add_order(order) for detail in order.details: if detail.product_sku.isnumeric(): sqldb.add_order_details(detail) print(detail.order_id) time.sleep(0.02) temp = {} timestamp = row["Paid at"].split() temp = { "order_id": row["Name"][1:], "paid_at_time": timestamp[1], "paid_at_date": timestamp[0], "customer_name": row["Billing Name"], "items": [row["Lineitem sku"]], }