Exemplo n.º 1
0
 def InvDetail(self, request, context):
     try:
         inv = Inventory.get(Inventory.goods == request.goodsId)
         return inventory_pb2.GoodsInvInfo(goodsId=inv.goods,
                                           num=inv.stocks)
     except DoesNotExist:
         context.set_code(grpc.StatusCode.NOT_FOUND)
         context.set_details("Inventory not found")
         return inventory_pb2.GoodsInvInfo()
 def reback(self):
     goods_list = [(1, 3), (30, 5)]
     request = inventory_pb2.SellInfo()
     for goodsId, num in goods_list:
         request.goodsInfo.append(
             inventory_pb2.GoodsInvInfo(goodsId=goodsId, num=num))
     rsp = self.inventory_stub.Reback(request)
 def sell(self):
     goods_list = [(421, 3), (422, 5)]
     request = inventory_pb2.SellInfo()
     for goodsId, num in goods_list:
         request.goodsInfo.append(
             inventory_pb2.GoodsInvInfo(goodsId=goodsId, num=num))
     rsp = self.inventory_stub.Sell(request)
 def get_inv(self):
     rsp = self.inventory_stub.InvDetail(
         inventory_pb2.GoodsInvInfo(goodsId=3))
     print(rsp.num)
 def set_inv(self):
     rsp = self.inventory_stub.SetInv(
         inventory_pb2.GoodsInvInfo(goodsId=10, num=110))