Exemplo n.º 1
0
Arquivo: api.py Projeto: vdog/piedb
def upsert_order():
    incoming = request.get_json()
    print(incoming)
    order = Orders()
    customer = Customer()
    orderid = incoming.get("OrderID", -1)
    customerid = incoming.get("CustomerID", None)
    if orderid != -1:
        order = model.db.query(Orders).get(incoming["OrderID"])
        model.db.query(OrderDetails).filter(OrderDetails.OrderID == incoming["OrderID"]).delete()
    if customerid is not None:
        customer = model.db.query(Customer).get(customerid)
        if customer is None:
            customer = Customer()
    order.ShipAddress = incoming["ShipAddress"]
    order.ShipName = incoming["ShipName"]
    order.RequiredDate = dateutil.parser.parse(incoming["RequiredDate"])
    order.CustomerID = incoming["CustomerID"]
    order.ShipCity = incoming["ShipCity"]
    order.ShipRegion = incoming["ShipRegion"]
    order.ShipPostalCode = incoming["ShipPostalCode"]
    order.OrdPaid = incoming["OrdPaid"]
    order.CustomerID = customerid
    model.db.add(order)
    if incoming["customer"] is not None:
        inbound = incoming["customer"]
        customer.CustomerID = customerid
        customer.CustomerFirstName = inbound["CustomerFirstName"]
        customer.CompanyName = inbound["CompanyName"]
        model.db.add(customer)
    model.db.commit()
    for tail in incoming["details"]:
        print(tail["OrderID"])
        if tail["OrderID"] is None:
            tail["OrderID"] = order.OrderID
        detail = OrderDetails()
        detail.serialize_in(tail)
        model.db.add(detail)

    model.db.commit()
    return json.dumps(incoming)
Exemplo n.º 2
0
Arquivo: api.py Projeto: vdog/piedb
def get_new_order():
    order = Orders()
    order.RequiredDate = None
    order.OrderID = -1
    return json.dumps(order.serialize())