Пример #1
0
 def createOrder(self, destination, date, productsToAdd, isPaid, isShipped):
     print(destination)
     orderID = str(uuid.uuid4())
     newOrder = Order(orderID, destination, date, {}, isPaid, isShipped)
     print("Order Created")
     for item in productsToAdd.items():
         product, numOfProducts = item
         product = self.getProductByName(product)
         if numOfProducts <= product.stock:
             newOrder.addProduct(product.name, numOfProducts)
             self.updateProduct(product, "stock",
                                (product.stock - numOfProducts))
         else:
             print("could not add")
     print("Products added")
     self.orders.update({orderID: newOrder})
     print("Order databse updated")
     return newOrder.orderToString()
Пример #2
0
    def createOrder(self, request, context):
        orderID = str(uuid.uuid4())
        destination = request.destination
        date = request.date
        productsToAdd = request.products
        isPaid = request.isPaid
        isShipped = request.isShipped
        newOrder = Order(orderID, destination, date, {}, isPaid, isShipped)

        for item in productsToAdd.items():
            product, numOfProducts = item
            product = self.getProductByName(product)
            if numOfProducts <= product.stock:
                newOrder.addProduct(product.name, numOfProducts)
                self.updateProduct(product, "stock",
                                   (product.stock - numOfProducts))
            else:
                context.set_code(grpc.StatusCode.ABORTED)
                context.set_details("Could not add " + product.name +
                                    ": not enough in stock")

        self.orders.update({orderID: newOrder})
        return newOrder.returnOrder()