def ObtenerProductos(): try: #prov = str(request.args['proveedor']) #if len(prov) == 11: np = UIProducto() lista = np.getProductos() response = jsonify({ "producto": [{ "id": x.idProd, "descripcion": x.descripcion, "precioU": x.precio_uni, "stock": x.cant_stock, "cantMin": x.cant_min, "cuit": x.cuit } for x in lista], 'msj': '' }) #else: # response = jsonify({ # 'msj': 'El cuit debe contener 11 numeros' # }) response.headers.add('Access-Control-Allow-Origin', '*') return response except ValueError as ve: response = jsonify({'msj': 'El campo no es correcto'}) response.headers.add('Access-Control-Allow-Origin', '*') return response except Exception as e: print(e.args) response = jsonify({'msj': 'Error al objetener el producto'}) response.headers.add('Access-Control-Allow-Origin', '*') return response
def addSolicitud(): try: dni = request.json['cliente'] #precio = request.args['precio_total'] fecha_sol = date.today() #Agregar fecha_vto_solicitud sol_details = request.json['productos'] s = UISolicitud() p = UIProducto() total = 0 for valor in sol_details[0]: prod = p.buscarProducto(valor['id']) total += prod.precio_uni sol = s.Alta(dni=dni, total=total, fecha=fecha_sol) sd = UISolicitudDetalle() #for det in sol_details[0]: nuevo_detalle = sd.Alta(sol.nroSolicitud, sol_details[0]) if (not nuevo_detalle is None): response = jsonify({'msj': 'ok'}) else: response = jsonify({'msj': 'Error'}) except Exception as ex: response = jsonify({'msj': 'Error de servicio'}) response.headers.add('Access-Control-Allow-Origin', '*') return response
def validaSolicitud(self, nro_sol, cant, prod): try: if not nro_sol is None: sol = UISolicitud() validaSol = sol.buscarSolicitud(nro_sol) if not cant is None and not prod is None: p = UIProducto() pr = p.buscarProducto(prod) if not p is None: if cant < pr.cant_stock: return True except Exception as ex: print(ex) return False
def AgregarProducto(): try: desc = request.json['descripcion'] precio_u = request.json['precioU'] stock = request.json['stock'] cantM = request.json['cantMin'] prov = request.json['cuit'] np = UIProducto() msj = np.alta(desc, precio_u, stock, cantM, prov) response = jsonify({'msj': 'msj'}) response.headers.add('Access-Control-Allow-Origin', '*') return response except Exception as e: print(e.args) response = jsonify({'msj': 'Error de servicio'}) response.headers.add('Access-Control-Allow-Origin', '*') return response
def ActualizarProducto(): try: id = int(request.args['id']) desc = str(request.args['desc']) precioU = float(request.args['precio_u']) stock = int(request.args['stock']) cantM = int(request.args['cant_m']) cuit = str(request.args['prov']) p = UIProducto() prod = p.updateProducto(id, desc, precioU, stock, cantM, cuit) if not prod is None: response = jsonify({ 'producto': [{ "id": prod.idProd, "descripcion": prod.descripcion, "precioUnitario": prod.precio_uni, "stock": prod.cant_stock, "cantidad_minima_stock": prod.cant_min, "proveedor": prod.cuit }], 'msj': '' }) else: if prod is None: response = jsonify( {'msj': 'Ocurrio un error al actualizar el producto'}) else: response = jsonify({'msj': prod}) response.headers.add('Access-Control-Allow-Origin', '*') return response except ValueError as ve: response = jsonify({'msj': 'Los campos no son correctos'}) response.headers.add('Access-Control-Allow-Origin', '*') return response except Exception as e: print(e.args) return jsonify({'msj': 'Ocurrio un error al modificar el producto'})
def EliminarProductoid(id): try: id = id #int(request.args['id_producto']) p = UIProducto() msj = p.deleteProducto(id) if msj == 'ok': response = jsonify({'msj': msj}) else: response = jsonify({'msj': msj}) response.headers.add('Access-Control-Allow-Origin', '*') return response except ValueError as ve: response = jsonify({'msj': 'El campo no es correcto'}) response.headers.add('Access-Control-Allow-Origin', '*') return response except Exception as e: print(e.args) response = jsonify({msj: 'Ocurrio un error al eliminar el producto'}) response.headers.add('Access-Control-Allow-Origin', '*') return response