def viewMachineRoute(self, request): formLogout = loginForm() data = db.session.query(machine.id, machine.nameMachine).order_by(machine.id.asc()) return render_template('viewMachine.html', formLogout=formLogout, data=data)
def registerMachineRoute(self, request): if current_user.typeUser == 3: flash('Error 404: Ruta no encontrada', 'WA') return redirect(url_for('homeRoute')) form = machineForm(request.form) # Creacion del formulario formLogout = loginForm() if request.method == 'POST' and form.validate(): machineTemp = db.session.query(machine).filter( machine.nameMachine == request.form['nameMachine']).first() if machineTemp: # error de nombre flash('Error: Ya existe una maquina registrada a ese nombre', 'WA') return render_template('registerMachine.html', formLogout=formLogout, form=form) machineNuevo = machine( nameMachine=request.form['nameMachine'], descriptionMachine=request.form['descriptionMachine']) db.session.add(machineNuevo) db.session.commit() flash('Maquina registrada exitosamente', 'AC') return redirect(url_for('homeRoute')) else: return render_template('registerMachine.html', formLogout=formLogout, form=form)
def viewComponentRoute(self, request): formLogout = loginForm() data = db.session.query(component).order_by( component.codeMachine.asc()) return render_template('viewComponent.html', formLogout=formLogout, data=data)
def stockRoute(self, request): formPurchase = stockForm(request.form) # Creacion del formulario formPurchase.codeComponent.choices = [ (g.id, g.machine.nameMachine + " : " + g.nameComponent) for g in db.session.query(component) ] formUtilization = formPurchase formLogout = loginForm() return render_template('stock.html', formLogout=formLogout, formPurchase=formPurchase, formUtilization=formUtilization)
def updateMachineRoute(self, request): if current_user.typeUser == 3: flash('Error 404: Ruta no encontrada', 'WA') return redirect(url_for('homeRoute')) form = machineForm(request.form) # Creacion del formulario formLogout = loginForm() if request.method == 'POST' and form.validate(): machineTemp = db.session.query(machine).filter( machine.id == request.form['codeMachine']).first() if not machineTemp: flash('Error: No existe una maquina registrada a ese nombre', 'WA') data = db.session.query( machine.id, machine.nameMachine).order_by(machine.id.asc()) return render_template('updateMachine.html', formLogout=formLogout, form=form, data=data) machineDuplicate = db.session.query(machine).filter( machine.nameMachine == request.form['nameMachine']).filter( machine.id != request.form['codeMachine']).first() if machineDuplicate: # error de nombre flash('Error: Ya existe una maquina registrada a ese nombre', 'WA') data = db.session.query( machine.id, machine.nameMachine).order_by(machine.id.asc()) return render_template('updateMachine.html', formLogout=formLogout, form=form, data=data) machineTemp.nameMachine = request.form['nameMachine'] machineTemp.descriptionMachine = request.form['descriptionMachine'] db.session.commit() flash('Maquina actualizada exitosamente', 'AC') return redirect(url_for('homeRoute')) else: data = db.session.query(machine.id, machine.nameMachine).order_by( machine.id.asc()) return render_template('updateMachine.html', formLogout=formLogout, form=form, data=data)
def registerComponentRoute(self, request): if current_user.typeUser == 3: flash('Error 404: Ruta no encontrada', 'WA') return redirect(url_for('homeRoute')) form = componentForm(request.form) # Creacion del formulario form.codeMachine.choices = [(g.id, g.nameMachine) for g in db.session.query(machine)] formLogout = loginForm() if request.method == 'POST' and form.validate(): componentTemp = db.session.query(component).filter( component.nameComponent == request.form['nameComponent']).first() if componentTemp: # error de nombre flash('Error: Ya existe un componente registrado a ese nombre', 'WA') return render_template('registerComponent.html', formLogout=formLogout, form=form) componentNuevo = component( codeMachine=request.form['codeMachine'], nameComponent=request.form['nameComponent'], typeComponent=request.form['typeComponent'], priority=request.form['priority'], notes=request.form['notes'], currentStock=request.form['currentStock'], minimumStock=request.form['minimumStock']) db.session.add(componentNuevo) componentTemp = db.session.query(component).filter( component.nameComponent == request.form['nameComponent']).first() purchaseNuevo = purchase(codeComponent=componentTemp.id, date=request.form['date'], amount=request.form['currentStock']) db.session.add(purchaseNuevo) db.session.commit() flash('Componente registrado exitosamente', 'AC') return redirect(url_for('homeRoute')) else: return render_template('registerComponent.html', formLogout=formLogout, form=form)
def updateComponentRoute(self, request): if current_user.typeUser == 3: flash('Error 404: Ruta no encontrada', 'WA') return redirect(url_for('homeRoute')) form = componentUpdateForm(request.form) # Creacion del formulario formLogout = loginForm() data = db.session.query(component).order_by( component.codeMachine.asc()) if request.method == 'POST' and form.validate(): componentTemp = db.session.query(component).filter( component.id == request.form['codeComponent']).first() if not componentTemp: flash('Error: No existe un componente registrado a ese nombre', 'WA') return render_template('updateComponent.html', formLogout=formLogout, form=form, data=data) componentDuplicate = db.session.query(component).filter( component.nameComponent == request.form['nameComponent'] ).filter(component.id != request.form['codeComponent']).first() if componentDuplicate: # error de nombre flash('Error: Ya existe un componente registrado a ese nombre', 'WA') return render_template('updateComponent.html', formLogout=formLogout, form=form, data=data) componentTemp.nameComponent = request.form['nameComponent'] componentTemp.typeComponent = request.form['typeComponent'] componentTemp.priority = request.form['priority'] componentTemp.notes = request.form['notes'] componentTemp.minimumStock = request.form['minimumStock'] db.session.commit() flash('Componente actualizado exitosamente', 'AC') return redirect(url_for('homeRoute')) else: return render_template('updateComponent.html', formLogout=formLogout, form=form, data=data)
def registerRoute(self, request): if current_user.typeUser == 3: flash('Error 404: Ruta no encontrada', 'WA') return redirect(url_for('homeRoute')) form = registerForm(request.form) # Creacion del formulario formLogout = loginForm() if request.method == 'POST' and form.validate(): userTemp = db.session.query(user).filter(user.nameUser == request.form['nameUser']).first() if userTemp: # error de nombre flash('Error: Ya existe una cuenta registrada a ese nombre', 'WA') return render_template('register.html', formLogout=formLogout, form=form) userTemp = db.session.query(user).filter(user.username == request.form['username']).first() if userTemp: # error de nombre de usuario flash('Error: Ya existe una cuenta registrada a ese nombre de usuario', 'WA') return render_template('register.html', formLogout=formLogout, form=form) userNuevo = user(nameUser=request.form['nameUser'], username=request.form['username'], typeUser=request.form['typeUser']) userNuevo.set_password(request.form['password']) db.session.add(userNuevo) db.session.commit() flash('Usuario registrado exitosamente', 'AC') return redirect(url_for('homeRoute')) else: return render_template('register.html', formLogout=formLogout, form=form)