def post(self, request, format=None): serializer = ProductSerializers(data=request.data) if serializer.is_valid(): serializer.save() datas = serializer.data return Response(datas) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def post(self, request, format=None): rol = request.user.is_superuser if rol == True: serializerProduct = ProductSerializers(data=request.data) if serializerProduct.is_valid(): serializerProduct.save() datas = serializerProduct.data ########## POST FOR INVENTORY ############# postInventory = Inventory.objects.create( user_id=request.user.id, product_id=datas['id'], quantity=request.data['quantity'], price=request.data['price'], tax=request.data['tax']) postInventory.save() ########## POST FOR TRANSACTIONS ############# Transaction.objects.create(inventory_id=postInventory.id, dates=timezone.now(), types=1, quantity=postInventory.quantity, description="Se agrego " + request.data['quantity'] + " " + datas['name']) return Response(datas) return Response(serializerProduct.errors, status=status.HTTP_400_BAD_REQUEST) else: return Response("No eres administrador")
def put(self, request, id, format=None): example = self.get_object(id) if example != False: serializer = ProductSerializers(example, data=request.data) if serializer.is_valid(): serializer.save() datas = serializer.data return Response(datas) else: return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) else: return Response(status=status.HTTP_400_BAD_REQUEST)
def put(self, request, id, format=None): rol = request.user.is_superuser idSale = self.get_object(id) if rol == True: searchIdSale = Sale.objects.get(pk=id) serializerSale = SaleSerializers(searchIdSale) SALE = serializerSale.data Sale.objects.filter(pk=id).update(status=request.data['status']) searchIdProduct = Inventory.objects.get( product=int(SALE['product'])) serializerInventory = InventorySerializers(searchIdProduct) INVENTORY = serializerInventory.data op = Operaciones(INVENTORY, SALE) Inventory.objects.filter(pk=int(SALE['product'])).update( quantity=op.residuo(int(request.data['status']))) inventoryIdProductSale = INVENTORY['id'] # print("ID inv sale: ", inventoryIdProductSale) idProduct = int(request.data['product']) searchIdProductInProducts = Product.objects.get(pk=idProduct) serializerProduct = ProductSerializers(searchIdProductInProducts) PRODUCT = serializerProduct.data Transaction.objects.create( inventory_id=inventoryIdProductSale, dates=timezone.now(), types=2, quantity=op.residuo(int(request.data['status'])), description="Se cancelo la venta del producto " + PRODUCT['name']) return Response("Success")
def get(self, request, id, format=None): example = self.get_object(id) if example != False: serializer = ProductSerializers(example) return Response(serializer.data) else: return Response(status=status.HTTP_400_BAD_REQUEST)
def post(self, request, format=None): #saleInventory = SaleSerializers(data = request.data) print("Request ", request.data) productId = int(request.data['product']) print("type value", type(productId)) SALES = request.data searchIdProduct = Inventory.objects.get(product=int(SALES['product'])) serializerInventory = InventorySerializers(searchIdProduct) INVENTORY = serializerInventory.data print("Vlues inventory", INVENTORY) ########## POST FOR TRANSACTIONS ############# op = Operaciones(INVENTORY, SALES) print(op.total()) newSale = Sale.objects.create( user_id=request.user.id, product_id=request.data['product'], quantity=request.data['quantity'], discount=SALES['discount'], total=op.total(), dates=timezone.now(), payment=SALES['payment'], status=SALES['status'], ) newSale.save() ########## UPDATE FOR PRODUCTS ############# Inventory.objects.filter(pk=int(SALES['product'])).update( quantity=op.residuo()) ########## POST FOR TRANSACTIONS ############# inventoryIdProductSale = INVENTORY['id'] idProduct = int(request.data['product']) searchIdProductInProducts = Product.objects.get(pk=idProduct) serializerProduct = ProductSerializers(searchIdProductInProducts) PRODUCT = serializerProduct.data Transaction.objects.create(inventory_id=inventoryIdProductSale, dates=timezone.now(), types=2, quantity=request.data['quantity'], description="Se vendio " + request.data['quantity'] + " " + PRODUCT['name']) return Response("Success")
def put(self, request, id, format=None): rol = request.user.is_superuser idSale = self.get_object(id) if rol == True: searchIdSale = Sale.objects.get(pk=id) serializerSale = SaleSerializers(searchIdSale) SALE = serializerSale.data print("status: ", request.data['status']) ########## UPDATE FOR status SALE ############# Sale.objects.filter(pk=id).update(status=request.data['status']) ########## POST FOR TRANSACTIONS ############# searchIdProduct = Inventory.objects.get( product=int(SALE['product'])) serializerInventory = InventorySerializers(searchIdProduct) INVENTORY = serializerInventory.data op = Operaciones(INVENTORY, SALE) quantitySum = op.residuo(int(request.data['status'])) print("Cancel suma: ", quantitySum) Inventory.objects.filter(pk=int(SALE['product'])).update( quantity=quantitySum) ########## POST FOR TRANSACTIONS ############# inventoryIdProductSale = INVENTORY['id'] print("ID inv sale: ", inventoryIdProductSale) print("Request", request.data) idProduct = int(request.data['product']) searchIdProductInProducts = Product.objects.get(pk=idProduct) serializerProduct = ProductSerializers(searchIdProductInProducts) PRODUCT = serializerProduct.data Transaction.objects.create( inventory_id=inventoryIdProductSale, dates=timezone.now(), types=2, quantity=op.residuo(int(request.data['status'])), description="Se cancelo la venta del producto " + PRODUCT['name']) return Response("Succes") else: return Response("No eres admin")
def get(self, request, format=None): queryset = Product.objects.all() serializer = ProductSerializers(queryset, many=True) return Response(serializer.data)